Skip to content

Commit

Permalink
feat(dev): pass debug args to execArgv (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and popomore committed Sep 29, 2016
1 parent 41f17f6 commit 92b111f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/dev_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ const Command = require('./command');

class DevCommand extends Command {
* run(cwd, args) {
const execArgv = args ? args.filter(str => str.indexOf('--debug') === 0 || str.indexOf('--inspect') === 0) : [];

args.push('--baseDir');
args.push(cwd);
args.push('--cluster');
args.push('1');

const eggPath = this.getFrameworkOrEggPath(cwd);

if (eggPath) {
args.push(`--eggPath=${eggPath}`);
}

const options = {
env: process.env,
execArgv,
};

options.env.NODE_ENV = options.env.NODE_ENV || 'development';

debug('%s %j %j', this.helper.serverBin, args, options.env.NODE_ENV);
debug('%s %j %j, %j', this.helper.serverBin, args, execArgv, options.env.NODE_ENV);
yield this.helper.checkDeps();
yield this.helper.forkNode(this.helper.serverBin, args, options);
}
Expand Down
1 change: 1 addition & 0 deletions lib/start-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ commander
.option('--baseDir [baseDir]')
.option('--port [port]')
.option('--cluster [workers]')
.allowUnknownOption(true)
.parse(process.argv);

const baseDir = commander.baseDir;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"common-bin": "^1.0.0",
"debug": "^2.2.0",
"egg-utils": "^1.0.0",
"glob": "^7.0.5",
"glob": "^7.1.0",
"istanbul": "^0.4.0",
"mkdirp": "^0.5.1",
"mocha": "^3.0.0",
"rimraf": "^2.5.4",
"thunk-mocha": "^1.0.3"
},
"devDependencies": {
"autod": "^2.7.0",
"coffee": "^3.2.4",
"autod": "^2.7.1",
"coffee": "^3.2.5",
"egg-ci": "1",
"eslint": "3",
"eslint-config-egg": "3",
Expand Down
22 changes: 22 additions & 0 deletions test/egg-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,26 @@ describe('egg-bin dev', () => {
.expect('code', 0)
.end(done);
});

it('should startCluster with execArgv --debug', done => {
coffee.fork(eggBin, [ 'dev', '--debug=7000' ], {
cwd: appdir,
})
// .debug()
.expect('stdout', `{"baseDir":"${appdir}","workers":1}\n`)
.expect('stderr', /Debugger listening on .*7000/)
.expect('code', 0)
.end(done);
});

it.skip('should startCluster with execArgv --inspect', done => {
coffee.fork(eggBin, [ 'dev', '--inspect=7000' ], {
cwd: appdir,
})
// .debug()
.expect('stdout', `{"baseDir":"${appdir}","workers":1}\n`)
.expect('stderr', /Debugger listening on .*7000/)
.expect('code', 0)
.end(done);
});
});

0 comments on commit 92b111f

Please sign in to comment.