2024-03-20 16:23:37 +01:00
|
|
|
"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;
|
2024-03-22 10:01:47 +01:00
|
|
|
FileUtils_1.FileUtils.prepareDirectoryFroWriting(this.scriptAccountDir);
|
2024-03-20 16:23:37 +01:00
|
|
|
}
|
|
|
|
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
|