33 lines
1.5 KiB
JavaScript
33 lines
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ScriptAccountStorage = void 0;
|
|
const FileUtils_1 = require("../FileUtils");
|
|
const path = require("node:path");
|
|
const fs = require("fs");
|
|
class ScriptAccountStorage {
|
|
constructor(scriptAccountDir) {
|
|
this.scriptAccountDir = scriptAccountDir;
|
|
}
|
|
storeScriptAccounts(scriptAccounts) {
|
|
this.persistDeletedScriptAccounts(scriptAccounts);
|
|
scriptAccounts.forEach(scriptAccount => {
|
|
this.storeScriptAccount(scriptAccount);
|
|
});
|
|
}
|
|
persistDeletedScriptAccounts(existingScriptAccount) {
|
|
const scriptAccountFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.scriptAccountDir);
|
|
scriptAccountFiles.forEach(scriptAccountFile => {
|
|
const scriptAccountFileName = path.parse(path.basename(scriptAccountFile)).name;
|
|
if (existingScriptAccount.find(scriptAccount => scriptAccount.fileName === scriptAccountFileName) == undefined) {
|
|
//No scriptAccountFile was found with that nae of the file. So the scriptAccount was deleted. Remove file
|
|
fs.unlinkSync(scriptAccountFile);
|
|
}
|
|
});
|
|
}
|
|
storeScriptAccount(scriptAccount) {
|
|
const completeScriptAccountFile = path.join(this.scriptAccountDir, scriptAccount.fileName + ".json");
|
|
fs.writeFileSync(completeScriptAccountFile, scriptAccount.jsonString, 'utf-8');
|
|
}
|
|
}
|
|
exports.ScriptAccountStorage = ScriptAccountStorage;
|
|
//# sourceMappingURL=ScriptAccountStoring.js.map
|