ConceptCreator/app/storage/loader/ScriptAccountLoader.ts
Sebastian Böckelmann 8016f55e85
Some checks failed
E2E Testing / test (push) Failing after 1m34s
Refactor Loading of ScriptAccounts
2024-03-20 09:26:14 +01:00

35 lines
1.3 KiB
TypeScript

import {StoreComponent} from "../StoreComponent";
import {FileUtils} from "../FileUtils";
import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType";
import * as fs from "fs";
import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory";
import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks";
export class ScriptAccountLoader {
scriptAccountDir: string
constructor(scriptAccountDir: string) {
this.scriptAccountDir = scriptAccountDir;
}
loadScriptAccounts(): StoreComponent[] {
const scriptAccountFiles = FileUtils.listFilesInDirectory(this.scriptAccountDir);
const loadedScriptAccounts: StoreComponent[] = []
scriptAccountFiles.forEach(scriptAccountFile => {
const loadedScriptAccount = this.loadScriptAccount(scriptAccountFile);
if(loadedScriptAccount != undefined) {
loadedScriptAccounts.push(loadedScriptAccount)
}
})
return loadedScriptAccounts;
}
private loadScriptAccount(scriptAccountFile: string) {
if(scriptAccountFile.endsWith(".json")) {
const scriptAccountData = fs.readFileSync(scriptAccountFile, 'utf-8');
return new StoreComponent(scriptAccountData, scriptAccountFile, ModelComponentType.SCRIPTACCOUNT);
}
}
}