Skip to content

Commit 621a149

Browse files
committed
chore: code style
1 parent 5f5d2f9 commit 621a149

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

lib/cmd/start.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ class StartCommand extends Command {
7171
}
7272

7373
* run(context) {
74-
const argv = Object.assign({}, context.argv);
74+
const { argv, env, cwd, execArgv } = context;
75+
7576
const HOME = homedir();
7677
const logDir = path.join(HOME, 'logs');
7778

7879
// egg-script start
7980
// egg-script start ./server
8081
// egg-script start /opt/app
81-
let baseDir = argv._[0] || context.cwd;
82-
if (!path.isAbsolute(baseDir)) baseDir = path.join(context.cwd, baseDir);
82+
let baseDir = argv._[0] || cwd;
83+
if (!path.isAbsolute(baseDir)) baseDir = path.join(cwd, baseDir);
8384
argv.baseDir = baseDir;
8485

8586
const isDaemon = argv.daemon;
@@ -97,24 +98,18 @@ class StartCommand extends Command {
9798
argv.stdout = argv.stdout || path.join(logDir, 'master-stdout.log');
9899
argv.stderr = argv.stderr || path.join(logDir, 'master-stderr.log');
99100

100-
const env = context.env;
101+
// normalize env
101102
env.HOME = HOME;
102103
env.NODE_ENV = 'production';
103104

104-
// adjust env for win
105-
const currentPATH = env.PATH || env.Path;
106-
// for nodeinstall
107-
let newPATH = `${path.join(baseDir, 'node_modules/.bin')}${path.delimiter}`;
108-
// support `${baseDir}/.node/bin`
109-
const customNodeBinDir = path.join(baseDir, '.node/bin');
110-
if (yield fs.exists(customNodeBinDir)) {
111-
newPATH += `${customNodeBinDir}${path.delimiter}`;
112-
}
113-
if (currentPATH) {
114-
env.PATH = `${newPATH}${currentPATH}`;
115-
} else {
116-
env.PATH = newPATH;
117-
}
105+
env.PATH = [
106+
// for nodeinstall
107+
path.join(baseDir, 'node_modules/.bin'),
108+
// support `.node/bin`, due to npm5 will remove `node_modules/.bin`
109+
path.join(baseDir, '.node/bin'),
110+
// adjust env for win
111+
env.PATH || env.Path,
112+
].filter(x => !!x).join(path.delimiter);
118113

119114
// for alinode
120115
env.ENABLE_NODE_LOG = 'YES';
@@ -128,7 +123,7 @@ class StartCommand extends Command {
128123
}
129124

130125
const options = {
131-
execArgv: context.execArgv,
126+
execArgv,
132127
env,
133128
stdio: 'inherit',
134129
detached: false,
@@ -151,6 +146,7 @@ class StartCommand extends Command {
151146
const child = this.child = spawn('node', eggArgs, options);
152147
this.isReady = false;
153148
child.on('message', msg => {
149+
/* istanbul ignore else */
154150
if (msg && msg.action === 'egg-ready') {
155151
this.isReady = true;
156152
this.logger.info('%s started on %s', this.frameworkName, msg.data.address);
@@ -177,6 +173,7 @@ class StartCommand extends Command {
177173
let name = 'egg';
178174
try {
179175
const pkg = require(pkgPath);
176+
/* istanbul ignore else */
180177
if (pkg.name) name = pkg.name;
181178
} catch (_) {
182179
/* istanbul next */

0 commit comments

Comments
 (0)