Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (45 loc) · 1.37 KB
/
Copy pathindex.js
File metadata and controls
48 lines (45 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var inputMinType = "uglifyjs";
var compressor = require("node-minify");
var walk = function(currentDirPath, callback) {
fs.readdirSync(currentDirPath).forEach(function(name) {
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, stat);
} else if (stat.isDirectory()) {
walk(filePath, callback);
}
});
}
var minifyAll = function(dir, options, callback){
options = options || {};
options.type = options.type || inputMinType;
walk(dir, function(path, result){
if (path.substr(-3) === ".js" || path.substr(-4) === ".css"){
if (!options.silent){
console.log("found file: " + path);
}
new compressor.minify({
type: options.type,
fileIn: path,
fileOut: path,
callback: callback || function(err, min){
if(err){
console.log(err);
}
}
});
}
});
};
if (require.main === module) {
var input = process.argv,
inputDir = input[2],
inputMinType = input[3] || inputMinType;
minifyAll(inputDir);
} else {
module.exports = minifyAll;
}