-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
49 lines (40 loc) · 1.19 KB
/
main.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 fs = require('fs');
const archiver = require('archiver');
const modclean = require('modclean');
const distDir = 'dist';
const targetDir = 'node_modules';
const distPath = `${distDir}/${targetDir}.zip`;
const zipArchive = async () => {
const zipPath = `${targetDir}.zip`;
const output = fs.createWriteStream(zipPath);
console.log('archive...')
output.on('close', function() {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
fs.copyFileSync(zipPath, distPath);
fs.unlinkSync(zipPath);
console.log("done");
});
const archive = archiver('zip', {
zlib: { level: 9 }
});
archive.pipe(output);
archive.directory(targetDir, false);
await archive.finalize();
}
const clearDir = (dir) => {
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true, force: true });
}
}
(async() => {
clearDir(distDir);
fs.mkdirSync(distDir);
try {
let mc = modclean({ignorePatterns:['example*', 'examples']});
mc.clean();
await zipArchive();
}catch(e){
console.error(e.stack);
}
})();