-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.js
52 lines (41 loc) · 1.05 KB
/
zip.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
process.on(`uncaughtException`, error => console.error(error))
process.on(`unhandledRejection`, error => console.error(error))
const path = require('path')
const fs = require('fs-extra')
const archiver = require('archiver')
const tempDir = path.join(__dirname, 'build-zip')
const outFile = path.join(__dirname, 'testfront-devtools.zip')
const items = [
`build`,
`background.js`,
`content.js`,
`devtools.html`,
`devtools.js`,
`manifest.json`
]
fs.removeSync(tempDir)
fs.removeSync(outFile)
for (let item of items) {
fs.copySync(path.join(__dirname, item), path.join(tempDir, item))
}
const outStream = fs.createWriteStream(outFile)
const archive = archiver(`zip`, { zlib: { level: 9 } })
outStream.on(`close`, () => {
fs.removeSync(tempDir)
})
outStream.on(`end`, () => {
fs.removeSync(tempDir)
})
archive.on(`warning`, error => {
if (error.code === 'ENOENT') {
console.warn(error)
} else {
throw error
}
})
archive.on(`error`, error => {
throw error
})
archive.pipe(outStream)
archive.directory(tempDir, false)
archive.finalize()