Repository navigation
Expand file tree
/
Copy pathupdate-types.mjs
More file actions
83 lines (65 loc) · 2.46 KB
/
Copy pathupdate-types.mjs
File metadata and controls
83 lines (65 loc) · 2.46 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
#!/usr/bin/env node
/*
* Refreshes the bundled editor API type snapshots in ./types.
*
* It copies the compiled `<plugin>/_out/<plugin>.d.ts` declaration file of
* every plugin in the Phaser Editor v5 source tree into ./types, so this
* template can compile against the full editor API (all plugins).
*
* The editor source location is derived from the PHASEREDITOR5_HOME env var:
*
* $PHASEREDITOR5_HOME/phaser-editor-v5/workbench/source/editor/plugins
*
* Usage:
* PHASEREDITOR5_HOME=/path/to/parent npm run update-types
*/
import { existsSync, mkdirSync, readdirSync, copyFileSync, statSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const HOME = process.env.PHASEREDITOR5_HOME;
if (!HOME) {
console.error("Error: the PHASEREDITOR5_HOME environment variable is not set.");
console.error("");
console.error("Set it to the folder that contains the Phaser Editor source, e.g.:");
console.error(" export PHASEREDITOR5_HOME=/path/to/PhaserStudioInc");
console.error("so that the source lives at:");
console.error(" $PHASEREDITOR5_HOME/phaser-editor-v5/workbench");
process.exit(1);
}
const pluginsDir = join(HOME, "phaser-editor-v5", "workbench", "source", "editor", "plugins");
if (!existsSync(pluginsDir)) {
console.error(`Error: plugins directory not found:\n ${pluginsDir}`);
console.error("Check that PHASEREDITOR5_HOME points to the parent of phaser-editor-v5.");
process.exit(1);
}
const here = dirname(fileURLToPath(import.meta.url));
const typesDir = join(here, "types");
mkdirSync(typesDir, { recursive: true });
let copied = 0;
const names = [];
for (const entry of readdirSync(pluginsDir)) {
const outDir = join(pluginsDir, entry, "_out");
if (!existsSync(outDir) || !statSync(outDir).isDirectory()) {
continue;
}
for (const file of readdirSync(outDir)) {
if (!file.endsWith(".d.ts")) {
continue;
}
copyFileSync(join(outDir, file), join(typesDir, file));
names.push(file);
copied++;
}
}
if (copied === 0) {
console.error(`No .d.ts files found under:\n ${pluginsDir}/*/_out`);
console.error("Has the editor been built? (its _out folders must exist)");
process.exit(1);
}
names.sort();
console.log(`Copied ${copied} declaration file(s) into types/ from:`);
console.log(` ${pluginsDir}`);
console.log("");
for (const name of names) {
console.log(` - ${name}`);
}