-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-browser.js
59 lines (40 loc) · 1.32 KB
/
build-browser.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
const fs = require('fs');
const path = require('path');
function copyFiles(srcFolder, outFolder, ext) {
const files = fs.readdirSync(srcFolder)
.filter(file => file.endsWith(ext));
for (const file of files) {
const from = path.join(srcFolder, file);
const to = path.join(outFolder, file);
fs.copyFileSync(from, to);
}
}
function processJSFiles(fromFolder, toFolder) {
const files = fs.readdirSync(fromFolder)
.filter(file => file.endsWith(".js"));
for (const file of files) {
if (file === "index.js") {
continue;
}
const from = path.join(fromFolder, file);
const to = path.join(toFolder, file);
let content = fs.readFileSync(from, "utf8");
const importRegex = /from "([^"]+)"/g;
content = content.replace(importRegex, (match, p1) => {
return `from "${p1}.js"`;
});
console.log(`Writing ${to}`);
fs.writeFileSync(to, content);
}
}
const packageData = JSON.parse(fs.readFileSync("package.json"));
const name = packageData.name
.replaceAll("@", "")
.replaceAll("/", "_")
.replaceAll("-", "_");
const version = packageData.version;
fs.mkdirSync(`browser/${name}`, { recursive: true });
fs.writeFileSync(`browser/${name}/library.txt`, version);
copyFiles("src", `browser/${name}/`, ".scene");
copyFiles("src", `browser/${name}/`, ".components");
processJSFiles("out", `browser/${name}/`);