Commit 4ed6de22 by Wes Todd

Converted watch to a boolean and got it actually working correctly

parent dc237d98
...@@ -53,7 +53,8 @@ var cli = meow({ ...@@ -53,7 +53,8 @@ var cli = meow({
'recursive', 'recursive',
'source-map-embed', 'source-map-embed',
'source-map-contents', 'source-map-contents',
'source-comments' 'source-comments',
'watch'
], ],
string: [ string: [
'functions', 'functions',
...@@ -64,8 +65,7 @@ var cli = meow({ ...@@ -64,8 +65,7 @@ var cli = meow({
'output', 'output',
'output-style', 'output-style',
'precision', 'precision',
'source-map-root', 'source-map-root'
'watch'
], ],
alias: { alias: {
c: 'source-comments', c: 'source-comments',
...@@ -82,7 +82,8 @@ var cli = meow({ ...@@ -82,7 +82,8 @@ var cli = meow({
'indent-width': 2, 'indent-width': 2,
linefeed: 'lf', linefeed: 'lf',
'output-style': 'nested', 'output-style': 'nested',
precision: 5 precision: 5,
recursive: true
} }
}); });
...@@ -139,7 +140,7 @@ function getEmitter() { ...@@ -139,7 +140,7 @@ function getEmitter() {
*/ */
function getOptions(args, options) { function getOptions(args, options) {
options.src = options.watch ? options.watch : args[0]; options.src = args[0];
if (args[1]) { if (args[1]) {
options.dest = path.resolve(process.cwd(), args[1]); options.dest = path.resolve(process.cwd(), args[1]);
...@@ -161,26 +162,20 @@ function getOptions(args, options) { ...@@ -161,26 +162,20 @@ function getOptions(args, options) {
*/ */
function watch(options, emitter) { function watch(options, emitter) {
var dir = options.watch; var glob = options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}';
var gaze = new Gaze(); var src = isSassFile(options.src) ? options.src : path.join(options.src, glob);
var graph = grapher.parseDir(path.resolve(path.dirname(src)), { loadPaths: options.includePath });
var watch = [];
if (dir === true) { // Add all files to watch list
dir = []; for (var i in graph.index) {
} else if (!Array.isArray(dir)) { watch.push(i);
dir = [dir];
} }
dir.push(options.src); var gaze = new Gaze();
dir = dir.map(function(d) { gaze.add(watch);
var glob = options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}';
return isSassFile(d) ? d : path.join(d, glob);
});
gaze.add(dir);
gaze.on('error', emitter.emit.bind(emitter, 'error')); gaze.on('error', emitter.emit.bind(emitter, 'error'));
var graph = grapher.parseDir(options.src, { loadPaths: options.includePath });
gaze.on('changed', function(file) { gaze.on('changed', function(file) {
var files = [file]; var files = [file];
graph.visitAncestors(file, function(parent) { graph.visitAncestors(file, function(parent) {
......
...@@ -207,6 +207,28 @@ describe('cli', function() { ...@@ -207,6 +207,28 @@ describe('cli', function() {
fs.appendFileSync(src, 'body{background:white}'); fs.appendFileSync(src, 'body{background:white}');
}, 500); }, 500);
}); });
it('should watch the full sass dep tree for a single file', function(done) {
var src = fixture('watching/index.scss');
var foo = fixture('watching/foo.scss');
fs.writeFileSync(foo, '');
var bin = spawn(cli, [
'--output-style', 'compressed',
'--watch', src
]);
bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
assert(data.trim() === 'body{background:white}');
done();
});
setTimeout(function() {
fs.appendFileSync(foo, 'body{background:white}');
}, 500);
});
}); });
describe('node-sass in.scss --output out.css', function() { describe('node-sass in.scss --output out.css', function() {
......
body{background:white}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment