-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip.js
44 lines (44 loc) · 1.2 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
const fs = require('fs')
const archiver = require('archiver')
const path = require('path')
const childProcess = require('child_process')
let isPack = false
// 创建zip包
const createZip = function () {
return new Promise(function (resolve, reject) {
// 导向到启动了静态服务器的目录,
const output = fs.createWriteStream(path.join(__dirname, `../server/public/app.zip`))
const archive = archiver('zip')
archive.on('error', function (err) {
console.log(err)
resolve(false)
})
archive.on('end', function (err) {
if (err) {
console.log(err)
}
else {
// console.log('完成')
}
resolve(true)
})
archive.pipe(output)
archive.directory(path.join(__dirname, './test'), false)
archive.finalize()
})
}
const main = async function () {
// 上传CDN & 更改数据库版本号 & 设置是否必须要更新
if (isPack) {
return
}
isPack = true
const startTime = parseInt(new Date().getTime())
console.log('打包中')
await createZip()
const overTime2 = parseInt(new Date().getTime())
console.log(`打包耗时:${(overTime2 - startTime) / 1000} s`)
console.log('完成')
isPack = false
}
main()