forked from xuejianxianzun/PixivBatchDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.js
70 lines (56 loc) · 1.42 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
// build 命令
const fs = require('fs')
const path = require('path')
const copy = require('recursive-copy')
const archiver = require('archiver')
const packName = 'powerfulpixivdownloader'
// 复制一些文件到 dist 目录
async function copys() {
return new Promise(async (resolve, reject) => {
// 复制 static 文件夹的内容
await copy('./static', './dist', {
overwrite: true,
}).catch(function (error) {
console.error('Copy failed: ' + error)
reject()
})
// 复制静态文件
await copy('./src', './dist', {
overwrite: true,
filter: ['manifest.json'],
})
await copy('./', './dist', {
overwrite: true,
filter: ['README.md', 'README-EN.md', 'LICENSE'],
}).then(function (results) {
resolve()
console.log('Copy success')
})
})
}
// 打包 dist 目录
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('dist', packName)
archive.finalize()
}
// 构建
async function build() {
await copys()
pack()
}
build()
console.log('Start pack')