Skip to content

Instantly share code, notes, and snippets.

@yuanchuan
Created May 10, 2012 14:39
Show Gist options
  • Save yuanchuan/2653472 to your computer and use it in GitHub Desktop.
Save yuanchuan/2653472 to your computer and use it in GitHub Desktop.
in favor of nodejs
#!/usr/bin/env node
var fs = require('fs')
, path = require('path')
, exec = require('child_process').exec
, src_css = '../css/'
, target_css = '../../css/'
, src_js = '../js/'
, target_js = '../../js/'
, compiler = 'tools/compiler.jar';
fs.readdir(src_css, function(err, files) {
if (err) throw err;
files
.filter(function(f){return /\.css$/.test(f);})
.forEach(function(f){
fs.readFile(src_css + f, function(err, cnt){
var min =
cnt.toString()
.replace(/\r*\n*/g,'')
.replace(/\s*([:|;|,|{|}])\s*/g, function(s,p1){ return p1;})
.replace(/;}/g,'}')
.replace(/\/\*.*?\*\//g, '');
fs.writeFile(target_css + f, min, function(err) {
if (err) throw err;
console.log(f + ' compressed.');
});
});
});
});
fs.readdir(src_js, function(err, files) {
if (err) throw err;
files
.filter(function(f){ return /\.js$/.test(f);})
.forEach(function(f){
var cmd = [
'java -jar ' + compiler
, '--js ' + src_js + f
, '--js_output_file ' + target_js + f
].join(' ');
exec(cmd, function(){
console.log(f + ' compressed.');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment