-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfigureMd5.js
39 lines (30 loc) · 1.13 KB
/
configureMd5.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
/**
* Created by Ellery1 on 16/6/6.
*/
var fs = require('fs'),
crypto = require('crypto');
var dest = './public/dest',
baseJs = dest + '/base.min.js',
indexJs = dest + '/index.js',
style = dest + '/style.min.css';
function md5(content) {
return crypto.createHash('md5').update(content).digest('hex');
}
console.log('configuring file md5...');
var baseMd5 = md5(fs.readFileSync(baseJs)),
indexMd5 = md5(fs.readFileSync(indexJs)),
styleMd5 = md5(fs.readFileSync(style));
console.log('base.min.js:' + baseMd5);
console.log('index.js:' + indexMd5);
console.log('style.min.css:' + styleMd5);
fs.renameSync(baseJs, baseJs.replace('.js', '@' + baseMd5 + '.js'));
fs.renameSync(indexJs, indexJs.replace('.js', '@' + indexMd5 + '.js'));
fs.renameSync(style, style.replace('.css', '@' + styleMd5 + '.css'));
fs.writeFileSync('./ver.json', JSON.stringify({
base: '@' + baseMd5,
index: '@' + indexMd5,
style: '@' + styleMd5
}, null, 4));
//复制一个index.js,开发时候方便
fs.writeFileSync('./public/dest/index.js', fs.readFileSync(indexJs.replace('.js', '@' + indexMd5 + '.js')));
console.log('all done!');