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); } } }