-
Notifications
You must be signed in to change notification settings - Fork 60
/
pack_dev_release.js
49 lines (41 loc) · 1.33 KB
/
pack_dev_release.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
const fsPromise = require('fs/promises');
const statics = [
'assets',
'dist',
'project.json',
];
const target = 'dev_release/' + process.argv[2];
(async () => {
await fsPromise.mkdir(target, { recursive: true });
await Promise.all(statics.map((source) => {
return fsPromise.cp(source, target + '/' + source, { recursive: true, filter: (src) => (!src.includes('LICENSE')) });
}));
fsPromise.writeFile(target + '/index.html', JSON.stringify((await listAll(target)).map(a => a.replace(new RegExp('^' + target), '')).filter(a => a !== '/index.html')));
})();
async function listAll(src) {
const res = [];
await listAllInner(src);
return res;
async function listAllInner(src) {
if (src.endsWith('.')) {
return;
}
var isSrcExists = false;
try {
await fsPromise.access(src);
isSrcExists = true;
} catch (e) {
isSrcExists = false;
}
if (isSrcExists) {
if ((await fsPromise.stat(src)).isDirectory()) { // 复制目录
var files = await fsPromise.readdir(src);
for (let file of files) {
await listAllInner(src + '/' + file);
}
} else { // 复制文件
res.push(src);
}
}
}
}