@bitmagic/cli 0.1.21 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -20
- package/dist/cli.d.ts +10 -6
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/dev.d.ts +5 -1
- package/dist/commands/dev.js +82 -13
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/generate.d.ts +20 -0
- package/dist/commands/generate.js +100 -2
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/reload.d.ts +10 -0
- package/dist/commands/reload.js +82 -0
- package/dist/commands/reload.js.map +1 -0
- package/dist/commands/upgrade.js +6 -0
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/editor/journal.js +2 -2
- package/dist/editor/reload-bus.d.ts +38 -0
- package/dist/editor/reload-bus.js +66 -0
- package/dist/editor/reload-bus.js.map +1 -0
- package/dist/editor/server.d.ts +7 -0
- package/dist/editor/server.js +51 -9
- package/dist/editor/server.js.map +1 -1
- package/dist/editor/shell-page.d.ts +24 -5
- package/dist/editor/shell-page.js +295 -36
- package/dist/editor/shell-page.js.map +1 -1
- package/dist/editor/watch.d.ts +101 -0
- package/dist/editor/watch.js +228 -0
- package/dist/editor/watch.js.map +1 -0
- package/dist/generate/stream.d.ts +16 -3
- package/dist/generate/stream.js +22 -1
- package/dist/generate/stream.js.map +1 -1
- package/dist/generate/vehicle.d.ts +53 -0
- package/dist/generate/vehicle.js +227 -0
- package/dist/generate/vehicle.js.map +1 -0
- package/dist/local-port.d.ts +10 -0
- package/dist/local-port.js +23 -0
- package/dist/local-port.js.map +1 -1
- package/dist/project/dev-handle.d.ts +14 -0
- package/dist/project/dev-handle.js +53 -0
- package/dist/project/dev-handle.js.map +1 -0
- package/dist/scaffold/claude-settings.d.ts +41 -0
- package/dist/scaffold/claude-settings.js +98 -0
- package/dist/scaffold/claude-settings.js.map +1 -0
- package/dist/scaffold/project-files.js +36 -10
- package/dist/scaffold/project-files.js.map +1 -1
- package/dist/scaffold/project.js +5 -0
- package/dist/scaffold/project.js.map +1 -1
- package/dist/scaffold/upgrade-project.d.ts +6 -0
- package/dist/scaffold/upgrade-project.js +19 -1
- package/dist/scaffold/upgrade-project.js.map +1 -1
- package/dist/verify/browser.js +3 -1
- package/dist/verify/browser.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/edit.d.ts +0 -10
- package/dist/commands/edit.js +0 -148
- package/dist/commands/edit.js.map +0 -1
package/dist/commands/edit.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `bitmagic edit` — `dev` plus a visual scene editor.
|
|
3
|
-
*
|
|
4
|
-
* Everything `dev` does (build, `tsc --watch`, vite) plus a loopback sidecar that serves the editor
|
|
5
|
-
* shell and writes scene edits into `src/work/world.json`. Deliberately a superset rather than a
|
|
6
|
-
* flag on `dev`: `dev` is the plain run-the-game loop and must stay offline, minimal and boring,
|
|
7
|
-
* while `edit` opens a second port and a write path into the creator's project.
|
|
8
|
-
*/
|
|
9
|
-
import { defineCommand } from 'citty';
|
|
10
|
-
import { spawn, spawnSync } from 'child_process';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import { CliError } from '../errors.js';
|
|
13
|
-
import { loadProjectContext, projectBin } from '../project/context.js';
|
|
14
|
-
import { startEditorServer } from '../editor/server.js';
|
|
15
|
-
import { CORS_ALLOWED_PORT_MAX, CORS_ALLOWED_PORT_MIN } from '../local-port.js';
|
|
16
|
-
import { waitForServer } from '../verify/wait-for-server.js';
|
|
17
|
-
const DEFAULT_GAME_PORT = 3010;
|
|
18
|
-
const DEFAULT_EDITOR_PORT = 3011;
|
|
19
|
-
/**
|
|
20
|
-
* Both ports must sit inside the CDN's CORS window.
|
|
21
|
-
*
|
|
22
|
-
* The game port for the reason `local-port.ts` documents at length: a project fetches its forged
|
|
23
|
-
* level and its GLBs cross-origin from the portal CDN, which allowlists `localhost:3000`-`3199`
|
|
24
|
-
* and nothing else. Outside it the fetch is blocked, the world loads with no terrain, and the
|
|
25
|
-
* symptom reads as a broken game rather than a blocked request.
|
|
26
|
-
*
|
|
27
|
-
* The editor port is checked too, even though the shell itself fetches nothing from the CDN,
|
|
28
|
-
* because the two are adjacent by default and a creator who moves one will move the other — being
|
|
29
|
-
* told the rule once, at the point of the mistake, beats discovering it as a terrain-less world.
|
|
30
|
-
*/
|
|
31
|
-
function parsePort(value, fallback, flag) {
|
|
32
|
-
if (value === undefined)
|
|
33
|
-
return fallback;
|
|
34
|
-
const port = Number(value);
|
|
35
|
-
if (!Number.isInteger(port)) {
|
|
36
|
-
throw new CliError(`\`${flag}\` must be a whole number, got "${value}".`);
|
|
37
|
-
}
|
|
38
|
-
if (port < CORS_ALLOWED_PORT_MIN || port > CORS_ALLOWED_PORT_MAX) {
|
|
39
|
-
throw new CliError(`\`${flag}\` must be between ${CORS_ALLOWED_PORT_MIN} and ${CORS_ALLOWED_PORT_MAX}. `
|
|
40
|
-
+ 'The asset CDN only allows those origins; outside that window the game loads with no terrain.');
|
|
41
|
-
}
|
|
42
|
-
return port;
|
|
43
|
-
}
|
|
44
|
-
export const editCommand = defineCommand({
|
|
45
|
-
meta: {
|
|
46
|
-
name: 'edit',
|
|
47
|
-
description: 'Serve the game with a visual scene editor, saving edits to world.json.',
|
|
48
|
-
},
|
|
49
|
-
args: {
|
|
50
|
-
port: { type: 'string', description: `Port to serve the game on (default ${DEFAULT_GAME_PORT}).` },
|
|
51
|
-
'editor-port': { type: 'string', description: `Port to serve the editor on (default ${DEFAULT_EDITOR_PORT}).` },
|
|
52
|
-
},
|
|
53
|
-
async run({ args }) {
|
|
54
|
-
const context = loadProjectContext();
|
|
55
|
-
const tsc = projectBin(context.root, 'tsc');
|
|
56
|
-
const vite = projectBin(context.root, 'vite');
|
|
57
|
-
const gamePort = parsePort(args.port, DEFAULT_GAME_PORT, '--port');
|
|
58
|
-
const editorPort = parsePort(args['editor-port'], DEFAULT_EDITOR_PORT, '--editor-port');
|
|
59
|
-
if (gamePort === editorPort) {
|
|
60
|
-
throw new CliError('`--port` and `--editor-port` must differ — the game and the editor are two servers.');
|
|
61
|
-
}
|
|
62
|
-
// Build to completion first, exactly as `dev` does: every alias resolves into dist/, so serving
|
|
63
|
-
// before the first emit 404s every module.
|
|
64
|
-
console.log('Building…');
|
|
65
|
-
const build = spawnSync(tsc, [], { cwd: context.root, stdio: 'inherit' });
|
|
66
|
-
if (build.error) {
|
|
67
|
-
throw new CliError(`Could not run the TypeScript compiler: ${build.error.message}`);
|
|
68
|
-
}
|
|
69
|
-
if (build.status !== 0) {
|
|
70
|
-
throw new CliError('Build failed. Fix the errors above, then run `bitmagic edit` again.', build.status ?? 1);
|
|
71
|
-
}
|
|
72
|
-
// Before the children, so a port clash fails fast rather than after vite has claimed its port.
|
|
73
|
-
const editor = await startEditorServer({
|
|
74
|
-
root: context.root,
|
|
75
|
-
metadata: context.metadata,
|
|
76
|
-
gameId: context.metadata.gameId,
|
|
77
|
-
gamePort,
|
|
78
|
-
port: editorPort,
|
|
79
|
-
log: (message) => console.log(message),
|
|
80
|
-
});
|
|
81
|
-
const children = [
|
|
82
|
-
{
|
|
83
|
-
name: 'tsc --watch',
|
|
84
|
-
process: spawn(tsc, ['--watch', '--preserveWatchOutput'], { cwd: context.root, stdio: 'inherit' }),
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: 'vite',
|
|
88
|
-
process: spawn(vite, ['--port', String(gamePort), '--strictPort'], { cwd: context.root, stdio: 'inherit' }),
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
let shuttingDown = false;
|
|
92
|
-
let requestedByUser = false;
|
|
93
|
-
const shutdown = () => {
|
|
94
|
-
if (shuttingDown)
|
|
95
|
-
return;
|
|
96
|
-
shuttingDown = true;
|
|
97
|
-
for (const child of children)
|
|
98
|
-
child.process.kill('SIGTERM');
|
|
99
|
-
void editor.close();
|
|
100
|
-
};
|
|
101
|
-
process.on('SIGINT', () => {
|
|
102
|
-
requestedByUser = true;
|
|
103
|
-
shutdown();
|
|
104
|
-
});
|
|
105
|
-
process.on('SIGTERM', () => {
|
|
106
|
-
requestedByUser = true;
|
|
107
|
-
shutdown();
|
|
108
|
-
});
|
|
109
|
-
void waitForServer(gamePort, 30_000)
|
|
110
|
-
.then(() => {
|
|
111
|
-
console.log(`\nServing the game at ${`http://localhost:${gamePort}/`}`);
|
|
112
|
-
console.log(`Editor ready at ${editor.url}`);
|
|
113
|
-
console.log('\nOpen the editor URL, click an object and drag the gizmo.');
|
|
114
|
-
console.log('Every change is saved to src/work/world.json.');
|
|
115
|
-
// Named on startup so the agent that launched this command knows where to look without
|
|
116
|
-
// being told — the journal is the only record of intentions the editor cannot carry out
|
|
117
|
-
// itself, and of who changed what.
|
|
118
|
-
console.log(`Editor actions are journalled to ${path.relative(context.root, editor.journalPath)}`);
|
|
119
|
-
})
|
|
120
|
-
.catch(() => {
|
|
121
|
-
// The child-exit watcher below reports a vite that never comes up.
|
|
122
|
-
});
|
|
123
|
-
const failure = await new Promise((resolve) => {
|
|
124
|
-
let exitedCount = 0;
|
|
125
|
-
for (const child of children) {
|
|
126
|
-
child.process.on('error', (error) => {
|
|
127
|
-
shutdown();
|
|
128
|
-
resolve({ name: child.name, detail: `could not start: ${error.message}` });
|
|
129
|
-
});
|
|
130
|
-
child.process.on('exit', (code, signal) => {
|
|
131
|
-
exitedCount += 1;
|
|
132
|
-
if (!requestedByUser && !shuttingDown) {
|
|
133
|
-
shutdown();
|
|
134
|
-
resolve({ name: child.name, detail: `exited with code ${code}${signal ? ` (signal ${signal})` : ''}` });
|
|
135
|
-
}
|
|
136
|
-
else if (exitedCount === children.length) {
|
|
137
|
-
resolve(undefined);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
await editor.close();
|
|
143
|
-
if (failure) {
|
|
144
|
-
throw new CliError(`${failure.name} ${failure.detail}. \`bitmagic edit\` stopped.`);
|
|
145
|
-
}
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