Skip to content

Commit 617818a

Browse files
committed
watch for fields in .development
1 parent 06e71de commit 617818a

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

HISTORY.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1.0.2 / 2014-11-22
2+
======================
3+
4+
* consider changes for files listed in the `.development` property

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A watch utility for Component. It watches a `component.json`, then emits `resolv
99
Options:
1010

1111
- `root` <process.cwd()> - path where the main `component.json` is located.
12+
- `development` - if you want to watch for field within the `.development` property.
1213
- `extensions` - extensions to look up for `scripts` and `styles`. Default `{ scripts: ['js', 'json', 'html'], styles: ['css'] }`.
1314
- `fields` - fields to look up for `scripts` and `styles`. Default `{ scripts: ['scripts', 'json', 'templates'], styles: ['styles'] }`.
1415

index.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ var FIELDS = {
2626
],
2727
styles: [
2828
'styles',
29-
],
30-
}
29+
]
30+
};
3131

3232
module.exports = function componentWatcher(options) {
3333
options = options || {};
@@ -57,15 +57,15 @@ module.exports = function componentWatcher(options) {
5757
if (watcher) watcher.close();
5858
watch();
5959
return emitter;
60-
}
60+
};
6161

6262
emitter.close =
6363
emitter.stop = function () {
6464
if (!watcher) return emitter;
6565
watcher.close();
6666
watcher = null;
6767
return emitter;
68-
}
68+
};
6969

7070
watch();
7171

@@ -142,6 +142,19 @@ module.exports = function componentWatcher(options) {
142142
// only add globs if necessary
143143
if (!~globs.indexOf(path)) globs.push(path);
144144
});
145+
// do the same for development if --dev was passed
146+
if (options.development) {
147+
(json.development[field] || []).forEach(function (path) {
148+
if (path.slice(2) === '..') throw new Error('invalid path: ' + path);
149+
if (path.slice(1) === '/') throw new Error('invalid path: ' + path);
150+
151+
// ./ paths
152+
if (path[0] === '.') path = path.slice(2);
153+
154+
// only add globs if necessary
155+
if (!~globs.indexOf(path)) globs.push(path);
156+
});
157+
}
145158
}
146159

147160
function addPath(path) {
@@ -152,7 +165,7 @@ module.exports = function componentWatcher(options) {
152165
globs.push(path + '/**/*.' + ext);
153166
}
154167
}
155-
}
168+
};
156169

157170
function read(filename) {
158171
var json = fs.readFileSync(filename, 'utf8');

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "component-watcher",
33
"description": "build watching utility for component",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"author": {
66
"name": "Jonathan Ong",
77
"email": "[email protected]",

0 commit comments

Comments
 (0)