@vobs/cli 1.7.4 → 1.7.7

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 (64) hide show
  1. package/dist/cli.cjs +551 -5
  2. package/dist/cli.cjs.map +1 -1
  3. package/dist/cli.js +551 -5
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/dsh.cjs +677 -0
  6. package/dist/commands/dsh.cjs.map +1 -0
  7. package/dist/commands/dsh.d.cts +43 -0
  8. package/dist/commands/dsh.d.ts +43 -0
  9. package/dist/commands/dsh.js +638 -0
  10. package/dist/commands/dsh.js.map +1 -0
  11. package/dist/commands/generate.cjs.map +1 -1
  12. package/dist/commands/generate.js.map +1 -1
  13. package/dist/commands/index.cjs +543 -5
  14. package/dist/commands/index.cjs.map +1 -1
  15. package/dist/commands/index.d.cts +2 -0
  16. package/dist/commands/index.d.ts +2 -0
  17. package/dist/commands/index.js +540 -5
  18. package/dist/commands/index.js.map +1 -1
  19. package/dist/commands/init.cjs +5 -2
  20. package/dist/commands/init.cjs.map +1 -1
  21. package/dist/commands/init.js +5 -2
  22. package/dist/commands/init.js.map +1 -1
  23. package/dist/index.cjs +553 -7
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.js +551 -5
  26. package/dist/index.js.map +1 -1
  27. package/dist/repl.cjs +5 -2
  28. package/dist/repl.cjs.map +1 -1
  29. package/dist/repl.js +5 -2
  30. package/dist/repl.js.map +1 -1
  31. package/dist/start.cjs +553 -7
  32. package/dist/start.cjs.map +1 -1
  33. package/dist/start.js +551 -5
  34. package/dist/start.js.map +1 -1
  35. package/dist/templates/dsh-plugin/README.md.hbs +54 -0
  36. package/dist/templates/dsh-plugin/cordis.patch.yml.hbs +7 -0
  37. package/dist/templates/dsh-plugin/package.json.hbs +40 -0
  38. package/dist/templates/dsh-plugin/src/client/index.tsx.hbs +24 -0
  39. package/dist/templates/dsh-plugin/src/client/panel.tsx.hbs +45 -0
  40. package/dist/templates/dsh-plugin/src/client/styles.ts.hbs +65 -0
  41. package/dist/templates/dsh-plugin/src/host/index.ts.hbs +20 -0
  42. package/dist/templates/dsh-plugin/tsconfig.json.hbs +19 -0
  43. package/dist/templates/dsh-plugin/vite.config.ts.hbs +13 -0
  44. package/dist/utils/file.cjs +5 -2
  45. package/dist/utils/file.cjs.map +1 -1
  46. package/dist/utils/file.d.cts +2 -2
  47. package/dist/utils/file.d.ts +2 -2
  48. package/dist/utils/file.js +5 -2
  49. package/dist/utils/file.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/cli.ts +28 -0
  52. package/src/commands/dsh.test.ts +279 -0
  53. package/src/commands/dsh.ts +673 -0
  54. package/src/commands/index.ts +2 -1
  55. package/src/templates/dsh-plugin/README.md.hbs +54 -0
  56. package/src/templates/dsh-plugin/cordis.patch.yml.hbs +7 -0
  57. package/src/templates/dsh-plugin/package.json.hbs +40 -0
  58. package/src/templates/dsh-plugin/src/client/index.tsx.hbs +24 -0
  59. package/src/templates/dsh-plugin/src/client/panel.tsx.hbs +45 -0
  60. package/src/templates/dsh-plugin/src/client/styles.ts.hbs +65 -0
  61. package/src/templates/dsh-plugin/src/host/index.ts.hbs +20 -0
  62. package/src/templates/dsh-plugin/tsconfig.json.hbs +19 -0
  63. package/src/templates/dsh-plugin/vite.config.ts.hbs +13 -0
  64. package/src/utils/file.ts +7 -3
