Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created February 25, 2013 20:00
Show Gist options
  • Save dhigginbotham/5032754 to your computer and use it in GitHub Desktop.
Save dhigginbotham/5032754 to your computer and use it in GitHub Desktop.
var lessFiles = __dirname + '/../src'
, cssFiles = __dirname + '/../public/css';
var less = require('less')
, fs = require('fs');
var onModify = function(filename){
fs.readFile(lessFiles + '/' + filename, function(err, lessCss){
if(err)
throw new Error(err);
lessCss = lessCss.toString();
less.render(lessCss, function(err, css) {
var newFilename = cssFiles + '/' + filename.replace(/\.less$/, '.css');
fs.writeFile(newFilename, css);
});
});
}
// module.exports = function() {
fs.readdir(lessFiles, function(err, files){
if(err)
throw new Error(err);
files.filter(function(path){
return path.match(/\.less$/); // Filter not .less files
}).forEach(function(path){
fs.watch(lessFiles + '/' + path, function(event, filename){
if(filename){
console.log('This file is getting lessd' + filename);
onModify(filename);
}
});
});
});
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment