-
Notifications
You must be signed in to change notification settings - Fork 23
/
update.js
52 lines (48 loc) · 1.37 KB
/
update.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
var fs = require('fs')
var zlib = require('zlib')
var version = require('../vue/package.json').version
var themeconfPath = 'themes/vue/_config.yml'
var installPath = 'src/v2/guide/installation.md'
var themeconfig = fs.readFileSync(themeconfPath, 'utf-8')
var installation = fs.readFileSync(installPath, 'utf-8')
fs.writeFileSync(
themeconfPath,
themeconfig.replace(/vue_version: .*/, 'vue_version: ' + version)
)
var sizes = {
dev: 'vue.js',
min: 'vue.min.js',
gz: 'vue.min.js',
ro_gz: 'vue.runtime.min.js'
}
var pending = []
Object.keys(sizes).forEach(file => {
var filesize = fs.statSync('../vue/dist/' + sizes[file], 'utf-8').size
if (!/gz$/.test(file)) {
sizes[file] = (filesize / 1024).toFixed(2)
} else {
pending.push(new Promise((resolve, reject) => {
fs.readFile('../vue/dist/' + sizes[file], (err, buf) => {
if (err) return reject(err)
zlib.gzip(buf, (err, buf) => {
if (err) return reject(err)
sizes[file] = (buf.length / 1024).toFixed(2)
resolve()
})
})
}))
}
})
Promise.all(pending).then(() => {
fs.writeFileSync(
installPath,
installation
.replace(/vue_version: .*/, 'vue_version: ' + version)
.replace(/(\w+)_size:.*/g, function (m, p1) {
return p1 + '_size: "' + sizes[p1] + '"'
})
)
console.log(sizes)
}).catch(err => {
console.error(err)
})