@hewel/zgui-cli 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +95 -0
- package/README.md +25 -2
- package/THIRD_PARTY_NOTICES.md +37 -0
- package/inspector-bundle/app.css +138 -0
- package/inspector-bundle/app.mjs +7317 -0
- package/inspector-bundle/app.mjs.map +1 -0
- package/inspector-bundle/build-info.json +345 -0
- package/inspector-bundle/components.css +1546 -0
- package/inspector-bundle/manifest.json +31 -0
- package/package.json +60 -4
- package/src/cli.ts +488 -0
- package/src/doctor.ts +278 -0
- package/src/index.ts +17 -0
- package/src/init.ts +458 -0
- package/src/inspect.ts +160 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 2,
|
|
3
|
+
"id": "dev.example.inspector",
|
|
4
|
+
"hostApiVersion": 1,
|
|
5
|
+
"entry": "app.mjs",
|
|
6
|
+
"sourceMap": "app.mjs.map",
|
|
7
|
+
"styles": [
|
|
8
|
+
"components.css",
|
|
9
|
+
"app.css"
|
|
10
|
+
],
|
|
11
|
+
"assets": [],
|
|
12
|
+
"fonts": [],
|
|
13
|
+
"capabilities": {
|
|
14
|
+
"namedSockets": [
|
|
15
|
+
"devInspect"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"styleSystem": {
|
|
19
|
+
"name": "lightningcss",
|
|
20
|
+
"profile": "lightningcss-v1",
|
|
21
|
+
"configDigest": "sha256:864ab49f77e8240f0abc9c85c23764f2eb766d29c61091c83c908d47e69f1ee1"
|
|
22
|
+
},
|
|
23
|
+
"artifactDigests": {
|
|
24
|
+
"app.css": "sha256:f58e7612c5b82b63c314052b4df1e017307a1dd14288666e23304aeab5ec94f3",
|
|
25
|
+
"app.mjs": "sha256:f754c46be31e253f984eecf22ce099b30327a7d58b75f2d7fb907399de7b80ad",
|
|
26
|
+
"app.mjs.map": "sha256:0eaf2d5abdc42cc604efdb0eb6e8c079f48581a0b9464f06772143b7d0b7ecf2",
|
|
27
|
+
"build-info.json": "sha256:1e5dc4632dbcc1127e23c60658717f9cae04cb0118812508265ad607d2eace4f",
|
|
28
|
+
"components.css": "sha256:0545a0bafe0fe80c5e3f926f1cd0b1cd10bef5a111b6c4c84efd4532040ff4d3"
|
|
29
|
+
},
|
|
30
|
+
"buildId": "sha256:1894c60075d46e426ec2cf097c25ac62aa752a7a29c9deda8fdf84070cff5d9f"
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hewel/zgui-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official npm/Bun CLI for building, running, inspecting, and packaging zgui-js applications",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/hewel/zgui-js.git",
|
|
13
|
+
"directory": "packages/cli"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/hewel/zgui-js#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/hewel/zgui-js/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"zgui",
|
|
21
|
+
"zgui-js",
|
|
22
|
+
"cli",
|
|
23
|
+
"desktop",
|
|
24
|
+
"wayland",
|
|
25
|
+
"native-ui",
|
|
26
|
+
"solid-js"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"bun": ">=1.4.4"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./src/index.ts",
|
|
34
|
+
"default": "./src/index.ts"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"src",
|
|
40
|
+
"inspector-bundle",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"NOTICE",
|
|
44
|
+
"THIRD_PARTY_NOTICES.md"
|
|
45
|
+
],
|
|
46
|
+
"bin": {
|
|
47
|
+
"zgui-js": "./src/cli.ts"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"prepack": "bun pack-resources.ts",
|
|
51
|
+
"postpack": "bun pack-resources.ts --clean"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@hewel/zgui-build": "0.1.0"
|
|
55
|
+
},
|
|
56
|
+
"optionalDependencies": {
|
|
57
|
+
"@hewel/zgui-host-linux-x64": "0.1.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/bun": "1.4.4"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import {
|
|
3
|
+
buildApplication,
|
|
4
|
+
devApplication,
|
|
5
|
+
packageApplication,
|
|
6
|
+
previewApplication,
|
|
7
|
+
resolveApplication,
|
|
8
|
+
watchApplication,
|
|
9
|
+
type PreviewApplicationOptions,
|
|
10
|
+
type ResolvedApplication,
|
|
11
|
+
} from "@hewel/zgui-build";
|
|
12
|
+
import { buildSmoke, resolveSmokeTsconfigPath, typecheckProject } from "@hewel/zgui-build/internal";
|
|
13
|
+
import { readFileSync } from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { formatDoctorReport, runDoctor } from "./doctor.ts";
|
|
16
|
+
import { runInitCli } from "./init.ts";
|
|
17
|
+
import { runInspect } from "./inspect.ts";
|
|
18
|
+
|
|
19
|
+
const usage = `Usage: zgui-js <command> [options]
|
|
20
|
+
|
|
21
|
+
Commands:
|
|
22
|
+
init Scaffold a new zgui-js app (desktop-app or wayland-shell)
|
|
23
|
+
dev Resolve/build zgui-host, open the app, and reload on changes
|
|
24
|
+
build Type-check and publish an immutable application package
|
|
25
|
+
preview Build the app and host, then capture an offscreen native frame
|
|
26
|
+
package Assemble a self-contained runnable Linux app directory
|
|
27
|
+
doctor Verify Bun, zgui-host ABI, Wayland, Vulkan, portal, tsrs, and oxlint
|
|
28
|
+
inspect Query --dev-inspect socket, toggle visual picker, or open --ui Inspector window
|
|
29
|
+
smoke Build the compiler/runtime smoke fixture
|
|
30
|
+
|
|
31
|
+
Application defaults to the current directory (counter at the repository root).
|
|
32
|
+
Relative file and directory flags are resolved from the current working directory.
|
|
33
|
+
build --watch Watch packages without starting a host
|
|
34
|
+
build --bytecode Compile entry, chunks, and workers to QuickJS bytecode (.qjsb)
|
|
35
|
+
--capabilities-file F Merge capability declarations into build, dev, preview, or package
|
|
36
|
+
--host-root DIR Build the host from this Cargo checkout and run it there
|
|
37
|
+
--host-executable PATH Run this prebuilt host instead of resolving packages/Cargo
|
|
38
|
+
dev --exit-after-ms N Close the native app after N milliseconds
|
|
39
|
+
dev --width N Override initial window width in logical pixels
|
|
40
|
+
dev --height N Override initial window height in logical pixels
|
|
41
|
+
dev --title TEXT Override initial window title
|
|
42
|
+
dev --max-js-stack-bytes N Override the QuickJS stack size limit in bytes
|
|
43
|
+
dev --layer-config F Use an upstream layer-shell configuration
|
|
44
|
+
dev --pure-shell Start without a primary window (requires shellSurfaces or sessionLock)
|
|
45
|
+
dev --dev-inspect PATH Enable dev-only read-only inspector Unix socket
|
|
46
|
+
dev --strict-typecheck Gate dev publication on tsrs before reloading
|
|
47
|
+
preview --watch Re-run offscreen scenarios on changes, without a desktop host
|
|
48
|
+
preview --profile F --fixture F --scenario F --out NEW_DIRECTORY
|
|
49
|
+
package --out DIR [--bytecode] [--desktop-entry] [--pure-shell]
|
|
50
|
+
doctor [--json] [--host-root DIR] [--host-executable PATH]
|
|
51
|
+
inspect [--ui] [--host-root DIR] [--host-executable PATH] [--] <zgui-host inspect args...>
|
|
52
|
+
init [DIR] [--template desktop-app|wayland-shell] [--name NAME] [--force]`;
|
|
53
|
+
|
|
54
|
+
type PreviewOptions = Pick<
|
|
55
|
+
PreviewApplicationOptions,
|
|
56
|
+
"watch" | "profile" | "fixture" | "scenario" | "out"
|
|
57
|
+
>;
|
|
58
|
+
|
|
59
|
+
type HostOptions = Pick<PreviewApplicationOptions, "hostRoot" | "hostExecutable">;
|
|
60
|
+
|
|
61
|
+
type Command =
|
|
62
|
+
| { command: "smoke" }
|
|
63
|
+
| { command: "init"; args: string[] }
|
|
64
|
+
| ({ command: "doctor"; json: boolean } & HostOptions)
|
|
65
|
+
| ({ command: "inspect"; args: string[]; ui: boolean } & HostOptions)
|
|
66
|
+
| ({
|
|
67
|
+
command: "build";
|
|
68
|
+
selector?: string;
|
|
69
|
+
watch: boolean;
|
|
70
|
+
bytecode: boolean;
|
|
71
|
+
capabilitiesFile?: string;
|
|
72
|
+
} & HostOptions)
|
|
73
|
+
| ({
|
|
74
|
+
command: "dev";
|
|
75
|
+
selector?: string;
|
|
76
|
+
capabilitiesFile?: string;
|
|
77
|
+
exitAfterMs?: string;
|
|
78
|
+
width?: string;
|
|
79
|
+
height?: string;
|
|
80
|
+
title?: string;
|
|
81
|
+
maxJsStackBytes?: string;
|
|
82
|
+
layerConfig?: string;
|
|
83
|
+
devInspect?: string;
|
|
84
|
+
pureShell: boolean;
|
|
85
|
+
strictTypecheck: boolean;
|
|
86
|
+
} & HostOptions)
|
|
87
|
+
| ({
|
|
88
|
+
command: "preview";
|
|
89
|
+
selector?: string;
|
|
90
|
+
capabilitiesFile?: string;
|
|
91
|
+
} & PreviewOptions &
|
|
92
|
+
HostOptions)
|
|
93
|
+
| ({
|
|
94
|
+
command: "package";
|
|
95
|
+
selector?: string;
|
|
96
|
+
capabilitiesFile?: string;
|
|
97
|
+
out?: string;
|
|
98
|
+
bytecode: boolean;
|
|
99
|
+
desktopEntry: boolean;
|
|
100
|
+
pureShell: boolean;
|
|
101
|
+
} & HostOptions);
|
|
102
|
+
|
|
103
|
+
function parseInspect(args: string[]): Extract<Command, { command: "inspect" }> {
|
|
104
|
+
let hostRoot: string | undefined;
|
|
105
|
+
let hostExecutable: string | undefined;
|
|
106
|
+
let ui = false;
|
|
107
|
+
const forwarded: string[] = [];
|
|
108
|
+
let passthroughAll = false;
|
|
109
|
+
while (args.length > 0) {
|
|
110
|
+
const arg = args.shift()!;
|
|
111
|
+
if (passthroughAll) {
|
|
112
|
+
forwarded.push(arg);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (arg === "--") {
|
|
116
|
+
passthroughAll = true;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (arg === "--ui") {
|
|
120
|
+
ui = true;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (arg === "--host-root") {
|
|
124
|
+
const val = args.shift();
|
|
125
|
+
if (!val || val.startsWith("--")) throw new Error("--host-root requires a value");
|
|
126
|
+
hostRoot = path.resolve(val);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (arg === "--host-executable") {
|
|
130
|
+
const val = args.shift();
|
|
131
|
+
if (!val || val.startsWith("--")) throw new Error("--host-executable requires a value");
|
|
132
|
+
hostExecutable = path.resolve(val);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
forwarded.push(arg);
|
|
136
|
+
}
|
|
137
|
+
return { command: "inspect", args: forwarded, ui, hostRoot, hostExecutable };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function parse(args: string[]): Command {
|
|
141
|
+
const command = args.shift();
|
|
142
|
+
if (command === "init") {
|
|
143
|
+
return { command: "init", args };
|
|
144
|
+
}
|
|
145
|
+
if (command === "inspect") {
|
|
146
|
+
return parseInspect(args);
|
|
147
|
+
}
|
|
148
|
+
if (
|
|
149
|
+
command !== "dev" &&
|
|
150
|
+
command !== "build" &&
|
|
151
|
+
command !== "preview" &&
|
|
152
|
+
command !== "package" &&
|
|
153
|
+
command !== "doctor" &&
|
|
154
|
+
command !== "smoke"
|
|
155
|
+
) {
|
|
156
|
+
throw new Error(usage);
|
|
157
|
+
}
|
|
158
|
+
const flags = new Map<string, string | true>();
|
|
159
|
+
const allowed = new Set([
|
|
160
|
+
...(command === "doctor" || command === "smoke" ? [] : ["--app", "--capabilities-file"]),
|
|
161
|
+
...(command === "build" || command === "preview" ? ["--watch"] : []),
|
|
162
|
+
...(command === "build" || command === "package" ? ["--bytecode"] : []),
|
|
163
|
+
...(command === "build" ||
|
|
164
|
+
command === "dev" ||
|
|
165
|
+
command === "preview" ||
|
|
166
|
+
command === "package" ||
|
|
167
|
+
command === "doctor"
|
|
168
|
+
? ["--host-root", "--host-executable"]
|
|
169
|
+
: []),
|
|
170
|
+
...(command === "doctor" ? ["--json"] : []),
|
|
171
|
+
...(command === "dev"
|
|
172
|
+
? [
|
|
173
|
+
"--exit-after-ms",
|
|
174
|
+
"--width",
|
|
175
|
+
"--height",
|
|
176
|
+
"--title",
|
|
177
|
+
"--max-js-stack-bytes",
|
|
178
|
+
"--layer-config",
|
|
179
|
+
"--dev-inspect",
|
|
180
|
+
"--pure-shell",
|
|
181
|
+
"--strict-typecheck",
|
|
182
|
+
]
|
|
183
|
+
: []),
|
|
184
|
+
...(command === "preview" ? ["--profile", "--fixture", "--scenario", "--out"] : []),
|
|
185
|
+
...(command === "package" ? ["--out", "--desktop-entry", "--pure-shell"] : []),
|
|
186
|
+
]);
|
|
187
|
+
const booleanFlags = new Set([
|
|
188
|
+
"--watch",
|
|
189
|
+
"--bytecode",
|
|
190
|
+
"--pure-shell",
|
|
191
|
+
"--desktop-entry",
|
|
192
|
+
"--json",
|
|
193
|
+
"--strict-typecheck",
|
|
194
|
+
]);
|
|
195
|
+
let directory: string | undefined;
|
|
196
|
+
while (args.length) {
|
|
197
|
+
const arg = args.shift()!;
|
|
198
|
+
if (arg === "--") continue;
|
|
199
|
+
if (!arg.startsWith("-")) {
|
|
200
|
+
if (command === "doctor" || command === "smoke") {
|
|
201
|
+
throw new Error(`zgui-js ${command} does not accept positional arguments`);
|
|
202
|
+
}
|
|
203
|
+
if (directory !== undefined) throw new Error("Specify only one application directory");
|
|
204
|
+
directory = arg;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (!allowed.has(arg) || flags.has(arg)) throw new Error(`Unknown or duplicate option: ${arg}`);
|
|
208
|
+
if (booleanFlags.has(arg)) {
|
|
209
|
+
flags.set(arg, true);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const value = args.shift();
|
|
213
|
+
if (!value || value.startsWith("--")) throw new Error(`${arg} requires a value`);
|
|
214
|
+
flags.set(arg, value);
|
|
215
|
+
}
|
|
216
|
+
if (directory !== undefined && flags.has("--app"))
|
|
217
|
+
throw new Error("Use DIRECTORY or --app, not both");
|
|
218
|
+
if (command === "smoke" && (directory !== undefined || flags.size))
|
|
219
|
+
throw new Error("zgui-js smoke takes no options");
|
|
220
|
+
const value = (flag: string): string | undefined => {
|
|
221
|
+
const selected = flags.get(flag);
|
|
222
|
+
return typeof selected === "string" ? selected : undefined;
|
|
223
|
+
};
|
|
224
|
+
const pathValue = (flag: string): string | undefined => {
|
|
225
|
+
const selected = value(flag);
|
|
226
|
+
return selected === undefined ? undefined : path.resolve(selected);
|
|
227
|
+
};
|
|
228
|
+
const exitAfterMs = value("--exit-after-ms");
|
|
229
|
+
if (exitAfterMs !== undefined && !/^[1-9][0-9]*$/.test(exitAfterMs)) {
|
|
230
|
+
throw new Error("--exit-after-ms requires a positive integer");
|
|
231
|
+
}
|
|
232
|
+
const maxJsStackBytes = value("--max-js-stack-bytes");
|
|
233
|
+
if (maxJsStackBytes !== undefined && !/^[1-9][0-9]*$/.test(maxJsStackBytes)) {
|
|
234
|
+
throw new Error("--max-js-stack-bytes requires a positive integer");
|
|
235
|
+
}
|
|
236
|
+
for (const dim of ["--width", "--height"] as const) {
|
|
237
|
+
const raw = value(dim);
|
|
238
|
+
if (raw !== undefined) {
|
|
239
|
+
const parsed = Number(raw);
|
|
240
|
+
if (!Number.isFinite(parsed) || parsed <= 0 || parsed > 16384) {
|
|
241
|
+
throw new Error(`${dim} requires a positive finite number <= 16384`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const selector = directory ?? value("--app");
|
|
246
|
+
const capabilitiesFile = pathValue("--capabilities-file");
|
|
247
|
+
const host = {
|
|
248
|
+
hostRoot: pathValue("--host-root"),
|
|
249
|
+
hostExecutable: pathValue("--host-executable"),
|
|
250
|
+
};
|
|
251
|
+
switch (command) {
|
|
252
|
+
case "smoke":
|
|
253
|
+
return { command };
|
|
254
|
+
case "doctor":
|
|
255
|
+
return { command, ...host, json: flags.has("--json") };
|
|
256
|
+
case "build":
|
|
257
|
+
return {
|
|
258
|
+
command,
|
|
259
|
+
selector,
|
|
260
|
+
capabilitiesFile,
|
|
261
|
+
...host,
|
|
262
|
+
watch: flags.has("--watch"),
|
|
263
|
+
bytecode: flags.has("--bytecode"),
|
|
264
|
+
};
|
|
265
|
+
case "dev":
|
|
266
|
+
return {
|
|
267
|
+
command,
|
|
268
|
+
selector,
|
|
269
|
+
capabilitiesFile,
|
|
270
|
+
...host,
|
|
271
|
+
exitAfterMs,
|
|
272
|
+
width: value("--width"),
|
|
273
|
+
height: value("--height"),
|
|
274
|
+
title: value("--title"),
|
|
275
|
+
maxJsStackBytes,
|
|
276
|
+
layerConfig: pathValue("--layer-config"),
|
|
277
|
+
devInspect: pathValue("--dev-inspect"),
|
|
278
|
+
pureShell: flags.has("--pure-shell"),
|
|
279
|
+
strictTypecheck: flags.has("--strict-typecheck"),
|
|
280
|
+
};
|
|
281
|
+
case "preview":
|
|
282
|
+
return {
|
|
283
|
+
command,
|
|
284
|
+
selector,
|
|
285
|
+
capabilitiesFile,
|
|
286
|
+
...host,
|
|
287
|
+
watch: flags.has("--watch"),
|
|
288
|
+
profile: pathValue("--profile"),
|
|
289
|
+
fixture: pathValue("--fixture"),
|
|
290
|
+
scenario: pathValue("--scenario"),
|
|
291
|
+
out: pathValue("--out"),
|
|
292
|
+
};
|
|
293
|
+
case "package":
|
|
294
|
+
return {
|
|
295
|
+
command,
|
|
296
|
+
selector,
|
|
297
|
+
capabilitiesFile,
|
|
298
|
+
...host,
|
|
299
|
+
out: pathValue("--out"),
|
|
300
|
+
bytecode: flags.has("--bytecode"),
|
|
301
|
+
desktopEntry: flags.has("--desktop-entry"),
|
|
302
|
+
pureShell: flags.has("--pure-shell"),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function watchBuild(application: ResolvedApplication & { capabilitiesFile?: string }) {
|
|
308
|
+
const watcher = watchApplication(application.app, application);
|
|
309
|
+
let closing: Promise<void> | undefined;
|
|
310
|
+
const stop = () => {
|
|
311
|
+
closing ??= watcher.close().finally(() => {
|
|
312
|
+
process.removeListener("SIGINT", stop);
|
|
313
|
+
process.removeListener("SIGTERM", stop);
|
|
314
|
+
});
|
|
315
|
+
closing.catch((error: unknown) => {
|
|
316
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
317
|
+
process.exitCode = 1;
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
process.on("SIGINT", stop);
|
|
321
|
+
process.on("SIGTERM", stop);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async function withInterrupt(run: (signal: AbortSignal) => Promise<number>): Promise<number> {
|
|
325
|
+
const controller = new AbortController();
|
|
326
|
+
let interrupted: number | undefined;
|
|
327
|
+
const interrupt = (signal: "SIGINT" | "SIGTERM") => {
|
|
328
|
+
if (interrupted !== undefined) return;
|
|
329
|
+
interrupted = signal === "SIGINT" ? 130 : 143;
|
|
330
|
+
controller.abort(signal);
|
|
331
|
+
};
|
|
332
|
+
const onInt = () => interrupt("SIGINT");
|
|
333
|
+
const onTerm = () => interrupt("SIGTERM");
|
|
334
|
+
process.on("SIGINT", onInt);
|
|
335
|
+
process.on("SIGTERM", onTerm);
|
|
336
|
+
try {
|
|
337
|
+
return await run(controller.signal);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
if (!controller.signal.aborted) throw error;
|
|
340
|
+
return interrupted ?? 1;
|
|
341
|
+
} finally {
|
|
342
|
+
process.removeListener("SIGINT", onInt);
|
|
343
|
+
process.removeListener("SIGTERM", onTerm);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function cliVersion(): string {
|
|
348
|
+
const pkg = JSON.parse(
|
|
349
|
+
readFileSync(path.resolve(import.meta.dir, "../package.json"), "utf8"),
|
|
350
|
+
) as { version?: string };
|
|
351
|
+
return pkg.version ?? "0.1.0";
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export async function runCli(rawArgs: readonly string[]): Promise<number> {
|
|
355
|
+
const args = [...rawArgs];
|
|
356
|
+
if (!args.length || args[0] === "--help" || args[0] === "-h") {
|
|
357
|
+
console.log(usage);
|
|
358
|
+
return 0;
|
|
359
|
+
}
|
|
360
|
+
if (args[0] === "--version" || args[0] === "-V") {
|
|
361
|
+
console.log(`zgui-js ${cliVersion()}`);
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
364
|
+
const selected = parse(args);
|
|
365
|
+
if (selected.command === "init") {
|
|
366
|
+
return runInitCli(selected.args);
|
|
367
|
+
}
|
|
368
|
+
if (selected.command === "doctor") {
|
|
369
|
+
const report = await runDoctor({
|
|
370
|
+
hostRoot: selected.hostRoot,
|
|
371
|
+
hostExecutable: selected.hostExecutable,
|
|
372
|
+
});
|
|
373
|
+
if (selected.json) {
|
|
374
|
+
console.log(JSON.stringify(report, null, 2));
|
|
375
|
+
} else {
|
|
376
|
+
console.log(formatDoctorReport(report));
|
|
377
|
+
}
|
|
378
|
+
return report.ok ? 0 : 1;
|
|
379
|
+
}
|
|
380
|
+
if (selected.command === "inspect") {
|
|
381
|
+
return withInterrupt(signal =>
|
|
382
|
+
runInspect({
|
|
383
|
+
args: selected.args,
|
|
384
|
+
ui: selected.ui,
|
|
385
|
+
hostRoot: selected.hostRoot,
|
|
386
|
+
hostExecutable: selected.hostExecutable,
|
|
387
|
+
signal,
|
|
388
|
+
}),
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
if (selected.command === "smoke") {
|
|
392
|
+
typecheckProject(resolveSmokeTsconfigPath());
|
|
393
|
+
await buildSmoke();
|
|
394
|
+
return 0;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const hostSearchFrom = [import.meta.url];
|
|
398
|
+
const application = {
|
|
399
|
+
...(await resolveApplication(selected.selector)),
|
|
400
|
+
capabilitiesFile: selected.capabilitiesFile,
|
|
401
|
+
};
|
|
402
|
+
if (selected.command === "dev") {
|
|
403
|
+
const hostArgs: string[] = [];
|
|
404
|
+
if (selected.exitAfterMs !== undefined) hostArgs.push("--exit-after-ms", selected.exitAfterMs);
|
|
405
|
+
if (selected.width !== undefined) hostArgs.push("--width", selected.width);
|
|
406
|
+
if (selected.height !== undefined) hostArgs.push("--height", selected.height);
|
|
407
|
+
if (selected.title !== undefined) hostArgs.push("--title", selected.title);
|
|
408
|
+
if (selected.maxJsStackBytes !== undefined)
|
|
409
|
+
hostArgs.push("--max-js-stack-bytes", selected.maxJsStackBytes);
|
|
410
|
+
if (selected.layerConfig !== undefined) hostArgs.push("--layer-config", selected.layerConfig);
|
|
411
|
+
if (selected.devInspect !== undefined) hostArgs.push("--dev-inspect", selected.devInspect);
|
|
412
|
+
if (selected.pureShell) hostArgs.push("--pure-shell");
|
|
413
|
+
return withInterrupt(signal =>
|
|
414
|
+
devApplication(application.app, {
|
|
415
|
+
...application,
|
|
416
|
+
strictTypecheck: selected.strictTypecheck,
|
|
417
|
+
hostRoot: selected.hostRoot,
|
|
418
|
+
hostExecutable: selected.hostExecutable,
|
|
419
|
+
hostSearchFrom,
|
|
420
|
+
hostArgs,
|
|
421
|
+
signal,
|
|
422
|
+
}),
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
if (selected.command === "preview") {
|
|
426
|
+
return withInterrupt(signal =>
|
|
427
|
+
previewApplication(application.app, {
|
|
428
|
+
...application,
|
|
429
|
+
...selected,
|
|
430
|
+
hostSearchFrom,
|
|
431
|
+
signal,
|
|
432
|
+
onOutput: output => console.error(`[preview] Artifacts: ${output}`),
|
|
433
|
+
}),
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
if (selected.command === "package") {
|
|
437
|
+
const packaged = await withInterrupt(async signal => {
|
|
438
|
+
const result = await packageApplication(application.app, {
|
|
439
|
+
...application,
|
|
440
|
+
out: selected.out,
|
|
441
|
+
bytecode: selected.bytecode,
|
|
442
|
+
hostRoot: selected.hostRoot,
|
|
443
|
+
hostExecutable: selected.hostExecutable,
|
|
444
|
+
hostSearchFrom,
|
|
445
|
+
desktopEntry: selected.desktopEntry,
|
|
446
|
+
pureShell: selected.pureShell,
|
|
447
|
+
signal,
|
|
448
|
+
});
|
|
449
|
+
console.log(
|
|
450
|
+
`Packaged ${result.out} (${result.manifest.buildId}, host=${result.host.source})`,
|
|
451
|
+
);
|
|
452
|
+
return 0;
|
|
453
|
+
});
|
|
454
|
+
return packaged;
|
|
455
|
+
}
|
|
456
|
+
if (selected.watch) {
|
|
457
|
+
if (selected.bytecode) {
|
|
458
|
+
throw new Error("zgui-js build --watch cannot be combined with --bytecode");
|
|
459
|
+
}
|
|
460
|
+
await watchBuild(application);
|
|
461
|
+
return 0;
|
|
462
|
+
}
|
|
463
|
+
const { dist, manifest } = await buildApplication(application.app, {
|
|
464
|
+
...application,
|
|
465
|
+
bytecode: selected.bytecode,
|
|
466
|
+
hostRoot: selected.hostRoot,
|
|
467
|
+
hostExecutable: selected.hostExecutable,
|
|
468
|
+
hostSearchFrom,
|
|
469
|
+
});
|
|
470
|
+
console.log(`Published ${dist} ${manifest.buildId}`);
|
|
471
|
+
return 0;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (import.meta.main) {
|
|
475
|
+
try {
|
|
476
|
+
const code = await runCli(process.argv.slice(2));
|
|
477
|
+
if (code !== 0) process.exitCode = code;
|
|
478
|
+
} catch (error) {
|
|
479
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
480
|
+
process.exitCode =
|
|
481
|
+
typeof error === "object" &&
|
|
482
|
+
error !== null &&
|
|
483
|
+
"exitCode" in error &&
|
|
484
|
+
typeof error.exitCode === "number"
|
|
485
|
+
? error.exitCode
|
|
486
|
+
: 1;
|
|
487
|
+
}
|
|
488
|
+
}
|