-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.js
63 lines (51 loc) · 1.06 KB
/
utils.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Created by Administrator on 2017/8/10.
*/
/**
* Created by admin on 2017/7/26.
*/
var path = require('path')
var fs = require('fs')
exports.resolve = function(obj) {
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (obj[i] && Object.prototype.toString.call(obj[i]) === '[object Object]') {
obj[i] = this.resolve(obj[i]);
} else {
obj[i] = trim(obj[i]);
}
}
return obj;
}
function trim() {
var args = Array.prototype.slice.call(arguments);
args = args.map(function (v) {
try {
return JSON.parse(v);
} catch (e) {
console.error(e);
return '';
}
});
switch (args.length) {
case 0:
return '';
case 1:
return args[0];
default:
return args;
}
}
exports.after = function(root,files,hash) {
Object.keys(files)
.forEach(function (file) {
console.log(file)
file = path.resolve(root, file);
var content = fs.readFileSync(file, 'utf8');
if (/index\.html/i.test(file)) {
content = content
.replace(/(js\/config\.js)/, 'js/config.js?'+hash);
fs.writeFileSync(file, content);
}
});
}