Created
August 21, 2013 14:39
-
-
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
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 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