Created
May 14, 2012 19:22
-
-
Save ViliamKopecky/2695839 to your computer and use it in GitHub Desktop.
LESSwatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watch_dir = './www/less'; | |
var files = { | |
// 'input.less': 'output.css' | |
'./www/less/screen.less': './www/css/screen.css' | |
}; | |
var interval = 100; // ms | |
var fs = require('fs'); | |
var exec = require('child_process').exec; | |
var dirty = true; | |
var compile = function(input, output) { | |
exec("lessc -x " + input + " > " + output, function(error, stdout, stderr) { | |
if(stdout) | |
console.log(stdout); | |
if(stderr) | |
console.log("ERROR: "+stderr); | |
if(!error) | |
console.log("COMPILED | %s > %s | %s\r\n", input, output, new Date().toLocaleTimeString()); | |
}); | |
}; | |
var compileAll = function() { | |
for(var key in files) { | |
compile(key, files[key]); | |
} | |
}; | |
var check = function() { | |
if(dirty) { | |
dirty = false; | |
compileAll(); | |
} | |
setTimeout(check, interval); | |
}; | |
fs.watch(watch_dir, function() { | |
dirty = true; | |
}); | |
// run checking | |
check(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment