-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.js
45 lines (39 loc) · 1.6 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
import fs from 'fs'
import UglifyJS from 'uglify-js'
import { gzipSizeSync } from 'gzip-size'
// be uber-cool and use anylogger to print the logging in the build of anylogger :)
var log = function(l,m){console[l](m)}
var [ processName, script, command, ...args ] = process.argv
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
var v = pkg.version
;(function(){
var data
if (!command || command == 'minify') {
data = fs.readFileSync(pkg.iife, 'utf8')
data = UglifyJS.minify(data);
if (data.error) {
return log('error', data.error)
}
data = data.code;
fs.writeFileSync(pkg.min, data, 'utf8')
}
else {
data = fs.readFileSync(pkg.min, 'utf8')
}
var min = data.length
var gzip = gzipSizeSync(data)
if (!command || command == 'minify') {
log('info', 'created ' + pkg.min + ' (' + min + 'B, gzipped ~' + gzip + 'B)')
}
if (!command || command == 'docs') {
var readme = fs.readFileSync('./README.md', 'utf-8')
readme = readme.replace(/minified \d\d\d bytes/g, 'minified ' + min + ' bytes')
readme = readme.replace(/\[\d\d\d\]\(#gzip-size\)/g, '[' + gzip + '](#gzip-size)')
readme = readme.replace(/\<sub\>\<sup\>\d(\d)?\.\d(\d)?\.\d(\d)?(-([a-zA-Z0-9\.])*)\<\/sup\>\<\/sub\>/g, `<sub><sup>${v}</sup></sub>`)
readme = readme.replace(/&v=\d(\d)?\.\d(\d)?\.\d(\d)?/g, `&v=${v}`)
readme = readme.replace(/anylogger@\d(\d)?\.\d(\d)?\.\d(\d)?(-([a-zA-Z0-9\.])*)?/g, `anylogger@${v}`)
readme = readme.replace(/\>\=\d(\d)?\.\d(\d)?\.\d(\d)?/g, `>=${v}`)
fs.writeFileSync('README.md', readme, 'utf8')
log('info', 'updated README.md')
}
})()