forked from unicar9/jizhi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
64 lines (51 loc) · 1.48 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
54
55
56
57
58
59
60
61
62
63
64
const chalk = require('chalk')
const fs = require('fs')
const path = require('path')
const archiver = require('archiver')
const log = console.log
const browsers = {
chrome: {
name: 'chrome',
labelColor: 'magenta'
},
firefox: {
name: 'firefox',
labelColor: 'yellow'
}
}
const getArchive = browser => {
const buildFolderPath = path.resolve(__dirname, `./builds/build_${browser}`)
if (!fs.existsSync(buildFolderPath)) {
log(chalk.yellow(`${browser} build folder NOT found...`))
return
}
const chalkLabel = chalk.keyword(`${browsers[browser].labelColor}`)
const label = chalkLabel(browser)
log(label, chalk.green(`${browser} build folder found...`))
const zipPath = path.resolve(__dirname, `./builds/${browser}.zip`)
const output = fs.createWriteStream(zipPath)
const archive = archiver('zip', {
zlib: { level: 9 }
})
output.on('close', () => {
const fileSizeMB = (archive.pointer() / 1048576).toFixed(2)
log(label, chalk.green(`Zip file size: ${fileSizeMB} MB`))
log(label, 'archiver has been finalized and the output file descriptor has closed.')
})
output.on('end', () => log(label, 'Data has been drained'))
archive.on('warning', err => {
if (err.code === 'ENOENT') {
log(label, 'EEEEEE')
} else {
throw err
}
})
archive.on('error', err => {
throw err
})
archive.pipe(output)
archive.directory(buildFolderPath, false)
archive.finalize()
}
getArchive('chrome')
getArchive('firefox')