Skip to content
Permalink
Browse files

fix: support --workers same as egg-scripts (#127)

  • Loading branch information
atian25 committed Apr 1, 2019
1 parent a3e829c commit fcae1233518d094984aac0efe6890d679da533a0
Showing with 17 additions and 6 deletions.
  1. +1 −1 README.md
  2. +5 −5 lib/cmd/dev.js
  3. +11 −0 test/lib/cmd/dev.test.js
@@ -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`.
@@ -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',
@@ -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"}' ]
*/
@@ -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,
@@ -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()

0 comments on commit fcae123

Please sign in to comment.
You can’t perform that action at this time.