-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-browser.js
67 lines (49 loc) · 1.67 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
60
61
62
63
64
65
66
67
const fs = require('fs');
const path = require('path');
function concatFiles(inputFolder, outputFilePath, ext, order) {
const order2 = order.map(o => o + ext);
const files = fs.readdirSync(inputFolder)
.filter(file => file.endsWith(ext))
.sort((a, b) => {
a = order2.indexOf(a);
b = order2.indexOf(a);
a = a < 0 ? Number.MAX_VALUE : a;
b = b < 0 ? Number.MAX_VALUE : b;
return a - b;
});
let output = "";
const exportDefaultReplace = ext === ".d.ts" ? "declare " : "";
for (const file of files) {
const filepath = path.join(inputFolder, file);
let s = fs.readFileSync(filepath, 'utf-8');
s = s.replace(/import .*\n/g, "")
.replace(/export default /g, exportDefaultReplace)
.replace(/export \{.*\n?/g, "");
output += s + "\n";
}
fs.writeFileSync(outputFilePath, output, "utf-8");
}
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);
}
}
const packageData = JSON.parse(fs.readFileSync("package.json"));
const name = packageData.name
.replaceAll("@", "")
.replaceAll("/", "_")
.replaceAll("-", "_");
const version = packageData.version;
fs.mkdirSync(`browser/${name}/lib`, { recursive: true });
const ORDER = [
"ScriptNode"
];
fs.writeFileSync(`browser/${name}/library.txt`, version);
concatFiles("out", `browser/${name}/lib/${name}.js`, ".js", ORDER);
concatFiles("types", `browser/${name}/lib/${name}.d.ts`, ".d.ts", ORDER);
copyFiles("src", `browser/${name}/`, ".scene");
copyFiles("src", `browser/${name}/`, ".components");