-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.js
57 lines (48 loc) · 1.45 KB
/
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
const fs = require('fs');
const path = require('path');
const SRC_DIR = path.resolve(__dirname, 'src');
const DIST_DIR = path.resolve(__dirname, 'dist');
const copy = (src, dest) => {
const stats = fs.statSync(src);
if (stats.isDirectory()) {
fs.mkdirSync(dest, { recursive: true });
for (const file of fs.readdirSync(src)) {
copy(path.join(src, file), path.join(dest, file));
}
} else {
fs.copyFileSync(src, dest);
}
};
const clean = () => {
if (fs.existsSync(DIST_DIR)) {
fs.rmSync(DIST_DIR, { recursive: true, force: true });
}
};
const build = () => {
console.log('Building the extension...');
clean();
fs.mkdirSync(DIST_DIR);
['css', 'js', 'html', 'fonts', 'icon', 'manifest.json'].forEach((item) => {
const srcPath = path.join(SRC_DIR, item);
const destPath = path.join(DIST_DIR, item);
if (fs.existsSync(srcPath)) {
copy(srcPath, destPath);
}
});
const htmlDir = path.join(DIST_DIR, 'html');
if (fs.existsSync(htmlDir)) {
fs.readdirSync(htmlDir).forEach((file) => {
if (file.endsWith('.hbs')) {
fs.unlinkSync(path.join(htmlDir, file));
}
});
}
console.log("Build complete! Files are ready in the 'dist' folder.");
};
const command = process.argv[2];
if (command === 'clean') {
clean();
console.log("Cleaned the 'dist' folder.");
} else {
build();
}