-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-build.js
59 lines (45 loc) · 1.58 KB
/
post-build.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
/* eslint-disable */
/* eslint-enable semi, indent */
"use strict";
const path = require('node:path');
const fs = require('node:fs');
const buildDir = path.resolve(process.cwd(), 'dist');
const srcDir = path.resolve(process.cwd(), 'src');
async function recursiveRemoveDirectoryFiles(dir) {
if(!fs.existsSync(dir)) return;
for(const filename of (await fs.promises.readdir(dir))) {
const stats = await fs.promises.stat(path.join(dir, filename));
if(stats.isDirectory()) {
await recursiveRemoveDirectoryFiles(path.join(dir, filename));
} else {
await fs.promises.unlink(path.join(dir, filename));
}
}
await fs.promises.rmdir(dir);
}
async function recursiveRemoveUnnecessaryFiles(dir) {
if(!fs.existsSync(dir)) return;
for(const filename of (await fs.promises.readdir(dir))) {
const stats = await fs.promises.stat(path.join(dir, filename));
if(stats.isDirectory()) {
await recursiveRemoveUnnecessaryFiles(path.join(dir, filename));
} else if(
/.spec./.test(filename) /* ||
filename === '_types.js'*/ ||
filename.endsWith('.tmp') ||
filename.indexOf('.d.js') > -1 ||
// filename === 'test.js' ||
filename === 'test.d.ts'
) {
await fs.promises.unlink(path.join(dir, filename));
}
}
}
async function main() {
// await recursiveRemoveDirectoryFiles(path.join(buildDir, 'types'));
await recursiveRemoveUnnecessaryFiles(buildDir);
if(process.env.NODE_ENV === 'production') {
await recursiveRemoveDirectoryFiles(path.join(process.cwd(), '.vscode'));
}
}
main().catch(console.error);