@wbg-mde/repository
Version:
Managing all common method for file system CRUD operations.
182 lines (181 loc) • 5.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const os = require('os');
const model_1 = require("@wbg-mde/model");
class ProjectConfiguration {
constructor() {
this.refresh();
}
refresh() {
let config = this.readConfig();
this._userdatapath = config._userdatapath;
this._masterdatapath = config._masterdatapath;
this._appLogConfig = config._appLogConfig;
this._rPath = config._rPath;
this._RFrequencyCalcLimit = config._RFrequencyCalcLimit || 50;
this._templateTypes = config._templateTypes;
this._defaultTemplates = config._defaultTemplates;
this._i18nResources = config._i18nResources || { "en": "English" };
this._customDataTypes = config._customDataTypes;
this._enableDevTools = config._enableDevTools === false ? false : true;
this._QC_CONFIG = config._QC_CONFIG;
this._variableRepoConfig = config._variableRepoConfig;
this._publishConfig = config._publishConfig;
this._serverPort = parseInt(config._serverPort || 4040);
this._RServerPort = parseInt(config._RServerPort || 9090);
this._dbProvider = config._dbProvider;
}
get userDataPath() {
return (this._userdatapath || path.join(os.userInfo().homedir, '.metadata-editor'));
}
set userDataPath(path) {
this._userdatapath = path;
this.saveConfig();
}
get enableDevTools() {
return this._enableDevTools;
}
set enableDevTools(value) {
this._enableDevTools = value;
this.saveConfig();
}
get templateTypes() {
return this._templateTypes;
}
set templateTypes(path) {
this._templateTypes = path;
this.saveConfig();
}
get customDataTypes() {
return this._customDataTypes;
}
set customDataTypes(types) {
this._customDataTypes = types;
this.saveConfig();
}
get i18nResources() {
return this._i18nResources;
}
set i18nResources(resource) {
this._i18nResources = this.i18nResources;
this.saveConfig();
}
get defaultTemplates() {
return this._defaultTemplates || {};
}
set defaultTemplates(defaults) {
this._defaultTemplates = defaults;
this.saveConfig();
this.refresh();
}
get publishConfig() {
return this._publishConfig;
}
set publishConfig(config) {
this._publishConfig = config;
this.saveConfig();
}
get serverPort() {
return this._serverPort;
}
set serverPort(config) {
this._serverPort = config;
this.saveConfig();
}
get RServerPort() {
return this._RServerPort;
}
set RServerPort(config) {
this._RServerPort = config;
this.saveConfig();
}
get dbProvider() {
return this._dbProvider;
}
set dbProvider(value) {
this._dbProvider = value;
this.saveConfig();
}
get appLogConfig() {
if (!this._appLogConfig) {
this._appLogConfig = {
level: model_1.LogPreferences.writeOnlyErrors,
includeLongParams: model_1.LogBoolStatus.disabled,
includeRecMethods: model_1.LogBoolStatus.disabled
};
}
return this._appLogConfig;
}
set appLogConfig(__appLogConfig) {
this._appLogConfig = __appLogConfig;
this.saveConfig();
}
get variableRepoConfig() {
if (!this._variableRepoConfig) {
this._variableRepoConfig = {
donotUseGlobal: true,
localPath: undefined,
globalPath: undefined
};
}
return this._variableRepoConfig;
}
set variableRepoConfig(__repoConfig) {
this._variableRepoConfig = __repoConfig;
this.saveConfig();
}
get masterDataPath() {
let defuault_path = path.join(process.cwd(), 'dist');
return path.join(this._masterdatapath || defuault_path, 'assets');
}
set masterDataPath(path) {
this._masterdatapath = path;
this.saveConfig();
}
get rPath() {
return (this._rPath);
}
set rPath(rPackagePath) {
this._rPath = rPackagePath;
this.saveConfig();
}
get RFrequencyCalcLimit() {
return (this._RFrequencyCalcLimit);
}
set RFrequencyCalcLimit(limit) {
this._RFrequencyCalcLimit = limit;
this.saveConfig();
}
get QC_CONFIG() {
return this._QC_CONFIG;
}
set QC_CONFIG(config) {
this._QC_CONFIG = config;
}
readConfig() {
let configPath = path.join(os.userInfo().homedir, 'metadata-editor-config.json');
if (fs.existsSync(configPath)) {
let config = fs.readFileSync(configPath, 'utf8');
if (typeof config === 'string') {
try {
config = JSON.parse(config);
}
catch (e) {
config = {};
console.error(e);
}
}
return config;
}
else {
return {};
}
}
saveConfig() {
let configPath = path.join(os.userInfo().homedir, 'metadata-editor-config.json');
fs.writeFileSync(configPath, JSON.stringify(this, null, 4));
}
}
exports.configuaration = new ProjectConfiguration();