Skip to content

Commit

Permalink
Add support for task arguments
Browse files Browse the repository at this point in the history
…when task name is specified. It is not currently possible to support arguments without a task because argv[2] was hard-coded to be the task name. If it were defined as “--arg”, it would treat that as the task name.

fixes M-Zuber#37
  • Loading branch information
stevenvachon committed Jun 28, 2017
1 parent 8f621ea commit 6d2f5c9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions watch-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ class Watcher extends EventEmitter {
this.emit('info', 'No task specified. Will go through all possible tasks');
tasks = Object.keys(this.pkg.watch).map(taskName => this.startTask(taskName));
} else {
tasks = [ this.startTask(this.cfg.taskName) ];
tasks = [ this.startTask(this.cfg.taskName, this.cfg.taskArgs) ];
}

return Promise.all(tasks);
}

startTask(taskName) {
startTask(taskName, args=[]) {
return promiseTry(() => {
const task = this.pkg.watch[taskName];

Expand Down Expand Up @@ -130,7 +130,11 @@ class Watcher extends EventEmitter {
delete nodemonConfig.patterns;
}

nodemonConfig.exec = [npm, 'run', '-s', taskName].join(' ');
if (args.length > 0 && args[0] !== '--') {
args.unshift('--');
}

nodemonConfig.exec = [npm, 'run', '-s', taskName].concat(args).join(' ');
//nodemonConfig.stdout = false;

console.log(nodemonConfig)
Expand Down

0 comments on commit 6d2f5c9

Please sign in to comment.