Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Watch as a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Mar 28, 2015
1 parent fb5c2a4 commit bd1d246
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
34 changes: 9 additions & 25 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ var cli = meow({
'recursive',
'source-map-embed',
'source-map-contents',
'source-comments'
'source-comments',
'watch'
],
string: [
'functions',
Expand All @@ -64,8 +65,7 @@ var cli = meow({
'output',
'output-style',
'precision',
'source-map-root',
'watch'
'source-map-root'
],
alias: {
c: 'source-comments',
Expand Down Expand Up @@ -139,7 +139,7 @@ function getEmitter() {
*/

function getOptions(args, options) {
options.src = args[0] || options.watch;
options.src = args[0];

if (args[1]) {
options.dest = path.resolve(process.cwd(), args[1]);
Expand All @@ -161,30 +161,14 @@ function getOptions(args, options) {
*/

function watch(options, emitter) {
var watchDir = isSassFile(options.watch) ? path.dirname(path.resolve(options.watch)) : options.watch,
glob = options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}',
gaze = new Gaze(),
dir;

if (watchDir === true) {
dir = [];
} else if (!Array.isArray(watchDir)) {
dir = [watchDir];
}

// only add the src file if it is not already
// in the array as the watch path
if (options.watch !== options.src) {
dir.push(options.src);
}
dir = dir.map(function(d) {
return isSassFile(d) ? d : path.join(d, glob);
});
var glob = options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}';
var src = isSassFile(options.src) ? options.src : path.join(options.src, glob);
var gaze = new Gaze();

gaze.add(dir);
gaze.add(src);
gaze.on('error', emitter.emit.bind(emitter, 'error'));

var graph = grapher.parseDir(watchDir, { loadPaths: options.includePath });
var graph = grapher.parseDir(path.resolve(path.dirname(src)), { loadPaths: options.includePath });

gaze.on('changed', function(file) {
var files = [file];
Expand Down
1 change: 0 additions & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ describe('cli', function() {
bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
assert(data.trim() === 'body{background:white}');
fs.unlinkSync(fixtures('watching/index.css'));
done();
});

Expand Down

0 comments on commit bd1d246

Please # to comment.