diff --git a/src/backend/ProjectPath.ts b/src/backend/ProjectPath.ts index 7bfc56a0..b0837be0 100644 --- a/src/backend/ProjectPath.ts +++ b/src/backend/ProjectPath.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import * as fs from 'fs'; -import {Config} from '../common/config/private/Config'; +import {PrivateConfigClass} from '../common/config/private/PrivateConfigClass'; export class ProjectPathClass { public Root: string; @@ -11,8 +11,10 @@ export class ProjectPathClass { public FrontendFolder: string; public ExtensionFolder: string; public DBFolder: string; + private cfg: PrivateConfigClass; - constructor() { + init(cfg: PrivateConfigClass) { + this.cfg = cfg; this.reset(); } @@ -31,12 +33,12 @@ export class ProjectPathClass { reset(): void { this.Root = path.join(__dirname, '/../../'); this.FrontendFolder = path.join(this.Root, 'dist'); - this.ImageFolder = this.getAbsolutePath(Config.Media.folder); - this.TempFolder = this.getAbsolutePath(Config.Media.tempFolder); + this.ImageFolder = this.getAbsolutePath(this.cfg.Media.folder); + this.TempFolder = this.getAbsolutePath(this.cfg.Media.tempFolder); this.TranscodedFolder = path.join(this.TempFolder, 'tc'); this.FacesFolder = path.join(this.TempFolder, 'f'); - this.DBFolder = this.getAbsolutePath(Config.Database.dbFolder); - this.ExtensionFolder = this.getAbsolutePath(Config.Extensions.folder); + this.DBFolder = this.getAbsolutePath(this.cfg.Database.dbFolder); + this.ExtensionFolder = this.getAbsolutePath(this.cfg.Extensions.folder); // create thumbnail folder if not exist if (!fs.existsSync(this.TempFolder)) { diff --git a/src/backend/model/extension/ExtensionConfigTemplateLoader.ts b/src/backend/model/extension/ExtensionConfigTemplateLoader.ts index 868e7e9a..eab65fd4 100644 --- a/src/backend/model/extension/ExtensionConfigTemplateLoader.ts +++ b/src/backend/model/extension/ExtensionConfigTemplateLoader.ts @@ -2,11 +2,8 @@ import {PrivateConfigClass} from '../../../common/config/private/PrivateConfigCl import * as fs from 'fs'; import * as path from 'path'; import {ServerExtensionsEntryConfig} from '../../../common/config/private/subconfigs/ServerExtensionsConfig'; -import * as child_process from 'child_process'; +import {ProjectPath} from '../../ProjectPath'; -const execSync = child_process.execSync; - -const LOG_TAG = '[ExtensionConfigTemplateLoader]'; /** * This class decouples the extension management and the config. @@ -16,7 +13,6 @@ const LOG_TAG = '[ExtensionConfigTemplateLoader]'; export class ExtensionConfigTemplateLoader { private static instance: ExtensionConfigTemplateLoader; - private extensionsFolder: string; private loaded = false; private extensionList: string[] = []; @@ -31,29 +27,26 @@ export class ExtensionConfigTemplateLoader { } - init(extensionsFolder: string) { - this.extensionsFolder = extensionsFolder; - } public loadExtensionTemplates(config: PrivateConfigClass) { - if (!this.extensionsFolder) { + if (!ProjectPath.ExtensionFolder) { throw new Error('Unknown extensions folder.'); } // already loaded if (!this.loaded) { this.extensionTemplates = []; - if (fs.existsSync(this.extensionsFolder)) { + if (fs.existsSync(ProjectPath.ExtensionFolder)) { this.extensionList = (fs - .readdirSync(this.extensionsFolder)) + .readdirSync(ProjectPath.ExtensionFolder)) .filter((f): boolean => - fs.statSync(path.join(this.extensionsFolder, f)).isDirectory() + fs.statSync(path.join(ProjectPath.ExtensionFolder, f)).isDirectory() ); this.extensionList.sort(); for (let i = 0; i < this.extensionList.length; ++i) { const extFolder = this.extensionList[i]; - const extPath = path.join(this.extensionsFolder, extFolder); + const extPath = path.join(ProjectPath.ExtensionFolder, extFolder); const configExtPath = path.join(extPath, 'config.js'); const serverExtPath = path.join(extPath, 'server.js'); diff --git a/src/common/config/private/Config.ts b/src/common/config/private/Config.ts index 7a14e5c0..d9232fac 100644 --- a/src/common/config/private/Config.ts +++ b/src/common/config/private/Config.ts @@ -1,8 +1,7 @@ import {ExtensionConfigWrapper} from '../../../backend/model/extension/ExtensionConfigWrapper'; import {PrivateConfigClass} from './PrivateConfigClass'; import {ConfigClassBuilder} from 'typeconfig/node'; -import {ExtensionConfigTemplateLoader} from '../../../backend/model/extension/ExtensionConfigTemplateLoader'; -import * as path from 'path'; +import {ProjectPath} from '../../../backend/ProjectPath'; // we need to know the location of the extensions to load the full config (including the extensions) const pre = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass()); @@ -10,6 +9,9 @@ try { pre.loadSync({preventSaving: true}); } catch (e) { /* empty */ } -ExtensionConfigTemplateLoader.Instance.init(path.join(__dirname, '/../../../../', pre.Extensions.folder)); +// load extension paths before full config load +ProjectPath.init(pre); export const Config = ExtensionConfigWrapper.originalSync(true); +// set actual config +ProjectPath.init(Config);