-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildutil.js
41 lines (38 loc) · 1.31 KB
/
buildutil.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
const fs = require('node:fs').promises;
const path = require('node:path');
const bundle = {
src: [
{ source: "src/index.html", dest: "public/index.html" },
{ source: "src/basic.html", dest: "public/basic.html" },
"audio/dothemath.mp3"
],
libs: {
js: [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/three/three.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
],
css: [
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
}
};
bundle.src.forEach(async file => {
if (typeof file === 'string') {
const dir = path.join("public", path.dirname(file));
await fs.mkdir(dir, { recursive: true })
.then(() => fs.copyFile(file, path.join(dir, path.basename(file))));
} else if (file.source && file.dest) {
const dir = path.dirname(file.dest);
await fs.mkdir(dir, { recursive: true })
.then(() => fs.copyFile(file.source, file.dest));
}
});
Object.keys(bundle.libs).forEach(type => {
bundle.libs[type].forEach(async file => {
const dir = path.join("public", "lib", type);
await fs.mkdir(dir, { recursive: true })
.then(() => fs.copyFile(file, path.join(dir, path.basename(file))));
;
});
});