-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathpostinstall.mjs
More file actions
87 lines (69 loc) · 2.36 KB
/
postinstall.mjs
File metadata and controls
87 lines (69 loc) · 2.36 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { join } from "node:path";
import { execSync } from "node:child_process";
import { access, rename, rm, mkdir, copyFile } from "node:fs/promises";
import nextjsTemplatePackageJson from "./templates/nextjs/package.json" with { type: "json" };
import solidjsTemplatePackageJson from "./templates/solidjs/package.json" with { type: "json" };
import vanillajsTemplatePackageJson from "./templates/vanillajs/package.json" with { type: "json" };
import electronTemplatePackageJson from "./templates/electron/package.json" with { type: "json" };
const rootNodeModules = join(process.cwd(), "./node_modules/@babylonjs/core");
const editorNodeModules = join(process.cwd(), "./editor/node_modules/@babylonjs/core");
const templates = [
{
name: "nextjs",
packageJson: nextjsTemplatePackageJson,
},
{
name: "solidjs",
packageJson: solidjsTemplatePackageJson,
},
{
name: "vanillajs",
packageJson: vanillajsTemplatePackageJson,
},
{
name: "electron",
packageJson: electronTemplatePackageJson,
},
];
async function renameAssets(path) {
try {
await access(path);
} catch (e) {
return;
}
const glslangJs = join(path, "assets/glslang/glslang.js");
try {
await access(glslangJs);
await rename(glslangJs, glslangJs.replace("glslang.js", "glslang.cjs"));
console.log("Renamed glslang.js to glslang.cjs");
} catch (e) {
// Catch silently.
}
const twgslJs = join(path, "assets/twgsl/twgsl.js");
try {
await access(twgslJs);
await rename(twgslJs, twgslJs.replace("twgsl.js", "twgsl.cjs"));
console.log("Renamed twgsl.js to twgsl.cjs");
} catch (e) {
// Catch silently.
}
}
await renameAssets(rootNodeModules);
await renameAssets(editorNodeModules);
async function packTemplates() {
for (const template of templates) {
const tgzName = `${template.packageJson.name}-v${template.packageJson.version}.tgz`;
execSync("yarn pack", {
cwd: join(import.meta.dirname, `templates/${template.name}`),
});
try {
await access(join(import.meta.dirname, "editor/templates"));
} catch (e) {
await mkdir(join(import.meta.dirname, "editor/templates"));
}
await copyFile(join(import.meta.dirname, `templates/${template.name}`, tgzName), join(import.meta.dirname, `editor/templates/${template.name}.tgz`));
await rm(join(import.meta.dirname, `templates/${template.name}`, tgzName));
console.log("Packed template: ", tgzName);
}
}
await packTemplates();