Skip to content

Commit

Permalink
fix: support --workers same as egg-scripts (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Apr 1, 2019
1 parent a3e829c commit fcae123
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $ egg-bin dev
- `--framework` egg web framework root path.
- `--baseDir` application's root path, default to `process.cwd()`.
- `--port` server port, default to `7001`.
- `--cluster` worker process number, skip this argvs will start only `1` worker, provide this without value will start `cpu` count worker.
- `--workers` worker process number, default to `1` worker at local mode.
- `--sticky` start a sticky cluster server, default to `false`.
- `--typescript` / `--ts` enable typescript support, default to `false`. Also support read from `package.json`'s `egg.typescript`.
- `--declarations` / `--dts` enable [egg-ts-helper](https://github.com/whxaxes/egg-ts-helper) support, default to `false`. Also support read from `package.json`'s `egg.declarations`.
Expand Down
10 changes: 5 additions & 5 deletions lib/cmd/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class DevCommand extends Command {
description: 'directory of application, default to `process.cwd()`',
type: 'string',
},
cluster: {
description: 'numbers of app workers, if not provide then only 1 worker, provide without value then `os.cpus().length`',
workers: {
description: 'numbers of app workers, default to 1 at local mode',
type: 'number',
alias: 'c',
alias: [ 'c', 'cluster' ],
default: 1,
},
port: {
description: 'listening port, default to 7001',
Expand Down Expand Up @@ -73,7 +74,7 @@ class DevCommand extends Command {

/**
* format egg startCluster args then change it to json string style
* @method helper#formatArgs
* @function helper#formatArgs
* @param {Object} context - { cwd, argv }
* @return {Array} pass to start-cluster, [ '{"port":7001,"framework":"egg"}' ]
*/
Expand All @@ -84,7 +85,6 @@ class DevCommand extends Command {
/* istanbul ignore next */
if (!path.isAbsolute(argv.baseDir)) argv.baseDir = path.join(cwd, argv.baseDir);

argv.workers = argv.cluster || 1;
argv.port = argv.port || argv.p;
argv.framework = utils.getFrameworkPath({
framework: argv.framework,
Expand Down
11 changes: 11 additions & 0 deletions test/lib/cmd/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ describe('test/lib/cmd/dev.test.js', () => {
.end(done);
});

it('should startCluster with --workers=2', done => {
coffee.fork(eggBin, [ 'dev', '--workers=2' ], { cwd })
// .debug()
.expect('stdout', /"workers":2/)
.expect('stdout', /"baseDir":".*?demo-app"/)
.expect('stdout', /"framework":".*?aliyun-egg"/)
.notExpect('stdout', /"cluster"/)
.expect('code', 0)
.end(done);
});

it('should startCluster with --baseDir=root', done => {
coffee.fork(eggBin, [ 'dev', `--baseDir=${cwd}` ])
// .debug()
Expand Down

0 comments on commit fcae123

Please sign in to comment.