Skip to content

Instantly share code, notes, and snippets.

@ZauberNerd
Created August 21, 2013 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZauberNerd/6295340 to your computer and use it in GitHub Desktop.
Save ZauberNerd/6295340 to your computer and use it in GitHub Desktop.
Screw you, Ruby. I'm doing it with node.js. ;) Watch for file changes in .scss files and compile them with sass. Read here, why: https://plus.google.com/109651506622355695262/posts/eCSwytEr2cW
var watchr = require('watchr'),
exec = require('child_process').exec,
isCompiling = false,
needsRecompile = false;
console.log('started watching sass files for changes...');
watchr.watch({
path: './scss',
preferredMethods: ['watchFile', 'watch'],
listener: changeListener
});
function changeListener(type, filePath) {
if (filePath.indexOf('.scss') > -1) {
console.log('sass file changed', filePath);
if (!isCompiling) {
isCompiling = true;
needsRecompile = false;
runSass(function () {
isCompiling = false;
console.log('Sass file compiled.');
notify('Sass file compiled.');
if (needsRecompile) {
changeListener(type, filePath);
}
});
} else {
needsRecompile = true;
}
}
}
function runSass(done) {
var sass = exec('sass scss/main.scss:scss/main.css', function (err, stdout, stderr) {
if (err) {
console.warn(err);
process.exit(1);
}
if (typeof done === 'function') { done(); }
});
}
function notify(text) {
var notification = exec('notify-send "' + text + '"');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment