rerun-script
Advanced tools
Comparing version 0.4.1 to 0.5.0
62
index.js
@@ -1,8 +0,16 @@ | ||
'use strict'; | ||
'use strict' | ||
var path = require('path'); | ||
var debug = require('debug')('watch-and-run:index'); | ||
/*! | ||
* imports. | ||
*/ | ||
module.exports = getWatches; | ||
var debug = require('debug')('rerun-script:index') | ||
var path = require('path') | ||
/*! | ||
* exports. | ||
*/ | ||
module.exports = getWatches | ||
/** | ||
@@ -18,30 +26,40 @@ * Get package watches. | ||
function getWatches(directory) { | ||
var package_path = resolve(directory || './'); | ||
var pkg = read(package_path); | ||
var watches = extract(pkg); | ||
return Array.isArray(watches) ? watches : []; | ||
function getWatches (directory) { | ||
var package_path = resolve(directory || './') | ||
var pkg = read(package_path) | ||
var watches = extract(pkg) | ||
return Array.isArray(watches) ? watches : [] | ||
} | ||
function resolve(directory) { | ||
var package_path = path.resolve(directory, 'package.json'); | ||
debug('package.json path: %s', package_path); | ||
return package_path; | ||
function resolve (directory) { | ||
var package_path = path.resolve(directory, 'package.json') | ||
debug('package.json path: %s', package_path) | ||
return package_path | ||
} | ||
function read(package_path) { | ||
function read (package_path) { | ||
try { | ||
var pkg = require(package_path); | ||
var pkg = require(package_path) | ||
} catch (e) { | ||
throw new Error(package_path + ' does not exist.'); | ||
throw new Error(package_path + ' does not exist.') | ||
} | ||
debug('package.json contents: %s', JSON.stringify(pkg)); | ||
return pkg; | ||
debug('package.json contents: %s', JSON.stringify(pkg)) | ||
return pkg | ||
} | ||
function extract(pkg) { | ||
var watches = pkg.watches; | ||
debug('watches list: %s', JSON.stringify(watches)); | ||
return watches; | ||
function extract (pkg) { | ||
var watches | ||
if (Array.isArray(pkg.watches)) { | ||
watches = pkg.watches | ||
} else { | ||
watches = Object.keys(pkg.watches).map(function (key) { | ||
return { | ||
'script': key, | ||
'patterns': pkg.watches[key] | ||
} | ||
}) | ||
} | ||
debug('watches list: %s', JSON.stringify(watches)) | ||
return watches | ||
} |
{ | ||
"name": "rerun-script", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Invoke npm scripts upon file changes. Configure via package.json using glob patterns.", | ||
@@ -10,22 +10,19 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "tape test.js | faucet" | ||
"standard": "standard", | ||
"standard:format": "standard-format", | ||
"test": "tape test.js | tap-spec", | ||
"watch": "bin/rerun-script" | ||
}, | ||
"watches": [ | ||
{ | ||
"script": "test", | ||
"patterns": [ | ||
"*.js", | ||
"lib/**/*.js", | ||
"test/**/*.js" | ||
] | ||
}, | ||
{ | ||
"script": "lint", | ||
"patterns": [ | ||
"*.js", | ||
"lib/**/*.js", | ||
"test/**/*.js" | ||
] | ||
} | ||
], | ||
"watches": { | ||
"test": [ | ||
"*.js", | ||
"lib/**/*.js", | ||
"test/**/*.js" | ||
], | ||
"lint": [ | ||
"*.js", | ||
"lib/**/*.js", | ||
"test/**/*.js" | ||
] | ||
}, | ||
"keywords": [ | ||
@@ -50,3 +47,3 @@ "glob", | ||
"dependencies": { | ||
"chalk": "^0.5.1", | ||
"chalk": "^1.0.0", | ||
"commander": "^2.3.0", | ||
@@ -59,5 +56,7 @@ "debug": "^2.0.0", | ||
"devDependencies": { | ||
"faucet": "0.0.1", | ||
"standard": "^3.3.0", | ||
"standard-format": "^1.3.5", | ||
"tap-spec": "^2.2.2", | ||
"tape": "^3.0.0" | ||
} | ||
} |
# rerun-script | ||
[![Build Status](http://img.shields.io/travis/wilmoore/rerun-script.svg)](https://travis-ci.org/wilmoore/rerun-script) [![NPM version](http://img.shields.io/npm/v/rerun-script.svg)](https://www.npmjs.org/package/rerun-script) [![NPM downloads](http://img.shields.io/npm/dm/rerun-script.svg)](https://www.npmjs.org/package/rerun-script) [![LICENSE](http://img.shields.io/npm/l/rerun-script.svg)](license) | ||
[![Build Status](http://img.shields.io/travis/wilmoore/rerun-script.svg)](https://travis-ci.org/wilmoore/rerun-script) [![NPM version](http://img.shields.io/npm/v/rerun-script.svg)](https://www.npmjs.org/package/rerun-script) [![NPM downloads](http://img.shields.io/npm/dm/rerun-script.svg)](https://www.npmjs.org/package/rerun-script) [![LICENSE](http://img.shields.io/npm/l/rerun-script.svg)](license) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) | ||
> Invoke npm scripts upon file changes. Configure via package.json using glob patterns. | ||
> Invoke npm scripts upon file changes. Configure via `package.json` using glob patterns. | ||
@@ -19,15 +19,33 @@ $ npm install rerun-script --save-dev | ||
## example | ||
## configure package.json | ||
% ./node_modules/.bin/rerun-script | ||
**NOTE** 1: While the examples below use the [standard] lint checker, you are free to use any lint checker you like. | ||
**NOTE** 2: The `watch` script in `package.json` is optional and is only necessary if you plan to invoke `rerun-script` via `npm run`. You can use any script name you like. | ||
## package.json | ||
### `package.json` | ||
###### compact (recommended) format: | ||
{ | ||
"scripts": { | ||
"test": "node test.js", | ||
"lint": "eslint", | ||
"lint": "standard", | ||
"watch": "rerun-script" | ||
}, | ||
"watches": { | ||
"test": [ "*.js", "lib/**/*.js", "test/**/*.js" ], | ||
"lint": [ "*.js", "lib/**/*.js", "test/**/*.js" ] | ||
} | ||
} | ||
###### verbose format: | ||
{ | ||
"scripts": { | ||
"test": "node test.js", | ||
"lint": "standard", | ||
"watch": "rerun-script" | ||
}, | ||
"watches": [ | ||
@@ -45,5 +63,13 @@ { | ||
## start the watcher | ||
# directly | ||
$ ./node_modules/.bin/rerun-script | ||
# or via `npm run watch` | ||
$ npm run watch | ||
## screenshot | ||
![](https://cloudup.com/cJYbv0puHkE+) | ||
![](https://cloudup.com/c6iu6nW6gm2+) | ||
@@ -54,1 +80,2 @@ ## License | ||
[standard]: https://github.com/feross/standard |
27
test.js
@@ -1,15 +0,20 @@ | ||
var test = require('tape'); | ||
var getWatches = require('./'); | ||
'use strict' | ||
/*! | ||
* imports. | ||
*/ | ||
var test = require('tape') | ||
var getWatches = require('./') | ||
test('watches is an array', function (t) { | ||
var watches = getWatches('.'); | ||
t.assert(Array.isArray(watches)); | ||
t.end(); | ||
}); | ||
var watches = getWatches('.') | ||
t.assert(Array.isArray(watches), t.name) | ||
t.end() | ||
}) | ||
test('watches count', function (t) { | ||
var watches = getWatches('.'); | ||
t.equal(2, watches.length); | ||
t.end(); | ||
}); | ||
var watches = getWatches('.') | ||
t.equal(2, watches.length) | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8735
10
70
79
4
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
- Removedansi-regex@0.2.1(transitive)
- Removedansi-styles@1.1.0(transitive)
- Removedchalk@0.5.1(transitive)
- Removedhas-ansi@0.1.0(transitive)
- Removedstrip-ansi@0.3.0(transitive)
- Removedsupports-color@0.2.0(transitive)
Updatedchalk@^1.0.0