Commit ad4c44ce by Michael Mifsud

Update watched file list when files are added or removed (#1539)

Currently we build the Sass import graph when the CLI watcher is
started. However the graph is not update updated when files are
added or deleted. The latest is a big deal but the former results
in new files not triggered rebuilds when they're changed. The only
way to currently resolve this is to restart the CLI watcher.

This patch rebuilds the Sass import graph when files are added or
deleted to the watch always works as expected.

Fixes #1538
parent a04e84de
...@@ -230,16 +230,24 @@ function getOptions(args, options) { ...@@ -230,16 +230,24 @@ function getOptions(args, options) {
*/ */
function watch(options, emitter) { function watch(options, emitter) {
var watch = []; var buildGraph = function(options) {
var graphOptions = {
loadPaths: options.includePath,
extensions: ['scss', 'sass', 'css']
};
if (options.directory) {
var graph = grapher.parseDir(options.directory, graphOptions);
} else {
var graph = grapher.parseFile(options.src, graphOptions);
}
var graphOptions = { loadPaths: options.includePath, extensions: ['scss', 'sass', 'css'] }; return graph;
var graph;
if (options.directory) {
graph = grapher.parseDir(options.directory, graphOptions);
} else {
graph = grapher.parseFile(options.src, graphOptions);
} }
var watch = [];
var graph = buildGraph(options);
// Add all files to watch list // Add all files to watch list
for (var i in graph.index) { for (var i in graph.index) {
watch.push(i); watch.push(i);
...@@ -260,6 +268,14 @@ function watch(options, emitter) { ...@@ -260,6 +268,14 @@ function watch(options, emitter) {
} }
}); });
}); });
gaze.on('added', function(file) {
graph = buildGraph(options);
});
gaze.on('deleted', function(file) {
graph = buildGraph(options);
});
} }
/** /**
......
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