Skip to content

Instantly share code, notes, and snippets.

@rmariuzzo
Last active December 21, 2015 14:39
Show Gist options
  • Save rmariuzzo/6321203 to your computer and use it in GitHub Desktop.
Save rmariuzzo/6321203 to your computer and use it in GitHub Desktop.
A simple NodeJS script to watch for changes in a specific less and js file. When changes detected then bash script will be executed for to compile less files and to uglify js scripts.
clear
curdir="${0%/*}"
uglifyjs -v \
$curdir/jquery/jquery.js \
$curdir/twbs/js/bootstrap.js \
$curdir/superfish/superfish.js \
$curdir/site/js/site.js \
-o $curdir/../../js/app.js \
-m
echo 'JS files compiled successfully!'
clear
curdir="${0%/*}"
lessc -x \
$curdir/site/less/site.less \
$curdir/../../style.css
echo 'LESS files compiled successfully!'
require('shelljs/global');
var fs = require('fs'),
path = require('path');
var curdir = path.resolve(__dirname),
jsCompiling = false,
lessCompiling = false;
fs.watch(curdir + '/site/less/site.less', function(event, filename) {
if (event === 'change' && ! lessCompiling) {
echo('Change detected: ' + filename);
lessCompiling = true;
exec('sh ' + curdir + '/compile-less.sh', function() {
lessCompiling = false;
});
}
});
fs.watch(curdir + '/site/js/site.js', function(event, filename) {
if (event === 'change' && ! jsCompiling) {
echo('Change detected: ' + filename);
jsCompiling = true;
exec('sh ' + curdir + '/compile-js.sh', function() {
jsCompiling = false;
});
}
});
echo('Watching for changes...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment