handlebar-rider
Advanced tools
Comparing version 0.1.8 to 0.1.10
@@ -14,3 +14,3 @@ | ||
red : '\u001b[31m', | ||
blue: '\u001b[34m', | ||
blue: '\u001b[36m', | ||
green: '\u001b[32m', | ||
@@ -79,4 +79,4 @@ yellow: '\u001b[33m', | ||
var fileHasChanged = function(event, filename){ | ||
console.log(color.green + '[handlebar-rider] change detected to file, recompiling' + color.reset); | ||
console.log(color.blue + '[handlebar-rider] change detected to file, recompiling' + color.reset); | ||
compileTemplates(); | ||
@@ -89,8 +89,17 @@ | ||
var directoryHasChanged = function(event, filename){ | ||
console.log(color.blue + '[handlebar-rider] new or removed file detected, recompiling' + color.reset); | ||
readAndCompile(rider.in); | ||
readAndCompile(rider.in, rider.watch); | ||
}; | ||
var watchers = [] | ||
var unwatchAll = function(){ | ||
for(var w = 0; w < watchers.length; w++){ | ||
watchers[w].close(); | ||
} | ||
} | ||
//compiles to output destination | ||
@@ -134,3 +143,3 @@ var compileTemplates = function(){ | ||
console.log(color.red + '[handlebar-rider] ERROR! ' + color.reset + '\n' + e); | ||
console.log(color.red + '[handlebar-rider] warning - deleted or now missing file ' + color.reset); | ||
@@ -156,3 +165,4 @@ } | ||
fs.writeFileSync(rider.out, output, 'utf8'); | ||
console.log(color.green + '[handlebar-rider] compiled template directory ' + rider.in + ' to ' + rider.out + color.reset); | ||
} catch(e){ | ||
@@ -169,2 +179,7 @@ | ||
rider.templates = [] | ||
// unwatch all the files | ||
unwatchAll(); | ||
//read files in the directory | ||
@@ -177,4 +192,3 @@ readTemplatesDirectory(dir, function(err, files) { | ||
throw new Error('directory does not exists: ' + dir) | ||
rider.templates = [] | ||
for(var f = 0; f < files.length; f++){ | ||
@@ -188,3 +202,6 @@ | ||
// watch the file | ||
if(watch) fs.watch(info[1], fileHasChanged) | ||
if(watch) { | ||
//fs.unwatchFile(info[1], null) | ||
watchers.push(fs.watch(info[1], fileHasChanged)) | ||
} | ||
@@ -206,4 +223,8 @@ // get the template namespace by using the extra directory | ||
// watch the directory for new / removed files | ||
if(watch) fs.watch(info[1], directoryHasChanged) | ||
if(watch){ | ||
//fs.unwatchFile(info[1], null) | ||
watchers.push(fs.watch(info[1], directoryHasChanged)) | ||
} | ||
} | ||
@@ -257,5 +278,2 @@ | ||
//compile on startup | ||
console.log(color.green + '[handlebar-rider] compiling template directory ' + dir + ' to ' + rider.out + color.reset); | ||
if(rider.watch) | ||
@@ -273,2 +291,3 @@ console.log(color.yellow + '[handlebar-rider] watching template directory ' + dir + color.reset); | ||
console.log(color.yellow + '[handlebar-rider] watching template directory ' + rider.in + color.reset); | ||
rider.watch = true; | ||
readAndCompile(rider.in, true); | ||
@@ -279,4 +298,3 @@ | ||
exports.compile = function(){ | ||
console.log(color.green + '[handlebar-rider] compiling template directory ' + rider.in + ' to ' + rider.out + color.reset); | ||
rider.watch = false; | ||
readAndCompile(rider.in, false); | ||
@@ -283,0 +301,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description" : "Compiles/watches a directory of handlebar templates files and precompiles into single js output file", | ||
"version" : "0.1.8", | ||
"version" : "0.1.10", | ||
@@ -8,0 +8,0 @@ "repository" : { |
11360
194