Skip to content

Instantly share code, notes, and snippets.

@ViliamKopecky
Created May 14, 2012 19:22
Show Gist options
  • Save ViliamKopecky/2695839 to your computer and use it in GitHub Desktop.
Save ViliamKopecky/2695839 to your computer and use it in GitHub Desktop.
LESSwatch
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