@moloodev/cli 0.0.0-stage → 0.3.0
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/bin/moloo.mjs +11 -0
- package/package.json +48 -3
- package/src/cli.ts +91 -0
- package/src/dev-host-app.tsx +688 -0
- package/src/dev-host-client.ts +940 -0
- package/src/dev-host-entry.tsx +12 -0
- package/src/dev-host.css +19 -0
- package/src/dev-server.ts +365 -0
- package/src/editor-views.ts +201 -0
- package/src/index.ts +25 -0
- package/src/publish-bundle.ts +149 -0
- package/src/publish.ts +124 -0
- package/src/read-editor-manifest.ts +113 -0
- package/src/three-local-loaders.ts +102 -0
- package/src/view-page.ts +57 -0
- package/src/yjs-log.ts +16 -0
- package/README.md +0 -3
package/bin/moloo.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moloodev/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"moloo": "./bin/moloo.mjs"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./build": "./src/editor-views.ts",
|
|
11
|
+
"./publish": "./src/publish.ts",
|
|
12
|
+
"./manifest": "./src/read-editor-manifest.ts"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@babel/parser": "7.29.8",
|
|
16
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
17
|
+
"esbuild": "^0.28.2",
|
|
18
|
+
"shadcn": "^4.21.0",
|
|
19
|
+
"tailwindcss": "^4.3.3",
|
|
20
|
+
"tw-animate-css": "^1.4.0",
|
|
21
|
+
"vite": "^8.2.2",
|
|
22
|
+
"tsx": "^4.23.13",
|
|
23
|
+
"@tabler/icons-react": "^3.46.0",
|
|
24
|
+
"react": "^19.2.8",
|
|
25
|
+
"react-dom": "^19.2.8",
|
|
26
|
+
"@moloodev/editor-sdk": "0.3.0",
|
|
27
|
+
"@moloodev/editor-store": "0.3.0",
|
|
28
|
+
"@moloodev/platform": "0.3.0",
|
|
29
|
+
"@moloodev/ui": "0.3.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^24.13.3",
|
|
33
|
+
"typescript": "^7.0.2",
|
|
34
|
+
"@types/react": "^19.2.18",
|
|
35
|
+
"@types/react-dom": "^19.2.7",
|
|
36
|
+
"@moloodev/typescript-config": "0.3.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"bin",
|
|
43
|
+
"src",
|
|
44
|
+
"!src/**/*.test.ts",
|
|
45
|
+
"!src/**/*.test.tsx"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"test": "tsx --test 'src/**/*.test.ts'"
|
|
50
|
+
}
|
|
6
51
|
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { startEditorDevServer } from "./dev-server";
|
|
3
|
+
import { buildEditorPackage } from "./editor-views";
|
|
4
|
+
import { publishEditorPackage } from "./publish";
|
|
5
|
+
|
|
6
|
+
const EDITOR_USAGE =
|
|
7
|
+
"Usage: moloo editor <dev|build|publish> [--dir <path>] [--out-dir <path>] [--port <port>] [--view-port <port>] [--api-url <https-origin>]";
|
|
8
|
+
const USAGE = `Usage: moloo <command>\n\nCommands:\n editor dev | build | publish\n\n${EDITOR_USAGE}`;
|
|
9
|
+
|
|
10
|
+
type Command = (args: readonly string[]) => Promise<number>;
|
|
11
|
+
|
|
12
|
+
const editorCommands: Record<string, Command> = {
|
|
13
|
+
async dev(args) {
|
|
14
|
+
const hostPort = readPortFlag(args, "--port") ?? 4300;
|
|
15
|
+
const viewPort = readPortFlag(args, "--view-port");
|
|
16
|
+
const server = await startEditorDevServer({
|
|
17
|
+
packageRoot: packageRootFlag(args),
|
|
18
|
+
hostPort,
|
|
19
|
+
...(viewPort !== undefined ? { viewPort } : {}),
|
|
20
|
+
});
|
|
21
|
+
console.log(`${server.editorId} dev host -> ${server.hostOrigin}`);
|
|
22
|
+
console.log(`${server.editorId} view origin -> ${server.viewOrigin}`);
|
|
23
|
+
await new Promise<void>((resolveStop) => {
|
|
24
|
+
const stop = () => {
|
|
25
|
+
process.off("SIGINT", stop);
|
|
26
|
+
process.off("SIGTERM", stop);
|
|
27
|
+
void server.close().finally(resolveStop);
|
|
28
|
+
};
|
|
29
|
+
process.on("SIGINT", stop);
|
|
30
|
+
process.on("SIGTERM", stop);
|
|
31
|
+
});
|
|
32
|
+
return 0;
|
|
33
|
+
},
|
|
34
|
+
async build(args) {
|
|
35
|
+
const packageRoot = packageRootFlag(args);
|
|
36
|
+
const outDir = resolve(packageRoot, readFlag(args, "--out-dir") ?? "dist");
|
|
37
|
+
const built = await buildEditorPackage(packageRoot, outDir);
|
|
38
|
+
console.log(
|
|
39
|
+
`${built.id} built -> ${built.scriptPath} (${String(Buffer.byteLength(built.script, "utf8"))} bytes)`,
|
|
40
|
+
);
|
|
41
|
+
return 0;
|
|
42
|
+
},
|
|
43
|
+
async publish(args) {
|
|
44
|
+
const result = await publishEditorPackage(packageRootFlag(args), { apiUrl: readFlag(args, "--api-url") });
|
|
45
|
+
console.log(`${result.id} ${String(result.status)} ${result.body}`);
|
|
46
|
+
return result.status === 200 || result.status === 201 ? 0 : 1;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const groups: Record<string, { usage: string; commands: Record<string, Command> }> = {
|
|
51
|
+
editor: { usage: EDITOR_USAGE, commands: editorCommands },
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export async function runCli(argv: readonly string[]): Promise<number> {
|
|
55
|
+
const [groupName, commandName, ...rest] = argv;
|
|
56
|
+
const group = groupName === undefined ? undefined : groups[groupName];
|
|
57
|
+
const wantsHelp = argv.includes("--help") || argv.includes("-h");
|
|
58
|
+
if (!group) {
|
|
59
|
+
(wantsHelp ? console.log : console.error)(USAGE);
|
|
60
|
+
return wantsHelp ? 0 : 1;
|
|
61
|
+
}
|
|
62
|
+
const command = commandName === undefined ? undefined : group.commands[commandName];
|
|
63
|
+
if (!command || wantsHelp) {
|
|
64
|
+
(wantsHelp ? console.log : console.error)(group.usage);
|
|
65
|
+
return wantsHelp ? 0 : 1;
|
|
66
|
+
}
|
|
67
|
+
return command(rest);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function packageRootFlag(args: readonly string[]): string {
|
|
71
|
+
return resolve(readFlag(args, "--dir") ?? process.cwd());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function readFlag(args: readonly string[], flag: string): string | undefined {
|
|
75
|
+
const index = args.indexOf(flag);
|
|
76
|
+
if (index === -1) return undefined;
|
|
77
|
+
return args[index + 1];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function readPortFlag(args: readonly string[], flag: string): number | undefined {
|
|
81
|
+
const raw = readFlag(args, flag);
|
|
82
|
+
if (raw === undefined) return undefined;
|
|
83
|
+
if (!/^[0-9]+$/.test(raw)) {
|
|
84
|
+
throw new Error(`Invalid ${flag}: must be an integer port`);
|
|
85
|
+
}
|
|
86
|
+
const port = Number(raw);
|
|
87
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
88
|
+
throw new Error(`Invalid ${flag}: must be between 0 and 65535`);
|
|
89
|
+
}
|
|
90
|
+
return port;
|
|
91
|
+
}
|