2011-12-12 18:44:16 +08:00
|
|
|
var fs = require('fs'),
|
|
|
|
uglifyjs = require('uglify-js'),
|
|
|
|
deps = require('./deps.js').deps;
|
|
|
|
|
|
|
|
exports.getFiles = function (compsBase32) {
|
|
|
|
var memo = {},
|
|
|
|
comps;
|
|
|
|
|
|
|
|
if (compsBase32) {
|
|
|
|
comps = parseInt(compsBase32, 32).toString(2).split('');
|
|
|
|
console.log('Managing dependencies...')
|
|
|
|
}
|
|
|
|
|
|
|
|
function addFiles(srcs) {
|
|
|
|
for (var j = 0, len = srcs.length; j < len; j++) {
|
|
|
|
memo[srcs[j]] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i in deps) {
|
|
|
|
if (comps) {
|
|
|
|
if (parseInt(comps.pop(), 2) === 1) {
|
|
|
|
console.log('\t* ' + i);
|
|
|
|
addFiles(deps[i].src);
|
|
|
|
} else {
|
|
|
|
console.log('\t ' + i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addFiles(deps[i].src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var files = [];
|
|
|
|
|
|
|
|
for (var src in memo) {
|
|
|
|
files.push('src/' + src);
|
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.uglify = function (code) {
|
|
|
|
var pro = uglifyjs.uglify;
|
|
|
|
|
|
|
|
var ast = uglifyjs.parser.parse(code);
|
|
|
|
ast = pro.ast_mangle(ast);
|
|
|
|
ast = pro.ast_squeeze(ast, {keep_comps: false});
|
|
|
|
ast = pro.ast_squeeze_more(ast);
|
|
|
|
|
|
|
|
return pro.gen_code(ast);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.combineFiles = function (files) {
|
|
|
|
var content = '';
|
|
|
|
for (var i = 0, len = files.length; i < len; i++) {
|
2011-12-13 04:15:06 +08:00
|
|
|
content += fs.readFileSync(files[i], 'utf8') + '\r\n\r\n';
|
2011-12-12 18:44:16 +08:00
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.save = function (savePath, compressed) {
|
|
|
|
fs.writeFileSync(savePath, compressed, 'utf8');
|
|
|
|
}
|