Last active
August 29, 2015 13:56
-
-
Save civersen/9106385 to your computer and use it in GitHub Desktop.
A simple node.js script that monitors changes to javascript files in my development directory tree. Once a change occurs, the script creates a minified version using the Closure compiler.
This file contains hidden or 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 watch = require("watch"); | |
var cc = require("closurecompiler"); | |
var fs = require("fs"); | |
watch.watchTree("/Users/chris/Dropbox/Development",{"ignoreDotFiles":true},function(f,cstat,pstat){ | |
if(typeof(f)=="string" && f.toLowerCase().indexOf(".js")>1 && f.toLowerCase().indexOf(".min.")==-1){ | |
if(cstat.nlink===1){ | |
var fname = f.substring(f.lastIndexOf("/")+1); | |
var fpath = f.substr(0,f.lastIndexOf("/")); | |
fname = [fname.slice(0,fname.lastIndexOf(".")),fname.slice(fname.lastIndexOf(".")+1)]; | |
var nf = fpath+"/"+fname[0]+".min."+fname[1]; | |
console.log("Compiling File: "+fname.join(".")+" ...") | |
var minfile = cc.compile([f], | |
{ compilation_level : "SIMPLE_OPTIMIZATIONS" }, | |
function(error,result){ | |
if(result){ | |
fs.writeFile(nf,result,function(err){ | |
if(err){ | |
console.log("Error: Could not output to: "+nf); | |
throw err; | |
} | |
else { console.log("Completed: "+fname.join(".")); } | |
}) | |
} | |
else { console.log("Error: "+error)} | |
} | |
); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment