Comparing version 0.1.8 to 0.1.9
#!/usr/bin/env node | ||
'use strict'; | ||
var path = require('path') | ||
var windows = process.platform === 'win32' | ||
@@ -11,7 +10,6 @@ var pathVarName = (windows && !('PATH' in process.env)) ? 'Path' : 'PATH' | ||
var watchPackage = require('./watch-package') | ||
var watcher = watchPackage(process.argv[3] || process.cwd(), process.exit, process.argv[2]) | ||
var watcher = watchPackage(process.argv[2] || process.cwd(), process.exit) | ||
process.stdin.pipe(watcher) | ||
watcher.stdout.pipe(process.stdout) | ||
watcher.stderr.pipe(process.stderr) |
{ | ||
"name": "npm-watch", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "run scripts from package.json when files change", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,5 +26,38 @@ # npm-watch | ||
Possibilty to watch for different tasks | ||
```javascript | ||
{ | ||
"watch": | ||
{ | ||
"run_android": { | ||
"patterns": [ | ||
"app" | ||
], | ||
"extensions": "ts,html,scss", | ||
"quiet": false | ||
}, | ||
"run_ios": { | ||
"patterns": [ | ||
"app" | ||
], | ||
"extensions": "ts,html,scss", | ||
"quiet": false | ||
} | ||
}, | ||
"scripts": { | ||
"watch_android": "npm-watch run_android", | ||
"watch_ios": "npm-watch run_ios", | ||
"run_android": "tns run android --emulator", | ||
"run_ios": "tns run ios --emulator" | ||
} | ||
} | ||
``` | ||
The keys of the `"watch"` config should match the names of your `"scripts"`, and | ||
the values should be a glob pattern or array of glob patterns to watch. | ||
Also it is now possible to obtain a second parameter to define the script which should be run for watching and not watch all possible scripts at once. | ||
If you need to watch files with extensions other than those that `nodemon` watches [by default](https://github.com/remy/nodemon#specifying-extension-watch-list) (`.js`, `.coffee`, `.litcoffee`), you can set the value to an object with `patterns` and `extensions` keys. You can also add an `ignore` key (a list or a string) to ignore specific files. Finally, you can add a `quiet` flag to hide the script name in any output on stdout or stderr, or you can use the `inherit` flag to preserve the original's process stdout or stderr. | ||
@@ -31,0 +64,0 @@ > The `quiet` flag was changed from a `string` to a `boolean` in `0.1.5`. Backwards compatability will be kept for two patch versions. |
@@ -11,6 +11,16 @@ 'use strict'; | ||
module.exports = function watchPackage(pkgDir, exit) { | ||
var pkgDir = ''; | ||
var stdin = null; | ||
module.exports = function watchPackage(_pkgDir, exit, taskName) { | ||
pkgDir = _pkgDir; | ||
var pkg = require(path.join(pkgDir, 'package.json')) | ||
var processes = {} | ||
taskName = typeof taskName !== 'undefined' ? taskName.trim() : ''; | ||
if (taskName === '') { | ||
console.info('No task specified. Will go through all possible tasks'); | ||
} | ||
if (typeof pkg.watch !== 'object') { | ||
@@ -21,3 +31,3 @@ die('No "watch" config in package.json') | ||
// send 'rs' commands to the right proc | ||
var stdin = through(function (line, _, callback) { | ||
stdin = through(function (line, _, callback) { | ||
line = line.toString() | ||
@@ -41,2 +51,9 @@ var match = line.match(/^rs\s+(\w+)/) | ||
if (taskName !== '') { | ||
if (!pkg.scripts[taskName]) { | ||
die('No such script "' + taskName + '"', 2) | ||
} | ||
startScript(taskName, pkg, processes); | ||
} else { | ||
Object.keys(pkg.watch).forEach(function (script) { | ||
@@ -46,3 +63,32 @@ if (!pkg.scripts[script]) { | ||
} | ||
var exec = [npm, 'run', '-s', script].join(' ') | ||
startScript(script, pkg, processes); | ||
}) | ||
} | ||
return stdin | ||
function die(message, code) { | ||
process.stderr.write(message) | ||
if (stdin) { | ||
stdin.end() | ||
stdin.stderr.end() | ||
stdin.stdout.end() | ||
} | ||
exit(code || 1) | ||
} | ||
} | ||
function prefixer(prefix) { | ||
return through(function (line, _, callback) { | ||
line = line.toString() | ||
if (!line.match('to restart at any time')) { | ||
this.push(prefix + ' ' + line) | ||
} | ||
callback() | ||
}) | ||
} | ||
function startScript(script, pkg, processes) { | ||
var exec = [npm, 'run', '-s', script].join(' ') | ||
var patterns = null | ||
@@ -95,26 +141,2 @@ var extensions = null | ||
} | ||
}) | ||
return stdin | ||
function die(message, code) { | ||
process.stderr.write(message) | ||
if (stdin) { | ||
stdin.end() | ||
stdin.stderr.end() | ||
stdin.stdout.end() | ||
} | ||
exit(code || 1) | ||
} | ||
} | ||
function prefixer(prefix) { | ||
return through(function (line, _, callback) { | ||
line = line.toString() | ||
if (!line.match('to restart at any time')) { | ||
this.push(prefix + ' ' + line) | ||
} | ||
callback() | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10210
127
129
7