package/dist/start.js CHANGED
@@ -69,13 +69,13 @@ function ensureDir(dir) {
69
69
  __name(ensureDir, "ensureDir");
70
70
  async function copyDirRecursive(srcDir, destDir, context) {
71
71
  const { readdirSync } = await import("fs");
72
- const { join } = await import("path");
72
+ const { join: join2 } = await import("path");
73
73
  const entries = readdirSync(srcDir, { withFileTypes: true });
74
74
  for (const entry of entries) {
75
- const srcPath = join(srcDir, entry.name);
75
+ const srcPath = join2(srcDir, entry.name);
76
76
  const isHbs = entry.name.endsWith(".hbs");
77
77
  const destName = isHbs ? entry.name.slice(0, -4) : entry.name;
78
- const destPath = join(destDir, destName);
78
+ const destPath = join2(destDir, destName);
79
79
  if (entry.isDirectory()) {
80
80
  ensureDir(destPath);
81
81
  await copyDirRecursive(srcPath, destPath, context);
@@ -89,8 +89,11 @@ async function copyDirRecursive(srcDir, destDir, context) {
89
89
  }
90
90
  }
91
91
  __name(copyDirRecursive, "copyDirRecursive");
92
- async function scaffoldProject(targetDir, context) {
93
- const templateDir = resolve(TEMPLATES_ROOT, "basic");
92
+ async function scaffoldProject(targetDir, context, template = "basic") {
93
+ const templateDir = resolve(TEMPLATES_ROOT, template);
94
+ if (!existsSync(templateDir)) {
95
+ throw new Error(`\u6A21\u677F\u4E0D\u5B58\u5728: ${template}\uFF08\u53EF\u7528\u6A21\u677F\u89C1 ${TEMPLATES_ROOT}\uFF09`);
96
+ }
94
97
  ensureDir(targetDir);
95
98
  await copyDirRecursive(templateDir, targetDir, context);
96
99
  }
@@ -321,6 +324,535 @@ async function addCommand(options) {
321
324
  }
322
325
  __name(addCommand, "addCommand");
323
326
 
327
+ // packages/cli/src/commands/dsh.ts
328
+ import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
329
+ import { readFile } from "fs/promises";
330
+ import { execSync as execSync3, spawnSync } from "child_process";
331
+ import { createServer as createServer2 } from "http";
332
+ import { createRequire } from "module";
333
+ import { isAbsolute, basename, dirname as dirname2, join, relative, resolve as resolve5 } from "path";
334
+ import * as p4 from "@clack/prompts";
335
+ var PLATFORM_MODULES = ["react", "react-dom"];
336
+ var vobsVersion = /* @__PURE__ */ __name(() => {
337
+ try {
338
+ const manifest = JSON.parse(
339
+ readFileSync2(new URL("../../package.json", import.meta.url), "utf8")
340
+ );
341
+ return manifest.version ?? "1.7.5";
342
+ } catch {
343
+ return "1.7.5";
344
+ }
345
+ }, "vobsVersion");
346
+ function toRowId(packageName) {
347
+ return packageName.replace(/^@[^/]+\//u, "");
348
+ }
349
+ __name(toRowId, "toRowId");
350
+ async function dshInitCommand(target, options) {
351
+ const name = target ?? await p4.text({
352
+ message: "\u63D2\u4EF6\u5305\u540D\uFF08npm \u5305\u540D\uFF0C\u5C0F\u5199\uFF09:",
353
+ placeholder: "dsh-plugin-my-panel",
354
+ validate: /* @__PURE__ */ __name((value) => /^[a-z0-9][a-z0-9._~-]*$/u.test(value) ? void 0 : "\u5FC5\u987B\u662F\u5408\u6CD5\u7684 npm \u5305\u540D", "validate")
355
+ });
356
+ if (p4.isCancel(name)) {
357
+ p4.cancel("\u5DF2\u53D6\u6D88");
358
+ return;
359
+ }
360
+ const packageManager = options.pm ?? await p4.select({
361
+ message: "\u5305\u7BA1\u7406\u5668:",
362
+ options: [
363
+ { value: "pnpm", label: "pnpm" },
364
+ { value: "npm", label: "npm" }
365
+ ]
366
+ });
367
+ if (p4.isCancel(packageManager)) {
368
+ p4.cancel("\u5DF2\u53D6\u6D88");
369
+ return;
370
+ }
371
+ const targetDir = options.dir !== void 0 ? resolve5(options.dir) : resolve5(process.cwd(), name);
372
+ const rowId = toRowId(name);
373
+ const displayName = rowId.replace(/^dsh-plugin-/u, "").split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
374
+ logger.step(`\u521B\u5EFA DSH \u63D2\u4EF6\u9879\u76EE ${name} \u2026`);
375
+ await scaffoldProject(
376
+ targetDir,
377
+ { packageName: name, rowId, displayName, vobsVersion: vobsVersion() },
378
+ "dsh-plugin"
379
+ );
380
+ ensureDir(targetDir);
381
+ writeFileSync2(
382
+ resolve5(targetDir, ".gitignore"),
383
+ ["node_modules/", "*.log", "*.tsbuildinfo", "", "# lib/ \u662F\u6784\u5EFA\u4EA7\u7269\uFF0C\u5FC5\u987B\u63D0\u4EA4\uFF1ADSH \u5B89\u88C5\u65F6\u4E0D\u4F1A\u6784\u5EFA\u4F60\u7684\u5305\u3002", ""].join("\n"),
384
+ "utf8"
385
+ );
386
+ logger.success("\u9879\u76EE\u5DF2\u751F\u6210");
387
+ logger.step("\u5B89\u88C5\u4F9D\u8D56 \u2026");
388
+ try {
389
+ installDependencies(targetDir, packageManager);
390
+ logger.success("\u4F9D\u8D56\u5DF2\u5B89\u88C5");
391
+ } catch {
392
+ logger.warn(`\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u6267\u884C ${packageManager} install`);
393
+ }
394
+ logger.step("\u4E0B\u4E00\u6B65");
395
+ console.log(`
396
+ cd ${name}
397
+ ${packageManager} run dev # \u672C\u5730\u9884\u89C8\uFF0C\u4E0D\u7528\u88C5\u8FDB DSH
398
+ ${packageManager} run build # \u4EA7\u51FA lib/{index,client}.js
399
+
400
+ # \u63D0\u4EA4\u4EA7\u7269\u5E76\u6253 tag \u4E4B\u540E\uFF0C\u5728 DSH \u63D2\u4EF6\u9875\u586B\uFF1A
401
+ github:<owner>/<repo>#v0.1.0&path:/<\u672C\u5305\u5728\u4ED3\u5E93\u4E2D\u7684\u8DEF\u5F84>
402
+ `);
403
+ }
404
+ __name(dshInitCommand, "dshInitCommand");
405
+ async function dshBuildCommand() {
406
+ const projectDir = process.cwd();
407
+ const configFile = resolve5(projectDir, "vite.config.ts");
408
+ if (!existsSync3(configFile)) {
409
+ logger.error("\u5F53\u524D\u76EE\u5F55\u6CA1\u6709 vite.config.ts\uFF0C\u8BF7\u5728\u63D2\u4EF6\u9879\u76EE\u6839\u76EE\u5F55\u8FD0\u884C\u3002");
410
+ process.exitCode = 1;
411
+ return;
412
+ }
413
+ const manifest = readManifest(projectDir);
414
+ if (manifest === void 0) {
415
+ logger.error("\u8BFB\u4E0D\u5230 package.json\u3002");
416
+ process.exitCode = 1;
417
+ return;
418
+ }
419
+ const hostEntry = resolveExport(manifest, ".");
420
+ if (hostEntry === void 0) {
421
+ logger.error('package.json \u7684 exports \u91CC\u6CA1\u6709 "."\uFF0CDSH \u52A0\u8F7D\u4E0D\u5230 Host \u4FA7\u63D2\u4EF6\u3002');
422
+ process.exitCode = 1;
423
+ return;
424
+ }
425
+ const { build: build2 } = await import("vite");
426
+ logger.info("\u6784\u5EFA\u5BA2\u6237\u7AEF\u4EA7\u7269 \u2026");
427
+ await build2({ configFile, mode: "production" });
428
+ logger.info("\u6784\u5EFA Host \u4EA7\u7269 \u2026");
429
+ const hostTarget = resolve5(projectDir, hostEntry.replace(/^\.\//u, ""));
430
+ const hostEntrySource = resolve5(projectDir, "src", "host", "index.ts");
431
+ if (!existsSync3(hostEntrySource)) {
432
+ logger.warn(`\u6CA1\u6709\u627E\u5230 ${hostEntrySource}\uFF0C\u8DF3\u8FC7 Host \u6784\u5EFA\u3002`);
433
+ return;
434
+ }
435
+ await build2({
436
+ configFile: false,
437
+ root: projectDir,
438
+ logLevel: "warn",
439
+ build: {
440
+ outDir: relative(projectDir, dirname2(hostTarget)) || ".",
441
+ emptyOutDir: false,
442
+ target: "es2022",
443
+ minify: false,
444
+ sourcemap: false,
445
+ lib: {
446
+ entry: hostEntrySource,
447
+ formats: ["es"],
448
+ fileName: /* @__PURE__ */ __name(() => basename(hostTarget), "fileName")
449
+ }
450
+ }
451
+ });
452
+ logger.success("\u6784\u5EFA\u5B8C\u6210 \u2192 \u5BA2\u6237\u7AEF\u4E0E Host \u4EA7\u7269\u90FD\u5DF2\u5C31\u4F4D");
453
+ }
454
+ __name(dshBuildCommand, "dshBuildCommand");
455
+ function resolveExport(manifest, key) {
456
+ const exportsField = manifest.exports ?? {};
457
+ const entry = exportsField[key];
458
+ if (typeof entry === "string") return entry;
459
+ if (typeof entry === "object" && entry !== null) {
460
+ const record = entry;
461
+ for (const condition of ["default", "import", "require"]) {
462
+ const value = record[condition];
463
+ if (typeof value === "string") return value;
464
+ }
465
+ }
466
+ return void 0;
467
+ }
468
+ __name(resolveExport, "resolveExport");
469
+ function buildPreviewHtml(options) {
470
+ const name = JSON.stringify(options.packageName).replace(/</gu, "\\u003c");
471
+ const title = (options.title ?? options.packageName).replace(/[<>&]/gu, "");
472
+ return `<!doctype html>
473
+ <html lang="zh-CN">
474
+ <head>
475
+ <meta charset="utf-8">
476
+ <meta name="viewport" content="width=device-width, initial-scale=1">
477
+ <title>vobs preview \xB7 ${title}</title>
478
+ </head>
479
+ <body>
480
+ <div id="root"></div>
481
+
482
+ <!-- 1. \u5148\u88C5\u57AB\u7247\uFF1A\u5FC5\u987B\u5728\u63D2\u4EF6 bundle \u4E4B\u524D\uFF0C\u6355\u83B7\u5B83\u7684 factory \u6CE8\u518C -->
483
+ <script>
484
+ window.__VOBS_DSH_PREVIEW__ = { factories: new Map() };
485
+ window.__ModuleLoader__ = {
486
+ load: function (entry) { window.__VOBS_DSH_PREVIEW__.factories.set(entry.id, entry.factory); }
487
+ };
488
+ </script>
489
+
490
+ <!-- 2. \u63D2\u4EF6\u4EA7\u7269\uFF1A\u5B83\u53EA\u6CE8\u518C factory\uFF0C\u4E0D\u4EA7\u751F\u526F\u4F5C\u7528 -->
491
+ <script src="/client.js"></script>
492
+
493
+ <!-- 3. \u542F\u52A8\u9884\u89C8\u5916\u58F3 -->
494
+ <script type="module">
495
+ import { startPreview } from '/preview.js';
496
+ window.__VOBS_PREVIEW__ = startPreview({
497
+ container: document.getElementById('root'),
498
+ packageName: ${name}
499
+ });
500
+ </script>
501
+
502
+ <!-- 4. \u91CD\u5EFA\u540E\u81EA\u52A8\u5237\u65B0\uFF1B?static=1 \u5173\u6389\u957F\u8FDE\u63A5\uFF0C\u4FBF\u4E8E\u65E0\u5934\u622A\u56FE\u4E0E CI \u65AD\u8A00 -->
503
+ <script>
504
+ if (!location.search.includes('static')) {
505
+ new EventSource('/events').addEventListener('reload', function () { location.reload(); });
506
+ }
507
+ </script>
508
+ </body>
509
+ </html>
510
+ `;
511
+ }
512
+ __name(buildPreviewHtml, "buildPreviewHtml");
513
+ async function dshDevCommand(options) {
514
+ const projectDir = process.cwd();
515
+ const manifest = readManifest(projectDir);
516
+ if (manifest === void 0) {
517
+ logger.error("\u5F53\u524D\u76EE\u5F55\u6CA1\u6709\u53EF\u8BFB\u7684 package.json\u3002");
518
+ process.exitCode = 1;
519
+ return;
520
+ }
521
+ if (readManifest(projectDir)?.dsh === void 0) {
522
+ logger.error("\u8FD9\u4E0D\u662F\u4E00\u4E2A DSH \u63D2\u4EF6\u9879\u76EE\uFF08package.json \u91CC\u6CA1\u6709 dsh \u5B57\u6BB5\uFF09\u3002");
523
+ process.exitCode = 1;
524
+ return;
525
+ }
526
+ const packageName = typeof manifest.name === "string" ? manifest.name : "dsh-plugin";
527
+ const clientEntry = resolveExport(manifest, "./client");
528
+ if (clientEntry === void 0) {
529
+ logger.error('package.json \u7684 exports \u91CC\u6CA1\u6709 "./client"\uFF0C\u9875\u9762\u62FF\u4E0D\u5230\u5BA2\u6237\u7AEF bundle\u3002');
530
+ process.exitCode = 1;
531
+ return;
532
+ }
533
+ const clientFile = resolve5(projectDir, clientEntry.replace(/^\.\//u, ""));
534
+ let previewFile;
535
+ try {
536
+ const projectRequire = createRequire(join(projectDir, "package.json"));
537
+ let packageRoot;
538
+ try {
539
+ packageRoot = dirname2(projectRequire.resolve("@vobs/dsh/package.json"));
540
+ } catch {
541
+ packageRoot = dirname2(dirname2(projectRequire.resolve("@vobs/dsh")));
542
+ }
543
+ const candidate = join(packageRoot, "dist", "preview.js");
544
+ previewFile = existsSync3(candidate) ? candidate : void 0;
545
+ } catch {
546
+ previewFile = void 0;
547
+ }
548
+ if (previewFile === void 0) {
549
+ logger.error("\u9879\u76EE\u91CC\u627E\u4E0D\u5230 @vobs/dsh \u7684\u9884\u89C8\u8FD0\u884C\u65F6\u3002\u5148\u5B89\u88C5\u4F9D\u8D56\uFF1Apnpm add -D @vobs/dsh");
550
+ process.exitCode = 1;
551
+ return;
552
+ }
553
+ const port = options.port ?? 5199;
554
+ const clients = /* @__PURE__ */ new Set();
555
+ const broadcast = /* @__PURE__ */ __name((event) => {
556
+ for (const client of clients) client.write(`event: ${event}
557
+ data: 1
558
+
559
+ `);
560
+ }, "broadcast");
561
+ logger.info("\u6784\u5EFA\u4EA7\u7269 \u2026");
562
+ const { build: build2 } = await import("vite");
563
+ const configFile = resolve5(projectDir, "vite.config.ts");
564
+ let buildError;
565
+ try {
566
+ const watcher = await build2({
567
+ configFile,
568
+ mode: "development",
569
+ logLevel: "warn",
570
+ build: { watch: {} }
571
+ });
572
+ watcher.on("event", (event) => {
573
+ if (event.code === "END") {
574
+ buildError = void 0;
575
+ logger.success("\u91CD\u65B0\u6784\u5EFA\u5B8C\u6210");
576
+ broadcast("reload");
577
+ } else if (event.code === "ERROR") {
578
+ buildError = event.error?.message ?? "\u6784\u5EFA\u5931\u8D25";
579
+ logger.error(buildError);
580
+ }
581
+ });
582
+ process.on("SIGINT", () => {
583
+ void watcher.close().then(() => process.exit(0));
584
+ });
585
+ } catch (error2) {
586
+ logger.error(`\u6784\u5EFA\u5931\u8D25\uFF1A${error2 instanceof Error ? error2.message : String(error2)}`);
587
+ process.exitCode = 1;
588
+ return;
589
+ }
590
+ const server = createServer2((request, response) => {
591
+ const url = (request.url ?? "/").split("?")[0];
592
+ if (url === "/events") {
593
+ response.writeHead(200, {
594
+ "content-type": "text/event-stream",
595
+ "cache-control": "no-store",
596
+ connection: "keep-alive"
597
+ });
598
+ response.write(": connected\n\n");
599
+ clients.add(response);
600
+ request.on("close", () => clients.delete(response));
601
+ return;
602
+ }
603
+ const send = /* @__PURE__ */ __name((body, type) => {
604
+ response.writeHead(200, { "content-type": type, "cache-control": "no-store" });
605
+ response.end(body);
606
+ }, "send");
607
+ if (url === "/") {
608
+ send(buildPreviewHtml({ packageName }), "text/html; charset=utf-8");
609
+ return;
610
+ }
611
+ if (url === "/preview.js") {
612
+ void readFile(previewFile).then((body) => send(body, "text/javascript; charset=utf-8"));
613
+ return;
614
+ }
615
+ if (url === "/client.js") {
616
+ if (!existsSync3(clientFile)) {
617
+ response.writeHead(503, { "content-type": "text/plain; charset=utf-8" });
618
+ response.end(`\u8FD8\u6CA1\u6709\u4EA7\u7269\uFF1A${clientEntry}
619
+ ${buildError ?? ""}`);
620
+ return;
621
+ }
622
+ void readFile(clientFile).then((body) => send(body, "text/javascript; charset=utf-8"));
623
+ return;
624
+ }
625
+ response.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
626
+ response.end("not found");
627
+ });
628
+ await new Promise((resolveListen) => {
629
+ server.listen(port, "127.0.0.1", resolveListen);
630
+ });
631
+ logger.success(`\u9884\u89C8\u5DF2\u5C31\u7EEA\uFF1Ahttp://127.0.0.1:${port}/`);
632
+ console.log("\n \u6539\u4EE3\u7801\u4F1A\u81EA\u52A8\u91CD\u5EFA\u5E76\u5237\u65B0\u9875\u9762\uFF1BCtrl+C \u9000\u51FA\u3002\n");
633
+ }
634
+ __name(dshDevCommand, "dshDevCommand");
635
+ function readManifest(dir) {
636
+ try {
637
+ return JSON.parse(readFileSync2(resolve5(dir, "package.json"), "utf8"));
638
+ } catch {
639
+ return void 0;
640
+ }
641
+ }
642
+ __name(readManifest, "readManifest");
643
+ function collectIssues(dir) {
644
+ const result = { errors: [], warnings: [], passed: [] };
645
+ const manifest = readManifest(dir);
646
+ if (manifest === void 0) {
647
+ result.errors.push("\u8BFB\u4E0D\u5230 package.json\uFF08JSON \u8BED\u6CD5\u9519\u8BEF\u6216\u6587\u4EF6\u7F3A\u5931\uFF09");
648
+ return result;
649
+ }
650
+ const name = typeof manifest.name === "string" ? manifest.name : "";
651
+ if (name === "") result.errors.push("package.json \u7F3A\u5C11 name");
652
+ else result.passed.push(`\u5305\u540D ${name}`);
653
+ const dsh = manifest.dsh ?? {};
654
+ const bundle = dsh.bundle ?? {};
655
+ const client = dsh.client ?? {};
656
+ if (typeof bundle.patch !== "string") {
657
+ result.errors.push("\u7F3A\u5C11 dsh.bundle.patch \u2014\u2014 DSH \u4E0D\u4F1A\u628A\u8FD9\u4E2A\u5305\u5F53\u4F5C\u7EC4\u5408\u5305\uFF08bundle\uFF09");
658
+ } else {
659
+ const patchPath = resolve5(dir, bundle.patch.replace(/^\.\//u, ""));
660
+ if (!existsSync3(patchPath)) {
661
+ result.errors.push(`dsh.bundle.patch \u6307\u5411\u7684 ${bundle.patch} \u4E0D\u5B58\u5728`);
662
+ } else {
663
+ const text5 = readFileSync2(patchPath, "utf8");
664
+ if (!text5.includes("insert:")) result.errors.push("cordis.patch.yml \u91CC\u6CA1\u6709 insert: \u6BB5\u843D\uFF0C\u63D2\u4EF6\u884C\u4E0D\u4F1A\u8FDB\u7EC4\u5408\u6811");
665
+ else if (name !== "" && !text5.includes(name)) {
666
+ result.warnings.push(`cordis.patch.yml \u91CC\u6CA1\u6709\u51FA\u73B0\u5305\u540D ${name}\uFF0C\u786E\u8BA4 insert \u7684 name \u5199\u5BF9\u4E86`);
667
+ } else result.passed.push("cordis.patch.yml \u4F1A\u63D2\u5165\u672C\u5305\u7684\u884C");
668
+ }
669
+ }
670
+ if (client.platform !== "web") {
671
+ result.errors.push("dsh.client.platform \u5FC5\u987B\u662F 'web' \u2014\u2014 \u5426\u5219 DSH \u4E0D\u4F1A\u7ED9\u9875\u9762\u63D0\u4F9B\u5BA2\u6237\u7AEF bundle");
672
+ } else result.passed.push("dsh.client.platform = web");
673
+ const exportsField = manifest.exports ?? {};
674
+ const hostEntry = exportsField["."];
675
+ const clientEntry = exportsField["./client"];
676
+ if (typeof hostEntry !== "string") result.errors.push('exports["."] \u672A\u58F0\u660E \u2014\u2014 DSH \u52A0\u8F7D\u4E0D\u5230 Host \u4FA7\u63D2\u4EF6');
677
+ else if (!existsSync3(resolve5(dir, hostEntry.replace(/^\.\//u, "")))) {
678
+ result.errors.push(`exports["."] \u6307\u5411\u7684 ${hostEntry} \u4E0D\u5B58\u5728\uFF0C\u5148\u6784\u5EFA`);
679
+ } else result.passed.push("Host \u5165\u53E3\u5B58\u5728");
680
+ if (typeof clientEntry !== "string") result.errors.push('exports["./client"] \u672A\u58F0\u660E \u2014\u2014 \u9875\u9762\u62FF\u4E0D\u5230\u5BA2\u6237\u7AEF bundle');
681
+ const scripts = manifest.scripts ?? {};
682
+ if (scripts.prepare !== void 0 || scripts.postinstall !== void 0) {
683
+ result.errors.push("\u58F0\u660E\u4E86 prepare / postinstall \u2014\u2014 DSH \u5B89\u88C5\u65F6\u4E0D\u6784\u5EFA\uFF0C\u4EA7\u7269\u5FC5\u987B\u9884\u5148\u63D0\u4EA4");
684
+ } else result.passed.push("\u6CA1\u6709\u5B89\u88C5\u671F\u751F\u547D\u5468\u671F\u94A9\u5B50");
685
+ const dependencyText = JSON.stringify({
686
+ dependencies: manifest.dependencies,
687
+ peerDependencies: manifest.peerDependencies,
688
+ devDependencies: manifest.devDependencies
689
+ });
690
+ if (dependencyText.includes("workspace:")) {
691
+ result.errors.push("\u4F9D\u8D56\u91CC\u51FA\u73B0\u4E86 workspace: \u534F\u8BAE \u2014\u2014 GitHub \u5B50\u76EE\u5F55\u76F4\u88C5\u65F6\u89E3\u6790\u4E0D\u4E86");
692
+ } else result.passed.push("\u6CA1\u6709 workspace: \u534F\u8BAE\u4F9D\u8D56");
693
+ if (typeof clientEntry === "string") {
694
+ const clientPath = resolve5(dir, clientEntry.replace(/^\.\//u, ""));
695
+ if (!existsSync3(clientPath)) {
696
+ result.errors.push(`\u5BA2\u6237\u7AEF\u4EA7\u7269 ${clientEntry} \u4E0D\u5B58\u5728\uFF0C\u5148\u8FD0\u884C\u6784\u5EFA`);
697
+ } else {
698
+ const code = readFileSync2(clientPath, "utf8");
699
+ const loads = (code.match(/__ModuleLoader__\.load\(/gu) ?? []).length;
700
+ if (loads !== 1) result.errors.push(`\u5BA2\u6237\u7AEF\u4EA7\u7269\u91CC __ModuleLoader__.load \u51FA\u73B0 ${loads} \u6B21\uFF0C\u5E94\u4E3A 1 \u6B21\uFF08\u5148\u6784\u5EFA\uFF09`);
701
+ else result.passed.push("\u4EA7\u7269\u5F62\u6001\u662F DSH \u5BA2\u6237\u7AEF\u6A21\u5757\u534F\u8BAE");
702
+ if (code.includes("import(")) result.errors.push("\u5BA2\u6237\u7AEF\u4EA7\u7269\u91CC\u6709\u52A8\u6001 import()\uFF0CDSH \u53EA\u652F\u6301\u81EA\u5305\u542B chunk");
703
+ const requires = [...code.matchAll(/require\((['"])([^'"]+)\1\)/gu)].map((match) => match[2] ?? "");
704
+ const foreign = requires.filter((id) => !PLATFORM_MODULES.includes(id) && !id.startsWith("@deepseek-ai/"));
705
+ if (foreign.length > 0) {
706
+ result.errors.push(`\u4EA7\u7269 require \u4E86\u975E\u5E73\u53F0\u6A21\u5757\uFF1A${[...new Set(foreign)].join(", ")} \u2014\u2014 \u4F9D\u8D56\u6CA1\u6709\u88AB\u6253\u8FDB\u4EA7\u7269`);
707
+ } else if (requires.length > 0) {
708
+ result.passed.push(`\u4EA7\u7269\u53EA require \u5E73\u53F0\u6A21\u5757\uFF08${[...new Set(requires)].join(", ")}\uFF09`);
709
+ }
710
+ if (name !== "" && !code.includes(`"${name}"`) && !code.includes(`'${name}'`)) {
711
+ result.warnings.push(`\u4EA7\u7269\u91CC\u7684\u6A21\u5757 id \u4E0E\u5305\u540D ${name} \u4E0D\u4E00\u81F4\uFF0C\u68C0\u67E5 dshBundle({ id })`);
712
+ }
713
+ }
714
+ }
715
+ return result;
716
+ }
717
+ __name(collectIssues, "collectIssues");
718
+ function dshCheckCommand() {
719
+ const dir = process.cwd();
720
+ const result = collectIssues(dir);
721
+ logger.step("DSH \u63D2\u4EF6\u88C5\u524D\u6821\u9A8C");
722
+ for (const item of result.passed) console.log(` \u2714 ${item}`);
723
+ for (const item of result.warnings) console.log(` \u26A0 ${item}`);
724
+ for (const item of result.errors) console.log(` \u2716 ${item}`);
725
+ if (result.errors.length > 0) {
726
+ logger.error(`${result.errors.length} \u9879\u4E0D\u901A\u8FC7\uFF0C\u88C5\u8FDB DSH \u540E\u4E0D\u4F1A\u6B63\u5E38\u5DE5\u4F5C\u3002`);
727
+ process.exitCode = 1;
728
+ return;
729
+ }
730
+ logger.success(`\u5168\u90E8\u901A\u8FC7\uFF08${result.passed.length} \u9879${result.warnings.length > 0 ? `\uFF0C${result.warnings.length} \u6761\u8B66\u544A` : ""}\uFF09`);
731
+ }
732
+ __name(dshCheckCommand, "dshCheckCommand");
733
+ function readPnpmVersion() {
734
+ try {
735
+ return execSync3("pnpm --version", { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
736
+ } catch {
737
+ return void 0;
738
+ }
739
+ }
740
+ __name(readPnpmVersion, "readPnpmVersion");
741
+ var majorOf = /* @__PURE__ */ __name((version) => {
742
+ const major = Number.parseInt((version ?? "").split(".")[0] ?? "", 10);
743
+ return Number.isFinite(major) ? major : 0;
744
+ }, "majorOf");
745
+ function buildInstallSpec(options) {
746
+ if (options.spec !== void 0) return { spec: options.spec };
747
+ if (options.from !== void 0) {
748
+ const target = resolve5(options.from);
749
+ if (!existsSync3(target)) return { error: `--from \u6307\u5411\u7684\u8DEF\u5F84\u4E0D\u5B58\u5728\uFF1A${target}` };
750
+ return { spec: target };
751
+ }
752
+ if (options.repo !== void 0) {
753
+ const ref = options.tag !== void 0 && options.tag !== "" ? `#${options.tag}` : "";
754
+ const sub = options.subpath !== void 0 && options.subpath !== "" ? `${ref === "" ? "#" : "&"}path:${options.subpath}` : "";
755
+ return { spec: `github:${options.repo}${ref}${sub}` };
756
+ }
757
+ return { error: "\u9700\u8981 --spec\u3001--from \u6216 --repo \u4E4B\u4E00\u6765\u6307\u5B9A\u5B89\u88C5\u6765\u6E90\u3002" };
758
+ }
759
+ __name(buildInstallSpec, "buildInstallSpec");
760
+ var CMD_NEEDS_QUOTE = /[\s&|<>^()"']/u;
761
+ function quoteForCmd(part) {
762
+ return CMD_NEEDS_QUOTE.test(part) ? `"${part.replace(/"/gu, '""')}"` : part;
763
+ }
764
+ __name(quoteForCmd, "quoteForCmd");
765
+ function buildShellCommand(exe, args) {
766
+ return [exe, ...args].map(quoteForCmd).join(" ");
767
+ }
768
+ __name(buildShellCommand, "buildShellCommand");
769
+ function spawnDsh(args, dry) {
770
+ if (dry) {
771
+ console.log(`
772
+ ${buildShellCommand("dsh", args)}
773
+ `);
774
+ return 0;
775
+ }
776
+ if (process.platform === "win32") {
777
+ const result2 = spawnSync(buildShellCommand("dsh", args), { stdio: "inherit", shell: true });
778
+ return result2.status ?? 1;
779
+ }
780
+ const result = spawnSync("dsh", args, { stdio: "inherit" });
781
+ return result.status ?? 1;
782
+ }
783
+ __name(spawnDsh, "spawnDsh");
784
+ function dshInstallCommand(options) {
785
+ const profile = options.profile ?? "desktop";
786
+ const { spec, error: error2 } = buildInstallSpec(options);
787
+ if (spec === void 0) {
788
+ logger.error(error2 ?? "\u672A\u77E5\u9519\u8BEF");
789
+ process.exitCode = 1;
790
+ return;
791
+ }
792
+ const usesSubpath = spec.includes("path:");
793
+ const pnpmVersion = readPnpmVersion();
794
+ if (usesSubpath && pnpmVersion !== void 0 && majorOf(pnpmVersion) < 11) {
795
+ logger.warn(
796
+ `\u68C0\u6D4B\u5230 pnpm ${pnpmVersion}\uFF1A11 \u4EE5\u4E0B\u4E0D\u652F\u6301 git \u5B50\u76EE\u5F55\u8BED\u6CD5\uFF08#\u2026&path:\uFF09\uFF0C\u4F1A\u9759\u9ED8\u88C5\u6210\u4ED3\u5E93\u6839\u800C\u4E0D\u662F\u4F60\u60F3\u8981\u7684\u5B50\u5305\u3002DSH \u5185\u7F6E\u7684 pnpm 11 \u4E0D\u53D7\u5F71\u54CD \u2014\u2014 \u5EFA\u8BAE\u6539\u7528 DSH \u63D2\u4EF6\u9875\u5B89\u88C5\u3002`
797
+ );
798
+ }
799
+ if (usesSubpath && process.platform === "win32") {
800
+ logger.info("Windows\uFF1A\u4F1A\u901A\u8FC7 cmd /d /s /c \u6267\u884C\uFF0C\u907F\u514D & \u88AB\u5F53\u6210\u547D\u4EE4\u5206\u9694\u7B26\u3002");
801
+ }
802
+ logger.step(`\u5B89\u88C5\u5230 profile\u300C${profile}\u300D`);
803
+ console.log(` spec: ${spec}`);
804
+ if (!isAbsolute(spec) && !spec.startsWith("github:") && !spec.startsWith("git+") && !spec.startsWith("http")) {
805
+ logger.warn("\u8FD9\u4E2A spec \u65E2\u4E0D\u662F\u7EDD\u5BF9\u8DEF\u5F84\u4E5F\u4E0D\u662F git/URL\uFF0C\u786E\u8BA4\u6CA1\u6709\u5199\u9519\u3002");
806
+ }
807
+ const status = spawnDsh(["plugin", "--profile", profile, "add", spec], options.dry === true);
808
+ if (options.dry === true) {
809
+ logger.info("dry run\uFF1A\u4EE5\u4E0A\u547D\u4EE4\u6CA1\u6709\u6267\u884C\u3002");
810
+ return;
811
+ }
812
+ if (status !== 0) {
813
+ logger.error(`\u5B89\u88C5\u5931\u8D25\uFF08\u9000\u51FA\u7801 ${status}\uFF09\u3002\u8BCA\u65AD\u65E5\u5FD7\u5728 ~/.dsh/profiles/${profile}/.plugin-manager/logs/`);
814
+ process.exitCode = status;
815
+ return;
816
+ }
817
+ logger.success("\u5B89\u88C5\u5B8C\u6210 \u2014\u2014 \u5B8C\u5168\u9000\u51FA DSH \u518D\u6253\u5F00\u5373\u53EF\u751F\u6548");
818
+ }
819
+ __name(dshInstallCommand, "dshInstallCommand");
820
+ var ACTIONS = {
821
+ init: "\u521B\u5EFA\u4E00\u4E2A DSH \u63D2\u4EF6\u9879\u76EE",
822
+ dev: "\u672C\u5730\u9884\u89C8\uFF08\u6D4F\u89C8\u5668\u91CC\u770B\u9762\u677F\uFF0C\u4E0D\u7528\u88C5\u8FDB DSH\uFF09",
823
+ build: "\u6784\u5EFA lib/{index,client}.js",
824
+ check: "\u88C5\u524D\u4E00\u81F4\u6027\u6821\u9A8C",
825
+ install: "\u628A\u63D2\u4EF6\u88C5\u8FDB DSH profile"
826
+ };
827
+ async function dshCommand(action, target, options) {
828
+ switch (action) {
829
+ case "init":
830
+ case "create":
831
+ await dshInitCommand(target, options);
832
+ return;
833
+ case "dev":
834
+ await dshDevCommand(options);
835
+ return;
836
+ case "build":
837
+ await dshBuildCommand();
838
+ return;
839
+ case "check":
840
+ dshCheckCommand();
841
+ return;
842
+ case "install":
843
+ dshInstallCommand(options);
844
+ return;
845
+ default:
846
+ logger.error(`\u672A\u77E5\u5B50\u547D\u4EE4: ${action ?? "(\u7A7A)"}`);
847
+ console.log("\n \u53EF\u7528\u5B50\u547D\u4EE4\uFF1A");
848
+ for (const [name, description] of Object.entries(ACTIONS)) {
849
+ console.log(` vobs dsh ${name.padEnd(8)} ${description}`);
850
+ }
851
+ process.exitCode = 1;
852
+ }
853
+ }
854
+ __name(dshCommand, "dshCommand");
855
+
324
856
  // packages/cli/src/banner.ts
325
857
  var BANNER_LINE1 = "\u{1D5E9}\u{1D5E2}\u{1D5D5}\u{1D5E6} \u{1D5D6}\u{1D5DF}\u{1D5DC} \u{1D603}\u{1D7ED}.\u{1D7EC}";
326
858
  var BANNER_TAGLINE = "Signals First \xB7 Zero Re-renders \xB7 Ultra Lightweight";
@@ -397,6 +929,20 @@ function createCLI() {
397
929
  dev: options.dev
398
930
  });
399
931
  });
932
+ cli.command("dsh <action> [target]", "DSH \u63D2\u4EF6\u5DE5\u5177\u94FE\uFF08init / dev / build / check / install\uFF09").option("--dir <dir>", "init\uFF1A\u76EE\u6807\u76EE\u5F55").option("--pm <pm>", "init\uFF1A\u5305\u7BA1\u7406\u5668\uFF08pnpm/npm\uFF09").option("--port <port>", "dev\uFF1A\u9884\u89C8\u7AEF\u53E3", { default: 5199 }).option("--profile <name>", "install\uFF1ADSH profile \u540D", { default: "desktop" }).option("--spec <spec>", "install\uFF1A\u5B8C\u6574\u5B89\u88C5 spec").option("--repo <owner/name>", "install\uFF1AGitHub owner/name").option("--tag <ref>", "install\uFF1AGit tag / \u5206\u652F / commit").option("--subpath <path>", "install\uFF1A\u4ED3\u5E93\u5185\u5B50\u76EE\u5F55").option("--from <path>", "install\uFF1A\u4ECE\u672C\u5730\u76EE\u5F55\u5B89\u88C5").option("--dry", "install\uFF1A\u53EA\u6253\u5370\u547D\u4EE4\uFF0C\u4E0D\u6267\u884C").action(async (action, target, options) => {
933
+ await dshCommand(action, target, {
934
+ dir: options.dir,
935
+ pm: options.pm,
936
+ profile: options.profile,
937
+ spec: options.spec,
938
+ repo: options.repo,
939
+ tag: options.tag,
940
+ subpath: options.subpath,
941
+ from: options.from,
942
+ dry: options.dry === true,
943
+ port: options.port === void 0 ? void 0 : Number(options.port)
944
+ });
945
+ });
400
946
  cli.command("logo", "Show the vobs CLI logo and version info").action(() => {
401
947
  showLogo();
402
948
  });