Skip to content

Commit

Permalink
patch for properly removing deleted files during watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed Jun 25, 2013
1 parent 4ada547 commit 9502b08
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
59 changes: 32 additions & 27 deletions lib/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,33 @@ var _watch = function(){

server.compiling();

// if there was an error, the whole project needs to be recompiled to
// get rid of the error message
if (global.options.error) {
options.debug.log('error, reloading project')
global.options.error = false;
return roots.compile_project(current_directory, server.reload);
}
// make sure the file wasn't deleted
if (fs.existsSync(file.fullPath)){

// if it's a dynamic file, the entire project needs to be recompiled
// so that references to it show up in other files
if (yaml_parser.detect(file.fullPath)){
options.debug.log('dynamic file changed, reloading project')
return roots.compile_project(current_directory, server.reload);
}
// if there was an error, the whole project needs to be recompiled to
// get rid of the error message
if (global.options.error) return compile_project('error');

// if it's a dynamic file, the entire project needs to be recompiled
// so that references to it show up in other files
if (yaml_parser.detect(file.fullPath)) return compile_project('dynamic file')

// ignored files that are modified actively are often dependencies
// for another non-ignored file. Until we have something like assetgraph
// in this project, the safest approach is to recompile the whole project
// when an ignored file is modified.
var ignored = global.options.ignore_files;
// ignored files that are modified are often dependencies
// for another non-ignored file. Until we have an asset graph
// in this project, the safest approach is to recompile the
// whole project when an ignored file is modified.
var ignored = global.options.ignore_files;

for (var i = 0; i < ignored.length; i++){
if (minimatch(path.basename(file.path), ignored[i].slice(1))) {
options.debug.log('ignored file changed, reloading project')
return roots.compile_project(current_directory, server.reload);
for (var i = 0; i < ignored.length; i++){
if (minimatch(path.basename(file.path), ignored[i].slice(1))) {
options.debug.log('ignored file changed, reloading project')
return roots.compile_project(current_directory, server.reload);
}
}
}

// otherwise, just compile the single file that was changed
if (fs.existsSync(file.fullPath)){
options.debug.log('single file compile')
roots.compile_project(file.fullPath, server.reload);
compile_single_file(file.fullPath);
} else {
// if the changed file was deleted, just remove it in the public folder
try {
fs.unlinkSync(output_path(file.fullPath));
} catch(e) {
Expand All @@ -77,3 +71,14 @@ var _watch = function(){
};

module.exports = { execute: _watch, needs_config: true };

function compile_single_file(file_path){
options.debug.log('single file compile');
roots.compile_project(file_path, server.reload);
}

function compile_project(reason){
options.debug.log(reason + ": full project compile");
global.options.error = false;
return roots.compile_project(current_directory, server.reload);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roots",
"version": "2.0.1",
"version": "2.0.2",
"description": "roots is a toolbox for building simple, beautiful, and efficient products for the web",
"keywords": [
"front-end",
Expand Down

0 comments on commit 9502b08

Please sign in to comment.