-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (40 loc) · 1.2 KB
/
index.js
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
/**
* Created by HENG on 2015/5/22.
*/
var fs = require("fs");
var path = require("path");
var mapDoImages = require("./limit.js");
var concurrent = 3;
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var i = 0;
(function next() {
var file = list[i++];
if (!file) return done(null, results);
file = path.resolve(dir, file);
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
next();
});
} else {
results.push(file);
next();
}
});
})();
});
};
var hasPath = process.argv.indexOf("--path");
var compressPath = (hasPath !== -1 && process.argv[hasPath + 1]) ? process.argv[hasPath + 1] : null;
if(compressPath) {
walk(compressPath, function (err, data) {
console.log("find these images: ", data);
mapDoImages(data, concurrent);
});
} else {
console.log("no enter dir");
}