@cybermp-community/resource-builder 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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +303 -2
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +584 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +1040 -0
  7. package/dist/index.js +1 -0
  8. package/dist/run-CmhtmY2x.js +7018 -0
  9. package/dist/run-CmhtmY2x.js.map +1 -0
  10. package/package.json +64 -3
  11. package/schema/config.json +122 -0
  12. package/templates/project-default/Dockerfile +17 -0
  13. package/templates/project-default/README.md +57 -0
  14. package/templates/project-default/_dockerignore +26 -0
  15. package/templates/project-default/_gitignore +32 -0
  16. package/templates/project-default/addons/gamemode/browser/env.d.ts +1 -0
  17. package/templates/project-default/addons/gamemode/browser/index.html +12 -0
  18. package/templates/project-default/addons/gamemode/browser/package.json +21 -0
  19. package/templates/project-default/addons/gamemode/browser/src/App.vue +40 -0
  20. package/templates/project-default/addons/gamemode/browser/src/global.d.ts +7 -0
  21. package/templates/project-default/addons/gamemode/browser/src/main.ts +4 -0
  22. package/templates/project-default/addons/gamemode/browser/tsconfig.json +7 -0
  23. package/templates/project-default/addons/gamemode/browser/vite.config.ts +15 -0
  24. package/templates/project-default/addons/gamemode/client/src/global.d.ts +5 -0
  25. package/templates/project-default/addons/gamemode/client/src/index.ts +11 -0
  26. package/templates/project-default/addons/gamemode/client/tsconfig.json +4 -0
  27. package/templates/project-default/addons/gamemode/package.json +22 -0
  28. package/templates/project-default/addons/gamemode/resource.toml +12 -0
  29. package/templates/project-default/addons/gamemode/server/src/global.d.ts +5 -0
  30. package/templates/project-default/addons/gamemode/server/src/index.ts +13 -0
  31. package/templates/project-default/addons/gamemode/server/tsconfig.json +7 -0
  32. package/templates/project-default/addons/gamemode/shared/src/index.ts +2 -0
  33. package/templates/project-default/biome.json +43 -0
  34. package/templates/project-default/cybermp.config.json +6 -0
  35. package/templates/project-default/docker-compose.yml +19 -0
  36. package/templates/project-default/package.json +25 -0
  37. package/templates/project-default/pnpm-workspace.yaml +6 -0
  38. package/templates/project-default/server.toml +21 -0
  39. package/templates/project-default/tsconfig.json +7 -0
  40. package/templates/types.json +15 -0
  41. package/tsconfig.base.json +17 -0
