diff --git a/packages/cli/lib/common/paths.js b/packages/cli/lib/common/paths.js index 0a9e3e15..51f4666f 100644 --- a/packages/cli/lib/common/paths.js +++ b/packages/cli/lib/common/paths.js @@ -4,22 +4,20 @@ */ const path = require('path'); -const pkg = require('../../package'); const ENV = process.env; exports.homePath = function () { - return ENV.HOME || ENV.USERPROFILE || (ENV.HOMEDRIVE + ENV.HOMEPATH); + return ENV.HOME || ENV.USERPROFILE || ENV.HOMEDRIVE + ENV.HOMEPATH; }; exports.dataPath = function () { - return ENV.HOME || ENV.APPDATA || ENV.LOCALAPPDATA || - ENV.TMPDIR || ENV.TEMP; + return ENV.HOME || ENV.APPDATA || ENV.LOCALAPPDATA || ENV.TMPDIR || ENV.TEMP; }; exports.storePath = function () { - return path.normalize(`${this.dataPath()}/.${pkg.name}`); + return path.normalize(`${this.dataPath()}/.dawn`); }; exports.rcPath = function () { - return `${this.homePath()}/.${pkg.name}rc`; -}; \ No newline at end of file + return `${this.homePath()}/.dawnrc`; +}; diff --git a/packages/cli/lib/configs.js b/packages/cli/lib/configs.js index 85035211..ae708af2 100644 --- a/packages/cli/lib/configs.js +++ b/packages/cli/lib/configs.js @@ -21,7 +21,7 @@ const paths = require('./common/paths'); const FETCH_TIMEOUT = 30000; exports.setLocalRc = async function (name, value) { - const rcObject = await this.getLocalRc() || {}; + const rcObject = (await this.getLocalRc()) || {}; rcObject[name] = value; const text = yaml.stringify(rcObject); const rcFile = paths.rcPath(); @@ -39,14 +39,14 @@ exports.getLocalRc = async function (name) { }; exports.getRemoteRc = async function (name) { - const remoteRCConf = await this.getRemoteConf('rc') || {}; + const remoteRCConf = (await this.getRemoteConf('rc')) || {}; const value = name ? remoteRCConf[name] || '' : remoteRCConf; debug('getRemoteRc', name || 'all', value || ''); return utils.isString(value) ? value.trim() : value; }; exports.getProjectRc = async function (name) { - const configsPath = path.resolve(process.cwd(), `./.${pkg.name}`); + const configsPath = path.resolve(process.cwd(), './.dawn'); const configs = utils.confman.load(configsPath); const rcObject = configs.rc || {}; const value = name ? rcObject[name] || '' : rcObject; @@ -56,21 +56,21 @@ exports.getProjectRc = async function (name) { exports.getRc = async function (name, opts) { opts = Object.assign({}, opts); - const value = await this.getProjectRc(name) || - await this.getLocalRc(name) || - (opts.remote !== false && await this.getRemoteRc(name)) || - pkg.configs[name] || ''; + const value = + (await this.getProjectRc(name)) || + (await this.getLocalRc(name)) || + (opts.remote !== false && (await this.getRemoteRc(name))) || + pkg.configs[name] || + ''; debug('getRc', name, value || ''); return utils.isString(value) ? value.trim() : value; }; exports.getServerUri = async function () { - const serverUri = await this.getProjectRc('server') || - await this.getLocalRc('server') || - pkg.configs.server || ''; + const serverUri = + (await this.getProjectRc('server')) || (await this.getLocalRc('server')) || pkg.configs.server || ''; debug('getServerUri', serverUri || ''); - return utils.isString(serverUri) ? - trim(serverUri.trim(), '/') : ''; + return utils.isString(serverUri) ? trim(serverUri.trim(), '/') : ''; }; exports.getRemoteConf = async function (name, defaultValue = {}) { @@ -109,4 +109,4 @@ exports.setLocalConf = async function (name, value) { const filename = path.normalize(`${localStoreDir}/${name}.json`); const text = JSON.stringify(value); await writeFile(filename, text); -}; \ No newline at end of file +}; diff --git a/packages/cli/lib/context.js b/packages/cli/lib/context.js index e4f78965..7f7f0816 100644 --- a/packages/cli/lib/context.js +++ b/packages/cli/lib/context.js @@ -18,7 +18,6 @@ const stp = require('stp'); const debug = require('debug')('context'); class Context extends EventEmitter { - constructor(cli, opts) { super(); opts = opts || {}; @@ -34,7 +33,7 @@ class Context extends EventEmitter { this.console = console; this.utils = utils; this.inquirer = utils.inquirer; - this.configName = `./.${pkg.name}`; + this.configName = './.dawn'; this.configPath = path.resolve(this.cwd, this.configName); this.conf = configs; this.mod = mod; @@ -42,10 +41,7 @@ class Context extends EventEmitter { async configIsExists() { debug('config name', this.configName); - const files = await utils.globby([ - `${this.configName}/**/*.*`, - `${this.configName}.*` - ]); + const files = await utils.globby([`${this.configName}/**/*.*`, `${this.configName}.*`]); debug('config files', files); return files.length > 0; } @@ -119,10 +115,9 @@ class Context extends EventEmitter { const middleware = middlewares.shift(); if (!middleware) return; const handler = await this.load(middleware); - const next = (args) => { + const next = args => { if (next.__result) return next.__result; - next.__result = this._execQueue(middlewares, args, onFail) - .catch(err => onFail(err)); + next.__result = this._execQueue(middlewares, args, onFail).catch(err => onFail(err)); return next.__result; }; return handler.call(this, next, this, args); @@ -130,7 +125,7 @@ class Context extends EventEmitter { unescapeExpr(str) { if (!str) return str; - return str.replace(/\\\{/, '{').replace('/\\\}/', '}'); + return str.replace(/\\\{/, '{').replace('/\\}/', '}'); } _parseOpts(opts) { @@ -156,9 +151,9 @@ class Context extends EventEmitter { throw new Error('Invalid pipeline config'); } opts = this._parseOpts(opts); - const modFactory = opts.location ? - require(path.resolve(this.cwd, opts.location)) : - await middleware.require(opts.name, this.cwd); + const modFactory = opts.location + ? require(path.resolve(this.cwd, opts.location)) + : await middleware.require(opts.name, this.cwd); if (!utils.isFunction(modFactory)) { throw new Error(`Invalid middleware '${opts.name}'`); } @@ -171,8 +166,7 @@ class Context extends EventEmitter { middlewares.push((next, ctx, args) => { resolve(args); }); - this._execQueue(middlewares, initailArgs, reject) - .catch(err => reject(err)); + this._execQueue(middlewares, initailArgs, reject).catch(err => reject(err)); }); } @@ -186,7 +180,6 @@ class Context extends EventEmitter { } return this.exec(this.pipeline); } - } module.exports = Context;