Skip to content

Instantly share code, notes, and snippets.

@justinrainbow
Created March 27, 2012 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinrainbow/2220346 to your computer and use it in GitHub Desktop.
Save justinrainbow/2220346 to your computer and use it in GitHub Desktop.
Auto building of YUI3 modules
var watch = require('watch'),
spawn = require('child_process').spawn,
queue = [],
proc;
function run(path) {
if (proc) {
return queue.push(path);
}
proc = spawn('ant', ['all'], {
cwd: __dirname + '/src/' + path,
env: {
PATH: process.env.PATH
}
});
console.log("Building " + (path || "all"));
proc.on('exit', function (code) {
proc = null;
if (queue.length > 0) {
run(queue.shift());
}
});
}
function compile(filename) {
var relativePath = filename.replace(__dirname+'/src/', ''),
moduleName = relativePath.split('/')[0];
console.log("Module: " + moduleName + " just changed");
// don't compile any build_tmp files
if (/build_tmp/.test(filename)) {
return;
}
// ignore any of the skui or skui-loader modules
if (moduleName === 'skui' || moduleName === 'skui-loader') {
return;
}
// if a js or css file changed - just compile that module
if (/\.(js|css)$/.test(filename)) {
return run(moduleName);
} else {
return run("");
}
}
watch.createMonitor(__dirname+'/src', function (monitor) {
monitor.on("created", function (f, stat) {
// Handle file changes
console.log("Created: " + f);
compile(f);
});
monitor.on("changed", function (f, curr, prev) {
// Handle new files
console.log("Modified: " + f);
compile(f);
});
monitor.on("removed", function (f, stat) {
// Handle removed files
console.log("Removed: " + f);
compile(f);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment