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 61a8b15 commit 9d2439b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ log.info = function() {

const config = {
pkgDir: process.cwd(),
taskName: process.argv[2]
taskName: process.argv[2],
taskArgs: process.argv.slice(3)
};

module.exports = watchPackage(config)
Expand Down
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 9d2439b

Please sign in to comment.