package/dist/cli.js ADDED
@@ -0,0 +1,584 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { RESOURCE_NAME_PATTERN } from "@cybermp-community/addon";
5
+ import { C as checkProject, F as loadConfig, Q as BuilderError, S as updateAddon, a as downloadServer, b as listAddons, c as serverDir, d as initNextSteps, h as TYPES_MODES, l as ADDON_REALMS, o as hostPlatform, p as initProject, s as readInstalledVersion, t as runServer, u as createAddon, v as addAddon, w as buildProject, x as removeAddon, y as installProject, z as PACKAGE_MANAGERS } from "./run-CmhtmY2x.js";
6
+ // src/cli.ts
7
+ /**
8
+ * `cybermp` — the project CLI.
9
+ *
10
+ * Thin wrappers around the library:
11
+ *
12
+ * - `init [dir]` renders the project template into an empty directory and
13
+ * prints the commands that take it to a running server;
14
+ * - `build [dir]` runs {@link buildProject} (default: the current directory)
15
+ * and prints the resources it wrote;
16
+ * - `check [dir]` runs {@link checkProject}, prints one line per issue and a
17
+ * summary, and fails when any issue is an error.
18
+ *
19
+ * Output contract, because CI reads it:
20
+ *
21
+ * - `build` prints its one-line summary on stdout, nothing else;
22
+ * - `check` prints every issue on stderr as `<level> <code> <path>: <message>`
23
+ * and its one-line summary on stdout, so stderr stays pure diagnostics;
24
+ * - exit `0` success (check: no errors), `1` validation or build failure,
25
+ * `2` usage error.
26
+ */
27
+ /** No errors; warnings are reported but never fail a check. */
28
+ const EXIT_OK = 0;
29
+ /** Validation or build failure. */
30
+ const EXIT_INVALID = 1;
31
+ /** Bad invocation: unknown command, unknown option, surplus argument. */
32
+ const EXIT_USAGE = 2;
33
+ const USAGE = `cybermp: scaffold, build and check a CyberMP project
34
+
35
+ Usage:
36
+ cybermp init [dir] [--template=<name>] [--types=<community|official>] [--pm=<pm>] [--no-install] [--no-lint] [--force]
37
+ cybermp create addon <name> [dir] [--realms=<client,server,shared,browser>] [--shared] [--types=<community|official|none>] [--no-install] [--pm=<pm>]
38
+ cybermp build [dir] [--filter=<resource>] [--no-browser] [--no-redscripts]
39
+ cybermp check [dir] [--no-redscripts]
40
+ cybermp add <spec> [dir] [--first|--before=<name>|--after=<name>] [--asset=<name|glob>] [--copy] [--pm=<pm>]
41
+ cybermp remove <name-or-package> [dir] [--pm=<pm>]
42
+ cybermp list [dir]
43
+ cybermp install [dir] [--pm=<pm>]
44
+ cybermp update [name] [dir] [--to=<tag>]
45
+ cybermp download [dir] [--platform=<win|linux>] [--version=<tag>] [--latest]
46
+ cybermp run [dir] [--prod]
47
+
48
+ Commands:
49
+ init [dir] Scaffold a project from the template shipped with this package
50
+ (default: the current directory), install dependencies and
51
+ print the next steps.
52
+ create addon <name> [dir]
53
+ Scaffold a local addon at addons/<name> in an existing project:
54
+ the package marker, resource.toml, the realms named by --realms
55
+ and the type packages pinned in the package's type table.
56
+ build [dir] Resolve, build and materialize the project, then rewrite
57
+ server.toml and write .addons.json.
58
+ check [dir] Validate the project: compare server.toml with the order a
59
+ build would write (the generated scripts first when they would
60
+ be built) and run the addon validator over every addon.
61
+ add <spec> Install an addon from an npm package, a gh:/gl: release, an
62
+ http(s) archive URL or a local path, validate it and add it to
63
+ addons.order.
64
+ remove <n> Remove a lock entry or an npm dependency and its addons.order
65
+ entry. Accepts a resource name or an npm package name.
66
+ list Print the installed addons: name, version, source and order.
67
+ install Install package-manager dependencies and restore release
68
+ addons recorded in cybermp.lock.json.
69
+ update [n] Re-resolve releases (unless pinned), accept a new tag with
70
+ --to, and recompute the hash of local path addons.
71
+ download Fetch the CyberMP server binaries for server.platforms into
72
+ workDir/mp/<platform>.
73
+ run Start the downloaded server with the project as its cwd.
74
+
75
+ Options:
76
+ --template=<name> Project template to render (init; default: project-default).
77
+ --no-install Skip the package manager install (init, create).
78
+ --no-lint Leave the biome config and dependency out (init).
79
+ --types=<set> Type packages to pin (init, create): official or
80
+ community. Default: official. \`community\` refuses a
81
+ realm the typecheck gate blocked; \`none\` (create only)
82
+ installs no package and stubs \`mp\` as \`unknown\`.
83
+ --realms=<list> Addon realms to scaffold (create): a comma-separated
84
+ subset of client, server, shared, browser; default
85
+ client,server.
86
+ --shared Include the shared realm (create).
87
+ --force Scaffold into a non-empty directory (init).
88
+ --filter=<resource> Build only the named resource.
89
+ --no-browser Skip the browser (CEF) build of local addons.
90
+ --no-redscripts Skip final_redscripts: build leaves it out, check accepts
91
+ a list without it.
92
+ --first Insert the addon first in addons.order.
93
+ --before=<name> Insert the addon before an existing order entry.
94
+ --after=<name> Insert the addon after an existing order entry.
95
+ --asset=<name|glob> Pick the release archive when a release ships several.
96
+ --copy Snapshot a local path into ./addons/<resource>.
97
+ --pm=<pm> Package manager: pnpm, npm, yarn or bun.
98
+ --to=<tag> Release tag to pin (update).
99
+ --platform=<win|linux> Server platform to download for this run (download).
100
+ --version=<tag> Server release tag to download (download).
101
+ --latest Download the latest server release (download).
102
+ --prod Start the server with NODE_ENV=production (run).
103
+ -h, --help Show this help.
104
+
105
+ Exit codes:
106
+ 0 success (check: no errors)
107
+ 1 validation or build failure
108
+ 2 usage error
109
+ `;
110
+ /** Flags each command understands; anything else is a usage error. */
111
+ const COMMAND_FLAGS = {
112
+ init: /* @__PURE__ */ new Set([
113
+ "template",
114
+ "types",
115
+ "pm",
116
+ "no-install",
117
+ "no-lint",
118
+ "force"
119
+ ]),
120
+ create: /* @__PURE__ */ new Set([
121
+ "realms",
122
+ "shared",
123
+ "types",
124
+ "no-install",
125
+ "pm"
126
+ ]),
127
+ build: /* @__PURE__ */ new Set([
128
+ "filter",
129
+ "no-browser",
130
+ "no-redscripts",
131
+ "watch"
132
+ ]),
133
+ check: /* @__PURE__ */ new Set(["no-redscripts"]),
134
+ add: /* @__PURE__ */ new Set([
135
+ "first",
136
+ "before",
137
+ "after",
138
+ "asset",
139
+ "copy",
140
+ "pm"
141
+ ]),
142
+ remove: /* @__PURE__ */ new Set(["pm"]),
143
+ list: /* @__PURE__ */ new Set(),
144
+ install: /* @__PURE__ */ new Set(["pm"]),
145
+ update: /* @__PURE__ */ new Set(["to"]),
146
+ download: /* @__PURE__ */ new Set([
147
+ "platform",
148
+ "version",
149
+ "latest"
150
+ ]),
151
+ run: /* @__PURE__ */ new Set(["prod"])
152
+ };
153
+ async function main() {
154
+ const options = readOptions(process.argv.slice(2));
155
+ if (options === void 0) return;
156
+ const { flags, positionals } = options;
157
+ if (flags.help === true) {
158
+ process.stdout.write(USAGE);
159
+ return;
160
+ }
161
+ const [command, ...args] = positionals;
162
+ if (command === void 0) {
163
+ usageError("a command is required");
164
+ return;
165
+ }
166
+ const allowed = COMMAND_FLAGS[command];
167
+ if (allowed === void 0) {
168
+ usageError(`unknown command \`${command}\``);
169
+ return;
170
+ }
171
+ const misplaced = Object.keys(flags).find((flag) => !allowed.has(flag));
172
+ if (misplaced !== void 0) {
173
+ usageError(`\`${command}\` does not take \`--${misplaced}\``);
174
+ return;
175
+ }
176
+ if (flags.pm !== void 0 && !isPackageManager(flags.pm)) {
177
+ usageError(`\`--pm=${flags.pm}\` is not one of ${PACKAGE_MANAGERS.join(", ")}`);
178
+ return;
179
+ }
180
+ if (flags.types !== void 0 && !isTypesMode(flags.types)) {
181
+ usageError(`\`--types=${flags.types}\` is not one of ${TYPES_MODES.join(", ")}`);
182
+ return;
183
+ }
184
+ switch (command) {
185
+ case "init":
186
+ await runInit(args, flags);
187
+ return;
188
+ case "create":
189
+ await runCreate(args, flags);
190
+ return;
191
+ case "build":
192
+ await runBuild(args, flags);
193
+ return;
194
+ case "check":
195
+ await runCheck(args, flags);
196
+ return;
197
+ case "add":
198
+ await runAdd(args, flags);
199
+ return;
200
+ case "remove":
201
+ await runRemove(args, flags);
202
+ return;
203
+ case "list":
204
+ await runList(args);
205
+ return;
206
+ case "install":
207
+ await runInstall(args, flags);
208
+ return;
209
+ case "update":
210
+ await runUpdate(args, flags);
211
+ return;
212
+ case "download":
213
+ await runDownload(args, flags);
214
+ return;
215
+ case "run":
216
+ await runServe(args, flags);
217
+ return;
218
+ }
219
+ }
220
+ /**
221
+ * `init` — scaffold a project and print the next steps.
222
+ *
223
+ * Every flag is optional: with no positional the current directory is
224
+ * scaffolded, which is why `init .` must also work (`--force` aside, only an
225
+ * empty directory is accepted).
226
+ */
227
+ async function runInit(args, flags) {
228
+ const [dir, ...surplus] = args;
229
+ if (surplus.length > 0) {
230
+ usageError("`init` takes at most one directory");
231
+ return;
232
+ }
233
+ if (flags.types === "none") {
234
+ usageError("`init` does not take `--types=none`; scaffold the project with a type set and use `create addon --types=none` for an untyped addon inside it");
235
+ return;
236
+ }
237
+ const report = await initProject({
238
+ dir: dir ?? ".",
239
+ template: flags.template,
240
+ pm: flags.pm,
241
+ install: flags["no-install"] !== true,
242
+ lint: flags["no-lint"] !== true,
243
+ types: typesMode(flags),
244
+ force: flags.force === true
245
+ });
246
+ process.stdout.write(initNextSteps(report));
247
+ }
248
+ /**
249
+ * Codes `create addon` reports as usage errors: the name cannot be scaffolded,
250
+ * so the invocation is wrong rather than the project.
251
+ *
252
+ * `createAddon` owns the checks (the reserved list and the addons already in the
253
+ * project), so the CLI maps its verdict instead of duplicating it.
254
+ */
255
+ const CREATE_USAGE_CODES = /* @__PURE__ */ new Set(["create.reserved-name", "create.duplicate-name"]);
256
+ /**
257
+ * `create addon` — scaffold a local addon inside the project.
258
+ *
259
+ * The name is screened here as well as in {@link createAddon}, so a typo is a
260
+ * usage error (exit 2) with the usage block rather than a project failure. The
261
+ * realm list is only syntax-validated: `createAddon` owns the scaffold.
262
+ */
263
+ async function runCreate(args, flags) {
264
+ const [kind, name, dir, ...surplus] = args;
265
+ if (kind === void 0) {
266
+ usageError("`create` needs a kind, e.g. `create addon hud`");
267
+ return;
268
+ }
269
+ if (kind !== "addon") {
270
+ usageError(`\`create\` cannot create \`${kind}\`; only \`addon\` is supported`);
271
+ return;
272
+ }
273
+ if (name === void 0) {
274
+ usageError("`create addon` needs a name");
275
+ return;
276
+ }
277
+ if (surplus.length > 0) {
278
+ usageError("`create addon` takes a name and at most one directory");
279
+ return;
280
+ }
281
+ if (!RESOURCE_NAME_PATTERN.test(name)) {
282
+ usageError(`\`${name}\` is not an addon name: use lowercase letters, digits, \`_\` and \`-\`, starting with a letter or digit`);
283
+ return;
284
+ }
285
+ const realms = flags.realms === void 0 ? void 0 : parseRealms(flags.realms);
286
+ if (flags.realms !== void 0 && realms === void 0) return;
287
+ let addonDir;
288
+ try {
289
+ addonDir = await createAddon({
290
+ name,
291
+ dir: resolve(dir ?? process.cwd()),
292
+ realms,
293
+ shared: flags.shared === true,
294
+ install: flags["no-install"] !== true,
295
+ types: typesMode(flags),
296
+ pm: packageManager(flags)
297
+ });
298
+ } catch (error) {
299
+ if (error instanceof BuilderError && CREATE_USAGE_CODES.has(error.code)) {
300
+ usageError(error.message);
301
+ return;
302
+ }
303
+ throw error;
304
+ }
305
+ process.stdout.write(`created addon ${name} in ${addonDir}\n`);
306
+ }
307
+ /** `add` — install one addon and print what was added. */
308
+ async function runAdd(args, flags) {
309
+ const [spec, dir, ...surplus] = args;
310
+ if (spec === void 0) {
311
+ usageError("`add` needs an addon spec");
312
+ return;
313
+ }
314
+ if (surplus.length > 0) {
315
+ usageError("`add` takes a spec and at most one directory");
316
+ return;
317
+ }
318
+ const addon = await addAddon(resolve(dir ?? process.cwd()), spec, {
319
+ first: flags.first === true,
320
+ before: flags.before,
321
+ after: flags.after,
322
+ asset: flags.asset,
323
+ copy: flags.copy === true,
324
+ pm: packageManager(flags)
325
+ });
326
+ process.stdout.write(`added ${addon.name}@${addon.version} (${addon.source})\n`);
327
+ }
328
+ /** `remove` — drop one addon and print its name and source. */
329
+ async function runRemove(args, flags) {
330
+ const [name, dir, ...surplus] = args;
331
+ if (name === void 0) {
332
+ usageError("`remove` needs a resource or package name");
333
+ return;
334
+ }
335
+ if (surplus.length > 0) {
336
+ usageError("`remove` takes a name and at most one directory");
337
+ return;
338
+ }
339
+ const removed = await removeAddon(resolve(dir ?? process.cwd()), name, { pm: packageManager(flags) });
340
+ process.stdout.write(`removed ${removed.name} (${removed.source})\n`);
341
+ }
342
+ /** `list` — one row per installed addon: name, version, source, order. */
343
+ async function runList(args) {
344
+ const [dir, ...surplus] = args;
345
+ if (surplus.length > 0) {
346
+ usageError("`list` takes at most one directory");
347
+ return;
348
+ }
349
+ const rows = await listAddons(resolve(dir ?? process.cwd()));
350
+ if (rows.length === 0) {
351
+ process.stdout.write("no addons installed\n");
352
+ return;
353
+ }
354
+ for (const row of rows) {
355
+ const order = row.order === void 0 ? "-" : String(row.order);
356
+ process.stdout.write(`${row.name} ${row.version} ${row.source} ${order}\n`);
357
+ }
358
+ }
359
+ /** `install` — dependencies plus missing release addons. */
360
+ async function runInstall(args, flags) {
361
+ const [dir, ...surplus] = args;
362
+ if (surplus.length > 0) {
363
+ usageError("`install` takes at most one directory");
364
+ return;
365
+ }
366
+ const report = await installProject(resolve(dir ?? process.cwd()), { pm: packageManager(flags) });
367
+ const dependencies = report.ranPackageManager ? `installed dependencies with ${report.packageManager}` : "no package.json, skipped the package manager";
368
+ const restored = report.restored.length === 0 ? "no release addons to restore" : `restored ${plural(report.restored.length, "release addon")}: ${report.restored.join(", ")}`;
369
+ process.stdout.write(`${dependencies}; ${restored}\n`);
370
+ }
371
+ /** `update` — one line per lock entry. */
372
+ async function runUpdate(args, flags) {
373
+ const [first, second, ...surplus] = args;
374
+ if (surplus.length > 0) {
375
+ usageError("`update` takes at most a name and a directory");
376
+ return;
377
+ }
378
+ const name = first;
379
+ const target = resolve(second ?? process.cwd());
380
+ const results = await updateAddon(target, name, flags.to);
381
+ if (results.length === 0) {
382
+ process.stdout.write("nothing to update\n");
383
+ return;
384
+ }
385
+ for (const result of results) if (result.changed) process.stdout.write(`updated ${result.name} ${result.from} -> ${result.to}\n`);
386
+ else if (result.pinned) process.stdout.write(`${result.name} is pinned at ${result.to}\n`);
387
+ else process.stdout.write(`${result.name} is up to date at ${result.to}\n`);
388
+ }
389
+ /**
390
+ * `download` — fetch the server binaries for the configured platforms.
391
+ *
392
+ * The tag is the explicit `--version`, `--latest`, else `server.version`, and
393
+ * the platforms are `--platform` (one run only) or `server.platforms`. Each
394
+ * installed platform is reported with the tag its marker records.
395
+ */
396
+ async function runDownload(args, flags) {
397
+ const [dir, ...surplus] = args;
398
+ if (surplus.length > 0) {
399
+ usageError("`download` takes at most one directory");
400
+ return;
401
+ }
402
+ if (flags.latest === true && flags.version !== void 0) {
403
+ usageError("`download` takes `--latest` or `--version=<tag>`, not both");
404
+ return;
405
+ }
406
+ if (flags.platform !== void 0 && !isServerPlatform(flags.platform)) {
407
+ usageError(`\`--platform=${flags.platform}\` is not one of win, linux`);
408
+ return;
409
+ }
410
+ const config = await loadConfig(resolve(dir ?? process.cwd()));
411
+ const platforms = flags.platform !== void 0 ? [flags.platform] : config.server.platforms;
412
+ const version = flags.latest === true ? "latest" : flags.version ?? config.server.version;
413
+ await downloadServer({
414
+ workDir: config.workDir,
415
+ version,
416
+ platforms
417
+ });
418
+ for (const platform of platforms) {
419
+ const tag = await readInstalledVersion(config.workDir, platform) ?? "unknown";
420
+ process.stdout.write(`downloaded cybermp-server ${tag} for ${platform} into ${serverDir(config.workDir, platform)}\n`);
421
+ }
422
+ }
423
+ /**
424
+ * `run` — start the downloaded server against the project.
425
+ *
426
+ * The platform follows the redscripts rule — `redscripts.platform`, then
427
+ * `server.platforms[0]`, then the host — so the server runs the build the
428
+ * scripts were compiled for. The child's exit code becomes ours.
429
+ */
430
+ async function runServe(args, flags) {
431
+ const [dir, ...surplus] = args;
432
+ if (surplus.length > 0) {
433
+ usageError("`run` takes at most one directory");
434
+ return;
435
+ }
436
+ const config = await loadConfig(resolve(dir ?? process.cwd()));
437
+ const platform = config.redscripts.platform ?? config.server.platforms[0] ?? hostPlatform();
438
+ await runServer({
439
+ root: config.root,
440
+ workDir: config.workDir,
441
+ resourcesDir: config.resourcesDir,
442
+ prod: flags.prod === true,
443
+ platform
444
+ });
445
+ }
446
+ function isServerPlatform(value) {
447
+ return value === "win" || value === "linux";
448
+ }
449
+ function isPackageManager(value) {
450
+ return PACKAGE_MANAGERS.includes(value);
451
+ }
452
+ function isTypesMode(value) {
453
+ return TYPES_MODES.includes(value);
454
+ }
455
+ /** `--types` as a mode; the value is already validated in `main`. */
456
+ function typesMode(flags) {
457
+ return flags.types !== void 0 && isTypesMode(flags.types) ? flags.types : void 0;
458
+ }
459
+ function packageManager(flags) {
460
+ return flags.pm !== void 0 && isPackageManager(flags.pm) ? flags.pm : void 0;
461
+ }
462
+ /**
463
+ * `--realms=a,b` as the realm list `create` scaffolds.
464
+ *
465
+ * The option is comma-separated and order-insensitive: an unknown or empty
466
+ * entry is a usage error naming the accepted values (the return value is
467
+ * `undefined`), rather than a scaffold with a silently missing realm.
468
+ * Duplicates collapse in `createAddon`.
469
+ */
470
+ function parseRealms(value) {
471
+ const named = value.split(",").map((realm) => realm.trim());
472
+ if (named.find((realm) => realm === "" || !ADDON_REALMS.includes(realm)) !== void 0) {
473
+ usageError(`\`--realms=${value}\` is not a realm list; use a comma-separated subset of ` + ADDON_REALMS.join(", "));
474
+ return;
475
+ }
476
+ return named;
477
+ }
478
+ /** `build` — run the pipeline and print the resources it produced. */
479
+ async function runBuild(args, flags) {
480
+ const [dir, ...surplus] = args;
481
+ if (surplus.length > 0) {
482
+ usageError("`build` takes at most one directory");
483
+ return;
484
+ }
485
+ if (flags.watch === true) {
486
+ usageError("`--watch` is not available yet; run `cybermp build` again after a change");
487
+ return;
488
+ }
489
+ const names = (await buildProject(resolve(dir ?? process.cwd()), {
490
+ filter: flags.filter,
491
+ noBrowser: flags["no-browser"] === true,
492
+ noRedscripts: flags["no-redscripts"] === true
493
+ })).addons.map((addon) => addon.name);
494
+ process.stdout.write(`built ${plural(names.length, "resource")}: ${names.join(", ")}\n`);
495
+ }
496
+ /** `check` — validate the project and report every issue. */
497
+ async function runCheck(args, flags) {
498
+ const [dir, ...surplus] = args;
499
+ if (surplus.length > 0) {
500
+ usageError("`check` takes at most one directory");
501
+ return;
502
+ }
503
+ const target = resolve(dir ?? process.cwd());
504
+ const result = await checkProject(target, { noRedscripts: flags["no-redscripts"] === true });
505
+ for (const issue of result.issues) process.stderr.write(`${formatIssue(issue)}\n`);
506
+ process.stdout.write(`${summary(target, result)}\n`);
507
+ process.exitCode = result.ok ? EXIT_OK : EXIT_INVALID;
508
+ }
509
+ /** The one-line wire format of an issue; `.` stands for the project root. */
510
+ function formatIssue(issue) {
511
+ return `${issue.level} ${issue.code} ${issue.path ?? "."}: ${issue.message}`;
512
+ }
513
+ /** The one-line stdout summary: where we looked, how much was found. */
514
+ function summary(target, result) {
515
+ const errors = result.issues.filter((issue) => issue.level === "error").length;
516
+ const warnings = result.issues.length - errors;
517
+ return `checked ${target}: ${plural(errors, "error")}, ${plural(warnings, "warning")}`;
518
+ }
519
+ function plural(count, noun) {
520
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
521
+ }
522
+ /**
523
+ * `parseArgs` in strict mode: an unknown option or a missing value is a usage
524
+ * error, not a crash. `undefined` means the error was already reported.
525
+ */
526
+ function readOptions(argv) {
527
+ try {
528
+ const { values, positionals } = parseArgs({
529
+ args: argv,
530
+ allowPositionals: true,
531
+ strict: true,
532
+ options: {
533
+ help: {
534
+ type: "boolean",
535
+ short: "h"
536
+ },
537
+ template: { type: "string" },
538
+ types: { type: "string" },
539
+ "no-install": { type: "boolean" },
540
+ "no-lint": { type: "boolean" },
541
+ realms: { type: "string" },
542
+ shared: { type: "boolean" },
543
+ force: { type: "boolean" },
544
+ filter: { type: "string" },
545
+ "no-browser": { type: "boolean" },
546
+ "no-redscripts": { type: "boolean" },
547
+ watch: { type: "boolean" },
548
+ first: { type: "boolean" },
549
+ before: { type: "string" },
550
+ after: { type: "string" },
551
+ asset: { type: "string" },
552
+ copy: { type: "boolean" },
553
+ pm: { type: "string" },
554
+ to: { type: "string" },
555
+ platform: { type: "string" },
556
+ version: { type: "string" },
557
+ latest: { type: "boolean" },
558
+ prod: { type: "boolean" }
559
+ }
560
+ });
561
+ return {
562
+ flags: values,
563
+ positionals
564
+ };
565
+ } catch (error) {
566
+ usageError(error instanceof Error ? error.message : String(error));
567
+ return;
568
+ }
569
+ }
570
+ /** Report a bad invocation on stderr, with the usage block, and set exit 2. */
571
+ function usageError(message) {
572
+ process.stderr.write(`cybermp: ${message}\n\n${USAGE}`);
573
+ process.exitCode = EXIT_USAGE;
574
+ }
575
+ try {
576
+ await main();
577
+ } catch (error) {
578
+ const detail = error instanceof Error ? error.message : String(error);
579
+ process.stderr.write(`cybermp: ${detail}\n`);
580
+ process.exitCode = EXIT_INVALID;
581
+ }
582
+ export {};
583
+
584
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * `cybermp` — the project CLI.\n *\n * Thin wrappers around the library:\n *\n * - `init [dir]` renders the project template into an empty directory and\n * prints the commands that take it to a running server;\n * - `build [dir]` runs {@link buildProject} (default: the current directory)\n * and prints the resources it wrote;\n * - `check [dir]` runs {@link checkProject}, prints one line per issue and a\n * summary, and fails when any issue is an error.\n *\n * Output contract, because CI reads it:\n *\n * - `build` prints its one-line summary on stdout, nothing else;\n * - `check` prints every issue on stderr as `<level> <code> <path>: <message>`\n * and its one-line summary on stdout, so stderr stays pure diagnostics;\n * - exit `0` success (check: no errors), `1` validation or build failure,\n * `2` usage error.\n */\nimport { resolve } from 'node:path';\nimport { parseArgs } from 'node:util';\nimport { RESOURCE_NAME_PATTERN, type Issue } from '@cybermp-community/addon';\nimport { PACKAGE_MANAGERS, type PackageManager } from './addons/sources/npm.js';\nimport { buildProject } from './build/index.js';\nimport { checkProject, type CheckResult } from './check.js';\nimport {\n addAddon,\n installProject,\n listAddons,\n removeAddon,\n updateAddon,\n} from './commands/addons.js';\nimport { ADDON_REALMS, type AddonRealm, createAddon } from './commands/create.js';\nimport { initNextSteps, initProject } from './commands/init.js';\nimport { BuilderError } from './errors.js';\nimport { TYPES_MODES, type TypesMode } from './scaffold/types.js';\nimport { loadConfig } from './config.js';\nimport {\n downloadServer,\n hostPlatform,\n readInstalledVersion,\n type ServerPlatform,\n serverDir,\n} from './server/download.js';\nimport { runServer } from './server/run.js';\n\n/** No errors; warnings are reported but never fail a check. */\nconst EXIT_OK = 0;\n/** Validation or build failure. */\nconst EXIT_INVALID = 1;\n/** Bad invocation: unknown command, unknown option, surplus argument. */\nconst EXIT_USAGE = 2;\n\nconst USAGE = `cybermp: scaffold, build and check a CyberMP project\n\nUsage:\n cybermp init [dir] [--template=<name>] [--types=<community|official>] [--pm=<pm>] [--no-install] [--no-lint] [--force]\n cybermp create addon <name> [dir] [--realms=<client,server,shared,browser>] [--shared] [--types=<community|official|none>] [--no-install] [--pm=<pm>]\n cybermp build [dir] [--filter=<resource>] [--no-browser] [--no-redscripts]\n cybermp check [dir] [--no-redscripts]\n cybermp add <spec> [dir] [--first|--before=<name>|--after=<name>] [--asset=<name|glob>] [--copy] [--pm=<pm>]\n cybermp remove <name-or-package> [dir] [--pm=<pm>]\n cybermp list [dir]\n cybermp install [dir] [--pm=<pm>]\n cybermp update [name] [dir] [--to=<tag>]\n cybermp download [dir] [--platform=<win|linux>] [--version=<tag>] [--latest]\n cybermp run [dir] [--prod]\n\nCommands:\n init [dir] Scaffold a project from the template shipped with this package\n (default: the current directory), install dependencies and\n print the next steps.\n create addon <name> [dir]\n Scaffold a local addon at addons/<name> in an existing project:\n the package marker, resource.toml, the realms named by --realms\n and the type packages pinned in the package's type table.\n build [dir] Resolve, build and materialize the project, then rewrite\n server.toml and write .addons.json.\n check [dir] Validate the project: compare server.toml with the order a\n build would write (the generated scripts first when they would\n be built) and run the addon validator over every addon.\n add <spec> Install an addon from an npm package, a gh:/gl: release, an\n http(s) archive URL or a local path, validate it and add it to\n addons.order.\n remove <n> Remove a lock entry or an npm dependency and its addons.order\n entry. Accepts a resource name or an npm package name.\n list Print the installed addons: name, version, source and order.\n install Install package-manager dependencies and restore release\n addons recorded in cybermp.lock.json.\n update [n] Re-resolve releases (unless pinned), accept a new tag with\n --to, and recompute the hash of local path addons.\n download Fetch the CyberMP server binaries for server.platforms into\n workDir/mp/<platform>.\n run Start the downloaded server with the project as its cwd.\n\nOptions:\n --template=<name> Project template to render (init; default: project-default).\n --no-install Skip the package manager install (init, create).\n --no-lint Leave the biome config and dependency out (init).\n --types=<set> Type packages to pin (init, create): official or\n community. Default: official. \\`community\\` refuses a\n realm the typecheck gate blocked; \\`none\\` (create only)\n installs no package and stubs \\`mp\\` as \\`unknown\\`.\n --realms=<list> Addon realms to scaffold (create): a comma-separated\n subset of client, server, shared, browser; default\n client,server.\n --shared Include the shared realm (create).\n --force Scaffold into a non-empty directory (init).\n --filter=<resource> Build only the named resource.\n --no-browser Skip the browser (CEF) build of local addons.\n --no-redscripts Skip final_redscripts: build leaves it out, check accepts\n a list without it.\n --first Insert the addon first in addons.order.\n --before=<name> Insert the addon before an existing order entry.\n --after=<name> Insert the addon after an existing order entry.\n --asset=<name|glob> Pick the release archive when a release ships several.\n --copy Snapshot a local path into ./addons/<resource>.\n --pm=<pm> Package manager: pnpm, npm, yarn or bun.\n --to=<tag> Release tag to pin (update).\n --platform=<win|linux> Server platform to download for this run (download).\n --version=<tag> Server release tag to download (download).\n --latest Download the latest server release (download).\n --prod Start the server with NODE_ENV=production (run).\n -h, --help Show this help.\n\nExit codes:\n 0 success (check: no errors)\n 1 validation or build failure\n 2 usage error\n`;\n\n/** Parsed flags; `parseArgs` guarantees the shape of each entry. */\ninterface Flags {\n help?: boolean;\n template?: string;\n 'no-install'?: boolean;\n 'no-lint'?: boolean;\n types?: string;\n realms?: string;\n shared?: boolean;\n force?: boolean;\n filter?: string;\n 'no-browser'?: boolean;\n 'no-redscripts'?: boolean;\n /** Parsed only so `runBuild` can refuse it: watch mode is not implemented. */\n watch?: boolean;\n first?: boolean;\n before?: string;\n after?: string;\n asset?: string;\n copy?: boolean;\n pm?: string;\n to?: string;\n platform?: string;\n version?: string;\n latest?: boolean;\n prod?: boolean;\n}\n\n/** Flags each command understands; anything else is a usage error. */\nconst COMMAND_FLAGS: Record<string, ReadonlySet<keyof Flags>> = {\n init: new Set(['template', 'types', 'pm', 'no-install', 'no-lint', 'force']),\n create: new Set(['realms', 'shared', 'types', 'no-install', 'pm']),\n // `watch` is listed only so `runBuild` can refuse it with its own message;\n // it is not a build option and is not advertised in the usage block.\n build: new Set(['filter', 'no-browser', 'no-redscripts', 'watch']),\n check: new Set(['no-redscripts']),\n add: new Set(['first', 'before', 'after', 'asset', 'copy', 'pm']),\n remove: new Set(['pm']),\n list: new Set(),\n install: new Set(['pm']),\n update: new Set(['to']),\n download: new Set(['platform', 'version', 'latest']),\n run: new Set(['prod']),\n};\n\nasync function main(): Promise<void> {\n const options = readOptions(process.argv.slice(2));\n if (options === undefined) return;\n\n const { flags, positionals } = options;\n if (flags.help === true) {\n process.stdout.write(USAGE);\n return;\n }\n\n const [command, ...args] = positionals;\n if (command === undefined) {\n usageError('a command is required');\n return;\n }\n\n const allowed = COMMAND_FLAGS[command];\n if (allowed === undefined) {\n usageError(`unknown command \\`${command}\\``);\n return;\n }\n\n const misplaced = (Object.keys(flags) as (keyof Flags)[]).find(\n (flag) => !allowed.has(flag),\n );\n if (misplaced !== undefined) {\n usageError(`\\`${command}\\` does not take \\`--${misplaced}\\``);\n return;\n }\n\n if (flags.pm !== undefined && !isPackageManager(flags.pm)) {\n usageError(`\\`--pm=${flags.pm}\\` is not one of ${PACKAGE_MANAGERS.join(', ')}`);\n return;\n }\n\n if (flags.types !== undefined && !isTypesMode(flags.types)) {\n usageError(`\\`--types=${flags.types}\\` is not one of ${TYPES_MODES.join(', ')}`);\n return;\n }\n\n switch (command) {\n case 'init':\n await runInit(args, flags);\n return;\n case 'create':\n await runCreate(args, flags);\n return;\n case 'build':\n await runBuild(args, flags);\n return;\n case 'check':\n await runCheck(args, flags);\n return;\n case 'add':\n await runAdd(args, flags);\n return;\n case 'remove':\n await runRemove(args, flags);\n return;\n case 'list':\n await runList(args);\n return;\n case 'install':\n await runInstall(args, flags);\n return;\n case 'update':\n await runUpdate(args, flags);\n return;\n case 'download':\n await runDownload(args, flags);\n return;\n case 'run':\n await runServe(args, flags);\n return;\n }\n}\n\n/**\n * `init` — scaffold a project and print the next steps.\n *\n * Every flag is optional: with no positional the current directory is\n * scaffolded, which is why `init .` must also work (`--force` aside, only an\n * empty directory is accepted).\n */\nasync function runInit(args: string[], flags: Flags): Promise<void> {\n const [dir, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`init` takes at most one directory');\n return;\n }\n if (flags.types === 'none') {\n usageError(\n '`init` does not take `--types=none`; scaffold the project with a type set and use ' +\n '`create addon --types=none` for an untyped addon inside it',\n );\n return;\n }\n\n const report = await initProject({\n dir: dir ?? '.',\n template: flags.template,\n pm: flags.pm,\n install: flags['no-install'] !== true,\n lint: flags['no-lint'] !== true,\n types: typesMode(flags),\n force: flags.force === true,\n });\n process.stdout.write(initNextSteps(report));\n}\n\n/**\n * Codes `create addon` reports as usage errors: the name cannot be scaffolded,\n * so the invocation is wrong rather than the project.\n *\n * `createAddon` owns the checks (the reserved list and the addons already in the\n * project), so the CLI maps its verdict instead of duplicating it.\n */\nconst CREATE_USAGE_CODES: ReadonlySet<string> = new Set([\n 'create.reserved-name',\n 'create.duplicate-name',\n]);\n\n/**\n * `create addon` — scaffold a local addon inside the project.\n *\n * The name is screened here as well as in {@link createAddon}, so a typo is a\n * usage error (exit 2) with the usage block rather than a project failure. The\n * realm list is only syntax-validated: `createAddon` owns the scaffold.\n */\nasync function runCreate(args: string[], flags: Flags): Promise<void> {\n const [kind, name, dir, ...surplus] = args;\n if (kind === undefined) {\n usageError('`create` needs a kind, e.g. `create addon hud`');\n return;\n }\n if (kind !== 'addon') {\n usageError(`\\`create\\` cannot create \\`${kind}\\`; only \\`addon\\` is supported`);\n return;\n }\n if (name === undefined) {\n usageError('`create addon` needs a name');\n return;\n }\n if (surplus.length > 0) {\n usageError('`create addon` takes a name and at most one directory');\n return;\n }\n if (!RESOURCE_NAME_PATTERN.test(name)) {\n usageError(\n `\\`${name}\\` is not an addon name: use lowercase letters, digits, \\`_\\` and \\`-\\`, ` +\n 'starting with a letter or digit',\n );\n return;\n }\n\n const realms = flags.realms === undefined ? undefined : parseRealms(flags.realms);\n if (flags.realms !== undefined && realms === undefined) return;\n\n let addonDir: string;\n try {\n addonDir = await createAddon({\n name,\n dir: resolve(dir ?? process.cwd()),\n realms,\n shared: flags.shared === true,\n install: flags['no-install'] !== true,\n types: typesMode(flags),\n pm: packageManager(flags),\n });\n } catch (error) {\n // A reserved or already-used name is a bad invocation: exit 2 with the\n // usage block, and nothing was written.\n if (error instanceof BuilderError && CREATE_USAGE_CODES.has(error.code)) {\n usageError(error.message);\n return;\n }\n throw error;\n }\n process.stdout.write(`created addon ${name} in ${addonDir}\\n`);\n}\n\n/** `add` — install one addon and print what was added. */\nasync function runAdd(args: string[], flags: Flags): Promise<void> {\n const [spec, dir, ...surplus] = args;\n if (spec === undefined) {\n usageError('`add` needs an addon spec');\n return;\n }\n if (surplus.length > 0) {\n usageError('`add` takes a spec and at most one directory');\n return;\n }\n\n const addon = await addAddon(resolve(dir ?? process.cwd()), spec, {\n first: flags.first === true,\n before: flags.before,\n after: flags.after,\n asset: flags.asset,\n copy: flags.copy === true,\n pm: packageManager(flags),\n });\n process.stdout.write(`added ${addon.name}@${addon.version} (${addon.source})\\n`);\n}\n\n/** `remove` — drop one addon and print its name and source. */\nasync function runRemove(args: string[], flags: Flags): Promise<void> {\n const [name, dir, ...surplus] = args;\n if (name === undefined) {\n usageError('`remove` needs a resource or package name');\n return;\n }\n if (surplus.length > 0) {\n usageError('`remove` takes a name and at most one directory');\n return;\n }\n\n const removed = await removeAddon(resolve(dir ?? process.cwd()), name, {\n pm: packageManager(flags),\n });\n process.stdout.write(`removed ${removed.name} (${removed.source})\\n`);\n}\n\n/** `list` — one row per installed addon: name, version, source, order. */\nasync function runList(args: string[]): Promise<void> {\n const [dir, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`list` takes at most one directory');\n return;\n }\n\n const rows = await listAddons(resolve(dir ?? process.cwd()));\n if (rows.length === 0) {\n process.stdout.write('no addons installed\\n');\n return;\n }\n for (const row of rows) {\n const order = row.order === undefined ? '-' : String(row.order);\n process.stdout.write(`${row.name} ${row.version} ${row.source} ${order}\\n`);\n }\n}\n\n/** `install` — dependencies plus missing release addons. */\nasync function runInstall(args: string[], flags: Flags): Promise<void> {\n const [dir, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`install` takes at most one directory');\n return;\n }\n\n const report = await installProject(resolve(dir ?? process.cwd()), {\n pm: packageManager(flags),\n });\n const dependencies = report.ranPackageManager\n ? `installed dependencies with ${report.packageManager}`\n : 'no package.json, skipped the package manager';\n const restored =\n report.restored.length === 0\n ? 'no release addons to restore'\n : `restored ${plural(report.restored.length, 'release addon')}: ${report.restored.join(', ')}`;\n process.stdout.write(`${dependencies}; ${restored}\\n`);\n}\n\n/** `update` — one line per lock entry. */\nasync function runUpdate(args: string[], flags: Flags): Promise<void> {\n const [first, second, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`update` takes at most a name and a directory');\n return;\n }\n\n // One positional is the addon name, two are the name and the project dir.\n const name = first;\n const target = resolve(second ?? process.cwd());\n const results = await updateAddon(target, name, flags.to);\n if (results.length === 0) {\n process.stdout.write('nothing to update\\n');\n return;\n }\n\n for (const result of results) {\n if (result.changed) {\n process.stdout.write(`updated ${result.name} ${result.from} -> ${result.to}\\n`);\n } else if (result.pinned) {\n process.stdout.write(`${result.name} is pinned at ${result.to}\\n`);\n } else {\n process.stdout.write(`${result.name} is up to date at ${result.to}\\n`);\n }\n }\n}\n\n/**\n * `download` — fetch the server binaries for the configured platforms.\n *\n * The tag is the explicit `--version`, `--latest`, else `server.version`, and\n * the platforms are `--platform` (one run only) or `server.platforms`. Each\n * installed platform is reported with the tag its marker records.\n */\nasync function runDownload(args: string[], flags: Flags): Promise<void> {\n const [dir, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`download` takes at most one directory');\n return;\n }\n if (flags.latest === true && flags.version !== undefined) {\n usageError('`download` takes `--latest` or `--version=<tag>`, not both');\n return;\n }\n if (flags.platform !== undefined && !isServerPlatform(flags.platform)) {\n usageError(`\\`--platform=${flags.platform}\\` is not one of win, linux`);\n return;\n }\n\n const config = await loadConfig(resolve(dir ?? process.cwd()));\n const platforms: ServerPlatform[] =\n flags.platform !== undefined ? [flags.platform] : config.server.platforms;\n const version = flags.latest === true ? 'latest' : (flags.version ?? config.server.version);\n\n await downloadServer({ workDir: config.workDir, version, platforms });\n\n for (const platform of platforms) {\n const tag = (await readInstalledVersion(config.workDir, platform)) ?? 'unknown';\n process.stdout.write(\n `downloaded cybermp-server ${tag} for ${platform} into ${serverDir(config.workDir, platform)}\\n`,\n );\n }\n}\n\n/**\n * `run` — start the downloaded server against the project.\n *\n * The platform follows the redscripts rule — `redscripts.platform`, then\n * `server.platforms[0]`, then the host — so the server runs the build the\n * scripts were compiled for. The child's exit code becomes ours.\n */\nasync function runServe(args: string[], flags: Flags): Promise<void> {\n const [dir, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`run` takes at most one directory');\n return;\n }\n\n const config = await loadConfig(resolve(dir ?? process.cwd()));\n const platform = config.redscripts.platform ?? config.server.platforms[0] ?? hostPlatform();\n\n await runServer({\n root: config.root,\n workDir: config.workDir,\n resourcesDir: config.resourcesDir,\n prod: flags.prod === true,\n platform,\n });\n}\n\nfunction isServerPlatform(value: string): value is ServerPlatform {\n return value === 'win' || value === 'linux';\n}\n\nfunction isPackageManager(value: string): value is PackageManager {\n return (PACKAGE_MANAGERS as readonly string[]).includes(value);\n}\n\nfunction isTypesMode(value: string): value is TypesMode {\n return (TYPES_MODES as readonly string[]).includes(value);\n}\n\n/** `--types` as a mode; the value is already validated in `main`. */\nfunction typesMode(flags: Flags): TypesMode | undefined {\n return flags.types !== undefined && isTypesMode(flags.types) ? flags.types : undefined;\n}\n\nfunction packageManager(flags: Flags): PackageManager | undefined {\n return flags.pm !== undefined && isPackageManager(flags.pm) ? flags.pm : undefined;\n}\n\n/**\n * `--realms=a,b` as the realm list `create` scaffolds.\n *\n * The option is comma-separated and order-insensitive: an unknown or empty\n * entry is a usage error naming the accepted values (the return value is\n * `undefined`), rather than a scaffold with a silently missing realm.\n * Duplicates collapse in `createAddon`.\n */\nfunction parseRealms(value: string): AddonRealm[] | undefined {\n const named = value.split(',').map((realm) => realm.trim());\n const unknown = named.find(\n (realm) => realm === '' || !(ADDON_REALMS as readonly string[]).includes(realm),\n );\n if (unknown !== undefined) {\n usageError(\n `\\`--realms=${value}\\` is not a realm list; use a comma-separated subset of ` +\n ADDON_REALMS.join(', '),\n );\n return undefined;\n }\n return named as AddonRealm[];\n}\n\n/** `build` — run the pipeline and print the resources it produced. */\nasync function runBuild(args: string[], flags: Flags): Promise<void> {\n const [dir, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`build` takes at most one directory');\n return;\n }\n\n // Watch mode is not implemented: refuse the flag instead of building once and\n // exiting, which reads as success while nothing keeps rebuilding.\n if (flags.watch === true) {\n usageError('`--watch` is not available yet; run `cybermp build` again after a change');\n return;\n }\n\n const report = await buildProject(resolve(dir ?? process.cwd()), {\n filter: flags.filter,\n noBrowser: flags['no-browser'] === true,\n noRedscripts: flags['no-redscripts'] === true,\n });\n const names = report.addons.map((addon) => addon.name);\n process.stdout.write(`built ${plural(names.length, 'resource')}: ${names.join(', ')}\\n`);\n}\n\n/** `check` — validate the project and report every issue. */\nasync function runCheck(args: string[], flags: Flags): Promise<void> {\n const [dir, ...surplus] = args;\n if (surplus.length > 0) {\n usageError('`check` takes at most one directory');\n return;\n }\n\n const target = resolve(dir ?? process.cwd());\n const result = await checkProject(target, {\n noRedscripts: flags['no-redscripts'] === true,\n });\n\n for (const issue of result.issues) {\n process.stderr.write(`${formatIssue(issue)}\\n`);\n }\n process.stdout.write(`${summary(target, result)}\\n`);\n process.exitCode = result.ok ? EXIT_OK : EXIT_INVALID;\n}\n\n/** The one-line wire format of an issue; `.` stands for the project root. */\nfunction formatIssue(issue: Issue): string {\n return `${issue.level} ${issue.code} ${issue.path ?? '.'}: ${issue.message}`;\n}\n\n/** The one-line stdout summary: where we looked, how much was found. */\nfunction summary(target: string, result: CheckResult): string {\n const errors = result.issues.filter((issue) => issue.level === 'error').length;\n const warnings = result.issues.length - errors;\n return `checked ${target}: ${plural(errors, 'error')}, ${plural(warnings, 'warning')}`;\n}\n\nfunction plural(count: number, noun: string): string {\n return `${count} ${noun}${count === 1 ? '' : 's'}`;\n}\n\n/**\n * `parseArgs` in strict mode: an unknown option or a missing value is a usage\n * error, not a crash. `undefined` means the error was already reported.\n */\nfunction readOptions(argv: string[]): { flags: Flags; positionals: string[] } | undefined {\n try {\n const { values, positionals } = parseArgs({\n args: argv,\n allowPositionals: true,\n strict: true,\n options: {\n help: { type: 'boolean', short: 'h' },\n template: { type: 'string' },\n types: { type: 'string' },\n 'no-install': { type: 'boolean' },\n 'no-lint': { type: 'boolean' },\n realms: { type: 'string' },\n shared: { type: 'boolean' },\n force: { type: 'boolean' },\n filter: { type: 'string' },\n 'no-browser': { type: 'boolean' },\n 'no-redscripts': { type: 'boolean' },\n watch: { type: 'boolean' },\n first: { type: 'boolean' },\n before: { type: 'string' },\n after: { type: 'string' },\n asset: { type: 'string' },\n copy: { type: 'boolean' },\n pm: { type: 'string' },\n to: { type: 'string' },\n platform: { type: 'string' },\n version: { type: 'string' },\n latest: { type: 'boolean' },\n prod: { type: 'boolean' },\n },\n });\n return { flags: values as Flags, positionals };\n } catch (error) {\n usageError(error instanceof Error ? error.message : String(error));\n return undefined;\n }\n}\n\n/** Report a bad invocation on stderr, with the usage block, and set exit 2. */\nfunction usageError(message: string): void {\n process.stderr.write(`cybermp: ${message}\\n\\n${USAGE}`);\n process.exitCode = EXIT_USAGE;\n}\n\ntry {\n await main();\n} catch (error) {\n // A bug or an unreadable environment, not a verdict on the project: say so\n // and fail, never exit 0 on an internal error.\n const detail = error instanceof Error ? error.message : String(error);\n process.stderr.write(`cybermp: ${detail}\\n`);\n process.exitCode = EXIT_INVALID;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,UAAU;;AAEhB,MAAM,eAAe;;AAErB,MAAM,aAAa;AAEnB,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2Gd,MAAM,gBAA0D;CAC9D,sBAAM,IAAI,IAAI;EAAC;EAAY;EAAS;EAAM;EAAc;EAAW;CAAO,CAAC;CAC3E,wBAAQ,IAAI,IAAI;EAAC;EAAU;EAAU;EAAS;EAAc;CAAI,CAAC;CAGjE,uBAAO,IAAI,IAAI;EAAC;EAAU;EAAc;EAAiB;CAAO,CAAC;CACjE,uBAAO,IAAI,IAAI,CAAC,eAAe,CAAC;CAChC,qBAAK,IAAI,IAAI;EAAC;EAAS;EAAU;EAAS;EAAS;EAAQ;CAAI,CAAC;CAChE,wBAAQ,IAAI,IAAI,CAAC,IAAI,CAAC;CACtB,sBAAM,IAAI,IAAI;CACd,yBAAS,IAAI,IAAI,CAAC,IAAI,CAAC;CACvB,wBAAQ,IAAI,IAAI,CAAC,IAAI,CAAC;CACtB,0BAAU,IAAI,IAAI;EAAC;EAAY;EAAW;CAAQ,CAAC;CACnD,qBAAK,IAAI,IAAI,CAAC,MAAM,CAAC;AACvB;AAEA,eAAe,OAAsB;CACnC,MAAM,UAAU,YAAY,QAAQ,KAAK,MAAM,CAAC,CAAC;CACjD,IAAI,YAAY,KAAA,GAAW;CAE3B,MAAM,EAAE,OAAO,gBAAgB;CAC/B,IAAI,MAAM,SAAS,MAAM;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