UNPKG

youzanyun-devtool-worker

Version:

131 lines (130 loc) 4.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path_1 = tslib_1.__importDefault(require("path")); const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); const lodash_1 = require("lodash"); const spring4js_nodejs_1 = require("spring4js-nodejs"); let ConfigService = class ConfigService { constructor() { let workerDir = path_1.default.resolve(__dirname, '../../../'); this.config = { workerDir, youzanyunWokrspace: this.userhome('_youzanyun-workspace_'), npmDir: this.userhome('.youzanyun/npm'), logDir: this.userhome('.youzanyun/log'), dataDir: this.userhome('.youzanyun/data'), isvPageTplDir: this.userhome('.youzanyun/isv-page'), pluginDir: path_1.default.resolve(workerDir, 'plugin'), mpCacheDir: this.userhome('.youzanyun/mp-cache'), mpGuideConfigDir: this.userhome('.youzanyun/mp-guide-config'), pcDemoDir: this.userhome('.youzanyun/pc-demo'), viewRoot: path_1.default.resolve(workerDir, 'views'), h5DemoDir: this.userhome('.youzanyun/h5-demo'), dpCacheDir: this.userhome('.youzanyun/dp-cache'), dpCompJsFile: this.userhome('.youzanyun/dp-comp-temp.js'), unionCompJsDir: this.userhome('.youzanyun/union-comp'), sqlDir: this.userhome('.youzanyun/sql'), sshClientDir: this.userhome('.youzanyun/ssh-client'), }; } async start() { await fs_extra_1.default.ensureDir(this.config.dataDir); await fs_extra_1.default.ensureDir(this.config.sqlDir); await fs_extra_1.default.ensureDir(this.config.unionCompJsDir); let configPath = this.userhome('.youzanyun/config.json'); let config = await fs_extra_1.default.readJson(configPath); this.config = Object.assign(this.config, config); const workerJson = await fs_extra_1.default.readJson(path_1.default.resolve(this.config.npmDir, 'package.json')); const version = workerJson.dependencies[this.config.workerName]; this.workerVersion = version.replace('^', ''); } isServerMode() { return this.config.isServerMode || false; } getYouzanyunWokrspace() { return this.config.youzanyunWokrspace; } getRenderRemoteDebugPort() { return this.config.renderRemoteDebugPort; } getWorkerDir() { return this.config.workerDir; } getWebPort() { return this.config.workerWebPort; } getProxyHttpPort() { return this.config.workerProxyPort; } getProxyHttpsPort() { return this.config.workerProxyPort + 1; } getMpGuideConfigDir() { return this.isMpGuideLocalDevelop() ? this.config.mpGuideDevelopDir : this.config.mpGuideConfigDir; } isMpGuideLocalDevelop() { return this.config.mpGuideLocalDevelop || false; } getIsvPageTplDir() { return this.config.isvPageTplDir; } getPcDemoDir() { return this.config.pcDemoDir; } getConfig(keyPath) { return (0, lodash_1.get)(this.config, keyPath); } getDataDir() { return this.config.dataDir; } getWorkerLogLevel() { return this.config.workerLogLevel; } getLogDir() { return this.config.logDir; } getViewRoot() { return this.config.viewRoot; } getH5DemoDir() { return this.config.h5DemoDir; } getDpCacheDir() { return this.config.dpCacheDir; } getDpCompJsFile() { return this.config.dpCompJsFile; } getUnionCompJsDir() { return this.config.unionCompJsDir; } async saveConfig(config) { } isUseProxy() { return this.config.useProxy; } getProxyHost() { return this.config.proxyHost; } getProxyPort() { return this.config.proxyPort; } userhome(relativePath) { let home = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']; if (!home) { throw new Error('Could not find a valid user home path.'); } return path_1.default.resolve(home, relativePath); } getSqlDir() { return this.config.sqlDir; } getWorkerVersion() { return this.workerVersion; } }; ConfigService = tslib_1.__decorate([ (0, spring4js_nodejs_1.Service)() ], ConfigService); exports.default = ConfigService;