Skip to content

Commit

Permalink
Added 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 23, 2017
1 parent 74f083c commit 398ee2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var pathVarName = (windows && !('PATH' in process.env)) ? 'Path' : 'PATH'
process.env[pathVarName] += path.delimiter + path.join(__dirname, 'node_modules', '.bin')

var watchPackage = require('./watch-package')
var watcher = watchPackage(process.argv[3] || process.cwd(), process.exit, process.argv[2])
var watcher = watchPackage(process.cwd(), process.exit, process.argv[2], process.argv.slice(3))

process.stdin.pipe(watcher)
watcher.stdout.pipe(process.stdout)
Expand Down
11 changes: 7 additions & 4 deletions watch-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var nodemon = process.platform === 'win32' ? 'nodemon.cmd' : 'nodemon';
var pkgDir = '';
var stdin = null;

module.exports = function watchPackage(_pkgDir, exit, taskName) {
module.exports = function watchPackage(_pkgDir, exit, taskName, args) {
pkgDir = _pkgDir;
var pkg = require(path.join(pkgDir, 'package.json'))
var processes = {}
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports = function watchPackage(_pkgDir, exit, taskName) {
if (!pkg.scripts[taskName]) {
die('No such script "' + taskName + '"', 2)
}
startScript(taskName, pkg, processes);
startScript(taskName, pkg, processes, args);
} else {

Object.keys(pkg.watch).forEach(function (script) {
Expand Down Expand Up @@ -85,8 +85,11 @@ function prefixer(prefix) {
})
}

function startScript(script, pkg, processes) {
var exec = [npm, 'run', '-s', script].join(' ')
function startScript(script, pkg, processes, args) {
if (args[0] !== '--') {
args.unshift('--');
}
var exec = [npm, 'run', '-s', script].concat(args).join(' ')
var patterns = null
var extensions = null
var ignores = null
Expand Down

0 comments on commit 398ee2c

Please sign in to comment.