Skip to content

Commit

Permalink
feat: cli add --launch option
Browse files Browse the repository at this point in the history
  • Loading branch information
WindomZ committed Nov 5, 2017
1 parent b36fdb3 commit fcb76dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
25 changes: 19 additions & 6 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,26 @@ class App extends EventEmitter {
.filter(entity => entity.active === true)
);

const aloneEntity = entities.find(entity => entity.alone);
this.entities = entities;

// 如果找到设置alone属性的provider,则单独运行,方便调试
if (aloneEntity && !this.options.isProduction) {
this.entities = [aloneEntity];
} else {
this.entities = entities;
if (!this.options.isProduction) {
let aloneEntity;

// 如果找到指定的provider,则单独运行
if (this.options.launchProvider) {
aloneEntity = entities.find(
entity => entity.name === this.options.launchProvider
);
}

// 如果找到设置alone属性的provider,则单独运行,方便调试
if (!aloneEntity) {
aloneEntity = entities.find(entity => entity.alone);
}

if (aloneEntity) {
this.entities = [aloneEntity];
}
}

this.emit(EVENT_ON_LAUNCH, this);
Expand Down
2 changes: 2 additions & 0 deletions bin/boomer
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ program
.argument('<phone>', '手机号码')
.option('-f, --forever', '是否持久运行,默认只运行一个周期', program.BOOLEAN, false)
.option('--dev', '是否是开发模式,如果true,则显示浏览器运行过程', program.BOOLEAN, false)
.option('--launch <provider>', '如果是开发模式,则指定站点名称<provider>', program.STRING, "")
.action((argv, opts) => {
const app = boomer(argv.phone || process.env.PHONE || '13800000000', {
once: !opts.forever,
isProduction: !opts.dev,
launchProvider: opts.launch,
});

app
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const isProduction = process.env.NODE_ENV === 'production';
const defaultOptions = {
isProduction,
username: 'abc123mmp',
name: '张大爷',
name: '隔壁老王1024',
password: 'abc123abc123',
phone: '13000000000', // do not set default phone number
once: isProduction === false,
Expand Down

0 comments on commit fcb76dc

Please sign in to comment.