@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/index.cjs CHANGED
@@ -122,13 +122,13 @@ function ensureDir(dir) {
122
122
  __name(ensureDir, "ensureDir");
123
123
  async function copyDirRecursive(srcDir, destDir, context) {
124
124
  const { readdirSync } = await import("fs");
125
- const { join } = await import("path");
125
+ const { join: join2 } = await import("path");
126
126
  const entries = readdirSync(srcDir, { withFileTypes: true });
127
127
  for (const entry of entries) {
128
- const srcPath = join(srcDir, entry.name);
128
+ const srcPath = join2(srcDir, entry.name);
129
129
  const isHbs = entry.name.endsWith(".hbs");
130
130
  const destName = isHbs ? entry.name.slice(0, -4) : entry.name;
131
- const destPath = join(destDir, destName);
131
+ const destPath = join2(destDir, destName);
132
132
  if (entry.isDirectory()) {
133
133
  ensureDir(destPath);
134
134
  await copyDirRecursive(srcPath, destPath, context);
@@ -142,8 +142,11 @@ async function copyDirRecursive(srcDir, destDir, context) {
142
142
  }
143
143
  }
144
144
  __name(copyDirRecursive, "copyDirRecursive");
145
- async function scaffoldProject(targetDir, context) {
146
- const templateDir = (0, import_node_path.resolve)(TEMPLATES_ROOT, "basic");
145
+ async function scaffoldProject(targetDir, context, template = "basic") {
146
+ const templateDir = (0, import_node_path.resolve)(TEMPLATES_ROOT, template);
147
+ if (!(0, import_node_fs.existsSync)(templateDir)) {
148
+ throw new Error(`\u6A21\u677F\u4E0D\u5B58\u5728: ${template}\uFF08\u53EF\u7528\u6A21\u677F\u89C1 ${TEMPLATES_ROOT}\uFF09`);
149
+ }
147
150
  ensureDir(targetDir);
148
151
  await copyDirRecursive(templateDir, targetDir, context);
149
152
  }
@@ -374,6 +377,535 @@ async function addCommand(options) {
374
377
  }
375
378
  __name(addCommand, "addCommand");
376
379
 
380
+ // packages/cli/src/commands/dsh.ts
381
+ var import_node_fs3 = require("fs");
382
+ var import_promises = require("fs/promises");
383
+ var import_node_child_process3 = require("child_process");
384
+ var import_node_http = require("http");
385
+ var import_node_module = require("module");
386
+ var import_node_path5 = require("path");
387
+ var p4 = __toESM(require("@clack/prompts"), 1);
388
+ var PLATFORM_MODULES = ["react", "react-dom"];
389
+ var vobsVersion = /* @__PURE__ */ __name(() => {
390
+ try {
391
+ const manifest = JSON.parse(
392
+ (0, import_node_fs3.readFileSync)(new URL("../../package.json", __VOBS_CJS_FILE_URL), "utf8")
393
+ );
394
+ return manifest.version ?? "1.7.5";
395
+ } catch {
396
+ return "1.7.5";
397
+ }
398
+ }, "vobsVersion");
399
+ function toRowId(packageName) {
400
+ return packageName.replace(/^@[^/]+\//u, "");
401
+ }
402
+ __name(toRowId, "toRowId");
403
+ async function dshInitCommand(target, options) {
404
+ const name = target ?? await p4.text({
405
+ message: "\u63D2\u4EF6\u5305\u540D\uFF08npm \u5305\u540D\uFF0C\u5C0F\u5199\uFF09:",
406
+ placeholder: "dsh-plugin-my-panel",
407
+ 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")
408
+ });
409
+ if (p4.isCancel(name)) {
410
+ p4.cancel("\u5DF2\u53D6\u6D88");
411
+ return;
412
+ }
413
+ const packageManager = options.pm ?? await p4.select({
414
+ message: "\u5305\u7BA1\u7406\u5668:",
415
+ options: [
416
+ { value: "pnpm", label: "pnpm" },
417
+ { value: "npm", label: "npm" }
418
+ ]
419
+ });
420
+ if (p4.isCancel(packageManager)) {
421
+ p4.cancel("\u5DF2\u53D6\u6D88");
422
+ return;
423
+ }
424
+ const targetDir = options.dir !== void 0 ? (0, import_node_path5.resolve)(options.dir) : (0, import_node_path5.resolve)(process.cwd(), name);
425
+ const rowId = toRowId(name);
426
+ const displayName = rowId.replace(/^dsh-plugin-/u, "").split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
427
+ logger.step(`\u521B\u5EFA DSH \u63D2\u4EF6\u9879\u76EE ${name} \u2026`);
428
+ await scaffoldProject(
429
+ targetDir,
430
+ { packageName: name, rowId, displayName, vobsVersion: vobsVersion() },
431
+ "dsh-plugin"
432
+ );
433
+ ensureDir(targetDir);
434
+ (0, import_node_fs3.writeFileSync)(
435
+ (0, import_node_path5.resolve)(targetDir, ".gitignore"),
436
+ ["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"),
437
+ "utf8"
438
+ );
439
+ logger.success("\u9879\u76EE\u5DF2\u751F\u6210");
440
+ logger.step("\u5B89\u88C5\u4F9D\u8D56 \u2026");
441
+ try {
442
+ installDependencies(targetDir, packageManager);
443
+ logger.success("\u4F9D\u8D56\u5DF2\u5B89\u88C5");
444
+ } catch {
445
+ logger.warn(`\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u6267\u884C ${packageManager} install`);
446
+ }
447
+ logger.step("\u4E0B\u4E00\u6B65");
448
+ console.log(`
449
+ cd ${name}
450
+ ${packageManager} run dev # \u672C\u5730\u9884\u89C8\uFF0C\u4E0D\u7528\u88C5\u8FDB DSH
451
+ ${packageManager} run build # \u4EA7\u51FA lib/{index,client}.js
452
+
453
+ # \u63D0\u4EA4\u4EA7\u7269\u5E76\u6253 tag \u4E4B\u540E\uFF0C\u5728 DSH \u63D2\u4EF6\u9875\u586B\uFF1A
454
+ github:<owner>/<repo>#v0.1.0&path:/<\u672C\u5305\u5728\u4ED3\u5E93\u4E2D\u7684\u8DEF\u5F84>
455
+ `);
456
+ }
457
+ __name(dshInitCommand, "dshInitCommand");
458
+ async function dshBuildCommand() {
459
+ const projectDir = process.cwd();
460
+ const configFile = (0, import_node_path5.resolve)(projectDir, "vite.config.ts");
461
+ if (!(0, import_node_fs3.existsSync)(configFile)) {
462
+ logger.error("\u5F53\u524D\u76EE\u5F55\u6CA1\u6709 vite.config.ts\uFF0C\u8BF7\u5728\u63D2\u4EF6\u9879\u76EE\u6839\u76EE\u5F55\u8FD0\u884C\u3002");
463
+ process.exitCode = 1;
464
+ return;
465
+ }
466
+ const manifest = readManifest(projectDir);
467
+ if (manifest === void 0) {
468
+ logger.error("\u8BFB\u4E0D\u5230 package.json\u3002");
469
+ process.exitCode = 1;
470
+ return;
471
+ }
472
+ const hostEntry = resolveExport(manifest, ".");
473
+ if (hostEntry === void 0) {
474
+ logger.error('package.json \u7684 exports \u91CC\u6CA1\u6709 "."\uFF0CDSH \u52A0\u8F7D\u4E0D\u5230 Host \u4FA7\u63D2\u4EF6\u3002');
475
+ process.exitCode = 1;
476
+ return;
477
+ }
478
+ const { build: build2 } = await import("vite");
479
+ logger.info("\u6784\u5EFA\u5BA2\u6237\u7AEF\u4EA7\u7269 \u2026");
480
+ await build2({ configFile, mode: "production" });
481
+ logger.info("\u6784\u5EFA Host \u4EA7\u7269 \u2026");
482
+ const hostTarget = (0, import_node_path5.resolve)(projectDir, hostEntry.replace(/^\.\//u, ""));
483
+ const hostEntrySource = (0, import_node_path5.resolve)(projectDir, "src", "host", "index.ts");
484
+ if (!(0, import_node_fs3.existsSync)(hostEntrySource)) {
485
+ logger.warn(`\u6CA1\u6709\u627E\u5230 ${hostEntrySource}\uFF0C\u8DF3\u8FC7 Host \u6784\u5EFA\u3002`);
486
+ return;
487
+ }
488
+ await build2({
489
+ configFile: false,
490
+ root: projectDir,
491
+ logLevel: "warn",
492
+ build: {
493
+ outDir: (0, import_node_path5.relative)(projectDir, (0, import_node_path5.dirname)(hostTarget)) || ".",
494
+ emptyOutDir: false,
495
+ target: "es2022",
496
+ minify: false,
497
+ sourcemap: false,
498
+ lib: {
499
+ entry: hostEntrySource,
500
+ formats: ["es"],
501
+ fileName: /* @__PURE__ */ __name(() => (0, import_node_path5.basename)(hostTarget), "fileName")
502
+ }
503
+ }
504
+ });
505
+ logger.success("\u6784\u5EFA\u5B8C\u6210 \u2192 \u5BA2\u6237\u7AEF\u4E0E Host \u4EA7\u7269\u90FD\u5DF2\u5C31\u4F4D");
506
+ }
507
+ __name(dshBuildCommand, "dshBuildCommand");
508
+ function resolveExport(manifest, key) {
509
+ const exportsField = manifest.exports ?? {};
510
+ const entry = exportsField[key];
511
+ if (typeof entry === "string") return entry;
512
+ if (typeof entry === "object" && entry !== null) {
513
+ const record = entry;
514
+ for (const condition of ["default", "import", "require"]) {
515
+ const value = record[condition];
516
+ if (typeof value === "string") return value;
517
+ }
518
+ }
519
+ return void 0;
520
+ }
521
+ __name(resolveExport, "resolveExport");
522
+ function buildPreviewHtml(options) {
523
+ const name = JSON.stringify(options.packageName).replace(/</gu, "\\u003c");
524
+ const title = (options.title ?? options.packageName).replace(/[<>&]/gu, "");
525
+ return `<!doctype html>
526
+ <html lang="zh-CN">
527
+ <head>
528
+ <meta charset="utf-8">
529
+ <meta name="viewport" content="width=device-width, initial-scale=1">
530
+ <title>vobs preview \xB7 ${title}</title>
531
+ </head>
532
+ <body>
533
+ <div id="root"></div>
534
+
535
+ <!-- 1. \u5148\u88C5\u57AB\u7247\uFF1A\u5FC5\u987B\u5728\u63D2\u4EF6 bundle \u4E4B\u524D\uFF0C\u6355\u83B7\u5B83\u7684 factory \u6CE8\u518C -->
536
+ <script>
537
+ window.__VOBS_DSH_PREVIEW__ = { factories: new Map() };
538
+ window.__ModuleLoader__ = {
539
+ load: function (entry) { window.__VOBS_DSH_PREVIEW__.factories.set(entry.id, entry.factory); }
540
+ };
541
+ </script>
542
+
543
+ <!-- 2. \u63D2\u4EF6\u4EA7\u7269\uFF1A\u5B83\u53EA\u6CE8\u518C factory\uFF0C\u4E0D\u4EA7\u751F\u526F\u4F5C\u7528 -->
544
+ <script src="/client.js"></script>
545
+
546
+ <!-- 3. \u542F\u52A8\u9884\u89C8\u5916\u58F3 -->
547
+ <script type="module">
548
+ import { startPreview } from '/preview.js';
549
+ window.__VOBS_PREVIEW__ = startPreview({
550
+ container: document.getElementById('root'),
551
+ packageName: ${name}
552
+ });
553
+ </script>
554
+
555
+ <!-- 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 -->
556
+ <script>
557
+ if (!location.search.includes('static')) {
558
+ new EventSource('/events').addEventListener('reload', function () { location.reload(); });
559
+ }
560
+ </script>
561
+ </body>
562
+ </html>
563
+ `;
564
+ }
565
+ __name(buildPreviewHtml, "buildPreviewHtml");
566
+ async function dshDevCommand(options) {
567
+ const projectDir = process.cwd();
568
+ const manifest = readManifest(projectDir);
569
+ if (manifest === void 0) {
570
+ logger.error("\u5F53\u524D\u76EE\u5F55\u6CA1\u6709\u53EF\u8BFB\u7684 package.json\u3002");
571
+ process.exitCode = 1;
572
+ return;
573
+ }
574
+ if (readManifest(projectDir)?.dsh === void 0) {
575
+ logger.error("\u8FD9\u4E0D\u662F\u4E00\u4E2A DSH \u63D2\u4EF6\u9879\u76EE\uFF08package.json \u91CC\u6CA1\u6709 dsh \u5B57\u6BB5\uFF09\u3002");
576
+ process.exitCode = 1;
577
+ return;
578
+ }
579
+ const packageName = typeof manifest.name === "string" ? manifest.name : "dsh-plugin";
580
+ const clientEntry = resolveExport(manifest, "./client");
581
+ if (clientEntry === void 0) {
582
+ logger.error('package.json \u7684 exports \u91CC\u6CA1\u6709 "./client"\uFF0C\u9875\u9762\u62FF\u4E0D\u5230\u5BA2\u6237\u7AEF bundle\u3002');
583
+ process.exitCode = 1;
584
+ return;
585
+ }
586
+ const clientFile = (0, import_node_path5.resolve)(projectDir, clientEntry.replace(/^\.\//u, ""));
587
+ let previewFile;
588
+ try {
589
+ const projectRequire = (0, import_node_module.createRequire)((0, import_node_path5.join)(projectDir, "package.json"));
590
+ let packageRoot;
591
+ try {
592
+ packageRoot = (0, import_node_path5.dirname)(projectRequire.resolve("@vobs/dsh/package.json"));
593
+ } catch {
594
+ packageRoot = (0, import_node_path5.dirname)((0, import_node_path5.dirname)(projectRequire.resolve("@vobs/dsh")));
595
+ }
596
+ const candidate = (0, import_node_path5.join)(packageRoot, "dist", "preview.js");
597
+ previewFile = (0, import_node_fs3.existsSync)(candidate) ? candidate : void 0;
598
+ } catch {
599
+ previewFile = void 0;
600
+ }
601
+ if (previewFile === void 0) {
602
+ 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");
603
+ process.exitCode = 1;
604
+ return;
605
+ }
606
+ const port = options.port ?? 5199;
607
+ const clients = /* @__PURE__ */ new Set();
608
+ const broadcast = /* @__PURE__ */ __name((event) => {
609
+ for (const client of clients) client.write(`event: ${event}
610
+ data: 1
611
+
612
+ `);
613
+ }, "broadcast");
614
+ logger.info("\u6784\u5EFA\u4EA7\u7269 \u2026");
615
+ const { build: build2 } = await import("vite");
616
+ const configFile = (0, import_node_path5.resolve)(projectDir, "vite.config.ts");
617
+ let buildError;
618
+ try {
619
+ const watcher = await build2({
620
+ configFile,
621
+ mode: "development",
622
+ logLevel: "warn",
623
+ build: { watch: {} }
624
+ });
625
+ watcher.on("event", (event) => {
626
+ if (event.code === "END") {
627
+ buildError = void 0;
628
+ logger.success("\u91CD\u65B0\u6784\u5EFA\u5B8C\u6210");
629
+ broadcast("reload");
630
+ } else if (event.code === "ERROR") {
631
+ buildError = event.error?.message ?? "\u6784\u5EFA\u5931\u8D25";
632
+ logger.error(buildError);
633
+ }
634
+ });
635
+ process.on("SIGINT", () => {
636
+ void watcher.close().then(() => process.exit(0));
637
+ });
638
+ } catch (error2) {
639
+ logger.error(`\u6784\u5EFA\u5931\u8D25\uFF1A${error2 instanceof Error ? error2.message : String(error2)}`);
640
+ process.exitCode = 1;
641
+ return;
642
+ }
643
+ const server = (0, import_node_http.createServer)((request, response) => {
644
+ const url = (request.url ?? "/").split("?")[0];
645
+ if (url === "/events") {
646
+ response.writeHead(200, {
647
+ "content-type": "text/event-stream",
648
+ "cache-control": "no-store",
649
+ connection: "keep-alive"
650
+ });
651
+ response.write(": connected\n\n");
652
+ clients.add(response);
653
+ request.on("close", () => clients.delete(response));
654
+ return;
655
+ }
656
+ const send = /* @__PURE__ */ __name((body, type) => {
657
+ response.writeHead(200, { "content-type": type, "cache-control": "no-store" });
658
+ response.end(body);
659
+ }, "send");
660
+ if (url === "/") {
661
+ send(buildPreviewHtml({ packageName }), "text/html; charset=utf-8");
662
+ return;
663
+ }
664
+ if (url === "/preview.js") {
665
+ void (0, import_promises.readFile)(previewFile).then((body) => send(body, "text/javascript; charset=utf-8"));
666
+ return;
667
+ }
668
+ if (url === "/client.js") {
669
+ if (!(0, import_node_fs3.existsSync)(clientFile)) {
670
+ response.writeHead(503, { "content-type": "text/plain; charset=utf-8" });
671
+ response.end(`\u8FD8\u6CA1\u6709\u4EA7\u7269\uFF1A${clientEntry}
672
+ ${buildError ?? ""}`);
673
+ return;
674
+ }
675
+ void (0, import_promises.readFile)(clientFile).then((body) => send(body, "text/javascript; charset=utf-8"));
676
+ return;
677
+ }
678
+ response.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
679
+ response.end("not found");
680
+ });
681
+ await new Promise((resolveListen) => {
682
+ server.listen(port, "127.0.0.1", resolveListen);
683
+ });
684
+ logger.success(`\u9884\u89C8\u5DF2\u5C31\u7EEA\uFF1Ahttp://127.0.0.1:${port}/`);
685
+ console.log("\n \u6539\u4EE3\u7801\u4F1A\u81EA\u52A8\u91CD\u5EFA\u5E76\u5237\u65B0\u9875\u9762\uFF1BCtrl+C \u9000\u51FA\u3002\n");
686
+ }
687
+ __name(dshDevCommand, "dshDevCommand");
688
+ function readManifest(dir) {
689
+ try {
690
+ return JSON.parse((0, import_node_fs3.readFileSync)((0, import_node_path5.resolve)(dir, "package.json"), "utf8"));
691
+ } catch {
692
+ return void 0;
693
+ }
694
+ }
695
+ __name(readManifest, "readManifest");
696
+ function collectIssues(dir) {
697
+ const result = { errors: [], warnings: [], passed: [] };
698
+ const manifest = readManifest(dir);
699
+ if (manifest === void 0) {
700
+ result.errors.push("\u8BFB\u4E0D\u5230 package.json\uFF08JSON \u8BED\u6CD5\u9519\u8BEF\u6216\u6587\u4EF6\u7F3A\u5931\uFF09");
701
+ return result;
702
+ }
703
+ const name = typeof manifest.name === "string" ? manifest.name : "";
704
+ if (name === "") result.errors.push("package.json \u7F3A\u5C11 name");
705
+ else result.passed.push(`\u5305\u540D ${name}`);
706
+ const dsh = manifest.dsh ?? {};
707
+ const bundle = dsh.bundle ?? {};
708
+ const client = dsh.client ?? {};
709
+ if (typeof bundle.patch !== "string") {
710
+ result.errors.push("\u7F3A\u5C11 dsh.bundle.patch \u2014\u2014 DSH \u4E0D\u4F1A\u628A\u8FD9\u4E2A\u5305\u5F53\u4F5C\u7EC4\u5408\u5305\uFF08bundle\uFF09");
711
+ } else {
712
+ const patchPath = (0, import_node_path5.resolve)(dir, bundle.patch.replace(/^\.\//u, ""));
713
+ if (!(0, import_node_fs3.existsSync)(patchPath)) {
714
+ result.errors.push(`dsh.bundle.patch \u6307\u5411\u7684 ${bundle.patch} \u4E0D\u5B58\u5728`);
715
+ } else {
716
+ const text5 = (0, import_node_fs3.readFileSync)(patchPath, "utf8");
717
+ 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");
718
+ else if (name !== "" && !text5.includes(name)) {
719
+ result.warnings.push(`cordis.patch.yml \u91CC\u6CA1\u6709\u51FA\u73B0\u5305\u540D ${name}\uFF0C\u786E\u8BA4 insert \u7684 name \u5199\u5BF9\u4E86`);
720
+ } else result.passed.push("cordis.patch.yml \u4F1A\u63D2\u5165\u672C\u5305\u7684\u884C");
721
+ }
722
+ }
723
+ if (client.platform !== "web") {
724
+ 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");
725
+ } else result.passed.push("dsh.client.platform = web");
726
+ const exportsField = manifest.exports ?? {};
727
+ const hostEntry = exportsField["."];
728
+ const clientEntry = exportsField["./client"];
729
+ if (typeof hostEntry !== "string") result.errors.push('exports["."] \u672A\u58F0\u660E \u2014\u2014 DSH \u52A0\u8F7D\u4E0D\u5230 Host \u4FA7\u63D2\u4EF6');
730
+ else if (!(0, import_node_fs3.existsSync)((0, import_node_path5.resolve)(dir, hostEntry.replace(/^\.\//u, "")))) {
731
+ result.errors.push(`exports["."] \u6307\u5411\u7684 ${hostEntry} \u4E0D\u5B58\u5728\uFF0C\u5148\u6784\u5EFA`);
732
+ } else result.passed.push("Host \u5165\u53E3\u5B58\u5728");
733
+ if (typeof clientEntry !== "string") result.errors.push('exports["./client"] \u672A\u58F0\u660E \u2014\u2014 \u9875\u9762\u62FF\u4E0D\u5230\u5BA2\u6237\u7AEF bundle');
734
+ const scripts = manifest.scripts ?? {};
735
+ if (scripts.prepare !== void 0 || scripts.postinstall !== void 0) {
736
+ 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");
737
+ } else result.passed.push("\u6CA1\u6709\u5B89\u88C5\u671F\u751F\u547D\u5468\u671F\u94A9\u5B50");
738
+ const dependencyText = JSON.stringify({
739
+ dependencies: manifest.dependencies,
740
+ peerDependencies: manifest.peerDependencies,
741
+ devDependencies: manifest.devDependencies
742
+ });
743
+ if (dependencyText.includes("workspace:")) {
744
+ 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");
745
+ } else result.passed.push("\u6CA1\u6709 workspace: \u534F\u8BAE\u4F9D\u8D56");
746
+ if (typeof clientEntry === "string") {
747
+ const clientPath = (0, import_node_path5.resolve)(dir, clientEntry.replace(/^\.\//u, ""));
748
+ if (!(0, import_node_fs3.existsSync)(clientPath)) {
749
+ result.errors.push(`\u5BA2\u6237\u7AEF\u4EA7\u7269 ${clientEntry} \u4E0D\u5B58\u5728\uFF0C\u5148\u8FD0\u884C\u6784\u5EFA`);
750
+ } else {
751
+ const code = (0, import_node_fs3.readFileSync)(clientPath, "utf8");
752
+ const loads = (code.match(/__ModuleLoader__\.load\(/gu) ?? []).length;
753
+ 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`);
754
+ else result.passed.push("\u4EA7\u7269\u5F62\u6001\u662F DSH \u5BA2\u6237\u7AEF\u6A21\u5757\u534F\u8BAE");
755
+ 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");
756
+ const requires = [...code.matchAll(/require\((['"])([^'"]+)\1\)/gu)].map((match) => match[2] ?? "");
757
+ const foreign = requires.filter((id) => !PLATFORM_MODULES.includes(id) && !id.startsWith("@deepseek-ai/"));
758
+ if (foreign.length > 0) {
759
+ 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`);
760
+ } else if (requires.length > 0) {
761
+ result.passed.push(`\u4EA7\u7269\u53EA require \u5E73\u53F0\u6A21\u5757\uFF08${[...new Set(requires)].join(", ")}\uFF09`);
762
+ }
763
+ if (name !== "" && !code.includes(`"${name}"`) && !code.includes(`'${name}'`)) {
764
+ result.warnings.push(`\u4EA7\u7269\u91CC\u7684\u6A21\u5757 id \u4E0E\u5305\u540D ${name} \u4E0D\u4E00\u81F4\uFF0C\u68C0\u67E5 dshBundle({ id })`);
765
+ }
766
+ }
767
+ }
768
+ return result;
769
+ }
770
+ __name(collectIssues, "collectIssues");
771
+ function dshCheckCommand() {
772
+ const dir = process.cwd();
773
+ const result = collectIssues(dir);
774
+ logger.step("DSH \u63D2\u4EF6\u88C5\u524D\u6821\u9A8C");
775
+ for (const item of result.passed) console.log(` \u2714 ${item}`);
776
+ for (const item of result.warnings) console.log(` \u26A0 ${item}`);
777
+ for (const item of result.errors) console.log(` \u2716 ${item}`);
778
+ if (result.errors.length > 0) {
779
+ logger.error(`${result.errors.length} \u9879\u4E0D\u901A\u8FC7\uFF0C\u88C5\u8FDB DSH \u540E\u4E0D\u4F1A\u6B63\u5E38\u5DE5\u4F5C\u3002`);
780
+ process.exitCode = 1;
781
+ return;
782
+ }
783
+ logger.success(`\u5168\u90E8\u901A\u8FC7\uFF08${result.passed.length} \u9879${result.warnings.length > 0 ? `\uFF0C${result.warnings.length} \u6761\u8B66\u544A` : ""}\uFF09`);
784
+ }
785
+ __name(dshCheckCommand, "dshCheckCommand");
786
+ function readPnpmVersion() {
787
+ try {
788
+ return (0, import_node_child_process3.execSync)("pnpm --version", { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
789
+ } catch {
790
+ return void 0;
791
+ }
792
+ }
793
+ __name(readPnpmVersion, "readPnpmVersion");
794
+ var majorOf = /* @__PURE__ */ __name((version) => {
795
+ const major = Number.parseInt((version ?? "").split(".")[0] ?? "", 10);
796
+ return Number.isFinite(major) ? major : 0;
797
+ }, "majorOf");
798
+ function buildInstallSpec(options) {
799
+ if (options.spec !== void 0) return { spec: options.spec };
800
+ if (options.from !== void 0) {
801
+ const target = (0, import_node_path5.resolve)(options.from);
802
+ if (!(0, import_node_fs3.existsSync)(target)) return { error: `--from \u6307\u5411\u7684\u8DEF\u5F84\u4E0D\u5B58\u5728\uFF1A${target}` };
803
+ return { spec: target };
804
+ }
805
+ if (options.repo !== void 0) {
806
+ const ref = options.tag !== void 0 && options.tag !== "" ? `#${options.tag}` : "";
807
+ const sub = options.subpath !== void 0 && options.subpath !== "" ? `${ref === "" ? "#" : "&"}path:${options.subpath}` : "";
808
+ return { spec: `github:${options.repo}${ref}${sub}` };
809
+ }
810
+ return { error: "\u9700\u8981 --spec\u3001--from \u6216 --repo \u4E4B\u4E00\u6765\u6307\u5B9A\u5B89\u88C5\u6765\u6E90\u3002" };
811
+ }
812
+ __name(buildInstallSpec, "buildInstallSpec");
813
+ var CMD_NEEDS_QUOTE = /[\s&|<>^()"']/u;
814
+ function quoteForCmd(part) {
815
+ return CMD_NEEDS_QUOTE.test(part) ? `"${part.replace(/"/gu, '""')}"` : part;
816
+ }
817
+ __name(quoteForCmd, "quoteForCmd");
818
+ function buildShellCommand(exe, args) {
819
+ return [exe, ...args].map(quoteForCmd).join(" ");
820
+ }
821
+ __name(buildShellCommand, "buildShellCommand");
822
+ function spawnDsh(args, dry) {
823
+ if (dry) {
824
+ console.log(`
825
+ ${buildShellCommand("dsh", args)}
826
+ `);
827
+ return 0;
828
+ }
829
+ if (process.platform === "win32") {
830
+ const result2 = (0, import_node_child_process3.spawnSync)(buildShellCommand("dsh", args), { stdio: "inherit", shell: true });
831
+ return result2.status ?? 1;
832
+ }
833
+ const result = (0, import_node_child_process3.spawnSync)("dsh", args, { stdio: "inherit" });
834
+ return result.status ?? 1;
835
+ }
836
+ __name(spawnDsh, "spawnDsh");
837
+ function dshInstallCommand(options) {
838
+ const profile = options.profile ?? "desktop";
839
+ const { spec, error: error2 } = buildInstallSpec(options);
840
+ if (spec === void 0) {
841
+ logger.error(error2 ?? "\u672A\u77E5\u9519\u8BEF");
842
+ process.exitCode = 1;
843
+ return;
844
+ }
845
+ const usesSubpath = spec.includes("path:");
846
+ const pnpmVersion = readPnpmVersion();
847
+ if (usesSubpath && pnpmVersion !== void 0 && majorOf(pnpmVersion) < 11) {
848
+ logger.warn(
849
+ `\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`
850
+ );
851
+ }
852
+ if (usesSubpath && process.platform === "win32") {
853
+ 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");
854
+ }
855
+ logger.step(`\u5B89\u88C5\u5230 profile\u300C${profile}\u300D`);
856
+ console.log(` spec: ${spec}`);
857
+ if (!(0, import_node_path5.isAbsolute)(spec) && !spec.startsWith("github:") && !spec.startsWith("git+") && !spec.startsWith("http")) {
858
+ 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");
859
+ }
860
+ const status = spawnDsh(["plugin", "--profile", profile, "add", spec], options.dry === true);
861
+ if (options.dry === true) {
862
+ logger.info("dry run\uFF1A\u4EE5\u4E0A\u547D\u4EE4\u6CA1\u6709\u6267\u884C\u3002");
863
+ return;
864
+ }
865
+ if (status !== 0) {
866
+ logger.error(`\u5B89\u88C5\u5931\u8D25\uFF08\u9000\u51FA\u7801 ${status}\uFF09\u3002\u8BCA\u65AD\u65E5\u5FD7\u5728 ~/.dsh/profiles/${profile}/.plugin-manager/logs/`);
867
+ process.exitCode = status;
868
+ return;
869
+ }
870
+ logger.success("\u5B89\u88C5\u5B8C\u6210 \u2014\u2014 \u5B8C\u5168\u9000\u51FA DSH \u518D\u6253\u5F00\u5373\u53EF\u751F\u6548");
871
+ }
872
+ __name(dshInstallCommand, "dshInstallCommand");
873
+ var ACTIONS = {
874
+ init: "\u521B\u5EFA\u4E00\u4E2A DSH \u63D2\u4EF6\u9879\u76EE",
875
+ dev: "\u672C\u5730\u9884\u89C8\uFF08\u6D4F\u89C8\u5668\u91CC\u770B\u9762\u677F\uFF0C\u4E0D\u7528\u88C5\u8FDB DSH\uFF09",
876
+ build: "\u6784\u5EFA lib/{index,client}.js",
877
+ check: "\u88C5\u524D\u4E00\u81F4\u6027\u6821\u9A8C",
878
+ install: "\u628A\u63D2\u4EF6\u88C5\u8FDB DSH profile"
879
+ };
880
+ async function dshCommand(action, target, options) {
881
+ switch (action) {
882
+ case "init":
883
+ case "create":
884
+ await dshInitCommand(target, options);
885
+ return;
886
+ case "dev":
887
+ await dshDevCommand(options);
888
+ return;
889
+ case "build":
890
+ await dshBuildCommand();
891
+ return;
892
+ case "check":
893
+ dshCheckCommand();
894
+ return;
895
+ case "install":
896
+ dshInstallCommand(options);
897
+ return;
898
+ default:
899
+ logger.error(`\u672A\u77E5\u5B50\u547D\u4EE4: ${action ?? "(\u7A7A)"}`);
900
+ console.log("\n \u53EF\u7528\u5B50\u547D\u4EE4\uFF1A");
901
+ for (const [name, description] of Object.entries(ACTIONS)) {
902
+ console.log(` vobs dsh ${name.padEnd(8)} ${description}`);
903
+ }
904
+ process.exitCode = 1;
905
+ }
906
+ }
907
+ __name(dshCommand, "dshCommand");
908
+
377
909
  // packages/cli/src/banner.ts
378
910
  var BANNER_LINE1 = "\u{1D5E9}\u{1D5E2}\u{1D5D5}\u{1D5E6} \u{1D5D6}\u{1D5DF}\u{1D5DC} \u{1D603}\u{1D7ED}.\u{1D7EC}";
379
911
  var BANNER_TAGLINE = "Signals First \xB7 Zero Re-renders \xB7 Ultra Lightweight";
@@ -450,6 +982,20 @@ function createCLI() {
450
982
  dev: options.dev
451
983
  });
452
984
  });
985
+ 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) => {
986
+ await dshCommand(action, target, {
987
+ dir: options.dir,
988
+ pm: options.pm,
989
+ profile: options.profile,
990
+ spec: options.spec,
991
+ repo: options.repo,
992
+ tag: options.tag,
993
+ subpath: options.subpath,
994
+ from: options.from,
995
+ dry: options.dry === true,
996
+ port: options.port === void 0 ? void 0 : Number(options.port)
997
+ });
998
+ });
453
999
  cli.command("logo", "Show the vobs CLI logo and version info").action(() => {
454
1000
  showLogo();
455
1001
  });
@@ -463,12 +1009,12 @@ function createCLI() {
463
1009
  __name(createCLI, "createCLI");
464
1010
 
465
1011
  // packages/cli/src/repl.ts
466
- var import_promises = require("readline/promises");
1012
+ var import_promises2 = require("readline/promises");
467
1013
  var import_node_process = require("process");
468
1014
  var import_picocolors2 = __toESM(require("picocolors"), 1);
469
1015
  async function startRepl() {
470
1016
  showLogo();
471
- const rl = (0, import_promises.createInterface)({
1017
+ const rl = (0, import_promises2.createInterface)({
472
1018
  input: import_node_process.stdin,
473
1019
  output: import_node_process.stdout,
474
1020
  prompt: ` ${import_picocolors2.default.magenta("\u276F")} `,