-
-
Notifications
You must be signed in to change notification settings - Fork 217
/
pack.js
72 lines (58 loc) · 1.53 KB
/
pack.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
65
66
67
68
69
70
71
72
// build 命令
const fs = require('fs')
const path = require('path')
const copy = require('recursive-copy')
const archiver = require('archiver')
const packName = 'powerfulpixivdownloader-online'
const distPath = './dist'
// 复制一些文件到发布目录
async function copys() {
return new Promise(async (resolve, reject) => {
// 复制 static 文件夹的内容
await copy('./src/static', distPath, {
overwrite: true,
}).catch(function (error) {
console.error('Copy failed: ' + error)
reject()
})
// 复制 src 目录里需要的文件
await copy('./src', distPath, {
overwrite: true,
filter: ['manifest.json', 'declarative_net_request_rules.json'],
})
// 复制根目录一些文件
await copy('./', distPath, {
overwrite: true,
filter: ['README*.md', 'LICENSE'],
}).then(function (results) {
resolve()
console.log('Copy success')
})
})
}
// 打包发布目录
function pack() {
const zipName = path.resolve(__dirname, packName + '.zip')
const output = fs.createWriteStream(zipName)
const archive = archiver('zip', {
zlib: { level: 9 }, // Sets the compression level.
})
archive.on('error', function (err) {
throw err
})
archive.on('finish', () => {
console.log(`Pack success`)
})
// pipe archive data to the file
archive.pipe(output)
// 添加文件夹
archive.directory(distPath, packName)
archive.finalize()
}
// 构建
async function build() {
await copys()
pack()
}
build()
console.log('Start pack')