-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.js
53 lines (47 loc) · 1.15 KB
/
build.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
var fs = require('fs');
var rollup = require('rollup');
var uglify = require('uglify-js');
var version = process.env.VERSION || require('./package.json').version;
var banner =
'/*!\n' +
' * md5-js v' + version + '\n' +
' * (c) ' + new Date().getFullYear() + ' hapjs\n' +
' * Released under the MIT License.\n' +
' */'
rollup.rollup({
entry: './src/md5.js'
})
.then(function (bundle) {
var code = bundle.generate({
format: 'umd',
banner: banner,
moduleName: 'md5'
}).code;
var res = uglify.minify(code, {
fromString: true,
output: {
preamble: banner,
ascii_only: true
}
});
return [
write('md5.js', code),
write('md5.min.js', res.code)
];
})
.catch(console.log);
function write (dest, code) {
return new Promise(function (resolve, reject) {
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(blue(dest) + ' ' + getSize(code))
resolve()
})
})
}
function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
}
function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}