-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.js
39 lines (34 loc) · 1.11 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
const {
copySync,
readFileSync,
outputFileSync,
readdirSync,
createWriteStream,
ensureDirSync,
removeSync,
} = require('fs-extra'); // eslint-disable-line import/no-extraneous-dependencies
const { join } = require('path');
const archiver = require('archiver'); // eslint-disable-line import/no-extraneous-dependencies
const dir = (...s) => join(__dirname, ...s);
// 取 dist 下的 index.html
const index = readFileSync(dir('dist', 'index.html'), 'utf8');
copySync(dir('dist'), dir('temp'), {
filter(src) {
return !src.includes('/index.html');
},
});
outputFileSync(dir('temp', 'index.html'), index.replace(/hash: '.*?',/, "hash: '',"));
ensureDirSync(dir('release'));
const files = readdirSync(dir('temp'));
const output = createWriteStream(dir('release', 'Prism.zip'));
const archive = archiver('zip', { zlib: { level: 9 } });
output.on('close', () => {
global.console.log(`Prism.zip [${archive.pointer()} bytes]`);
removeSync(dir('temp'));
});
archive.on('error', err => {
throw err;
});
archive.pipe(output);
files.forEach(file => archive.file(dir('temp', file), { name: file }));
archive.finalize();