-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtest.js
37 lines (31 loc) · 771 Bytes
/
test.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
'use strict';
var fs = require('fs'),
path = require('path'),
ug = require('./index');
function ugFile(srcFile, dstFile) {
fs.writeFileSync(dstFile, ug(fs.readFileSync(srcFile)));
}
function inplace(file) {
fs.writeFileSync(file, ug(fs.readFileSync(file)));
}
if (process.argv[2]) {
var dir = path.resolve('.', process.argv[2]);
ugDirInplace(dir);
} else {
ugFile('tmp.js', 'out.js');
}
function ugDirInplace(dir) {
(function walk(dir) {
if (fs.statSync(dir).isFile()) {
if (path.extname(dir) === '.js') {
console.log(dir);
inplace(dir);
}
} else {
fs.readdirSync(dir).forEach(function (filename) {
var filepath = path.resolve(dir, filename);
walk(filepath);
});
}
})(dir);
}