@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
@@ -0,0 +1,638 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // packages/cli/src/commands/dsh.ts
5
+ import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
6
+ import { readFile } from "fs/promises";
7
+ import { execSync as execSync2, spawnSync } from "child_process";
8
+ import { createServer } from "http";
9
+ import { createRequire } from "module";
10
+ import { isAbsolute, basename, dirname as dirname2, join, relative, resolve as resolve3 } from "path";
11
+ import * as p from "@clack/prompts";
12
+
13
+ // packages/cli/src/utils/logger.ts
14
+ import pc from "picocolors";
15
+ function timestamp() {
16
+ return pc.dim(`[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}]`);
17
+ }
18
+ __name(timestamp, "timestamp");
19
+ function info(msg) {
20
+ console.log(`${timestamp()} ${pc.cyan("\u2139")} ${msg}`);
21
+ }
22
+ __name(info, "info");
23
+ function success(msg) {
24
+ console.log(`${timestamp()} ${pc.green("\u2714")} ${msg}`);
25
+ }
26
+ __name(success, "success");
27
+ function warn(msg) {
28
+ console.log(`${timestamp()} ${pc.yellow("\u26A0")} ${msg}`);
29
+ }
30
+ __name(warn, "warn");
31
+ function error(msg) {
32
+ console.error(`${timestamp()} ${pc.red("\u2716")} ${msg}`);
33
+ }
34
+ __name(error, "error");
35
+ function step(msg) {
36
+ console.log(`
37
+ ${pc.bold(pc.cyan(msg))}`);
38
+ }
39
+ __name(step, "step");
40
+ var logger = { info, success, warn, error, step };
41
+
42
+ // packages/cli/src/utils/file.ts
43
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs";
44
+ import { resolve, dirname } from "path";
45
+ import { fileURLToPath } from "url";
46
+ import Handlebars from "handlebars";
47
+ var __dirname = dirname(fileURLToPath(import.meta.url));
48
+ var TEMPLATES_ROOT = resolve(__dirname, "..", "templates");
49
+ function renderTemplate(templatePath, context) {
50
+ const source = readFileSync(templatePath, "utf-8");
51
+ const template = Handlebars.compile(source);
52
+ return template(context);
53
+ }
54
+ __name(renderTemplate, "renderTemplate");
55
+ function writeFile(dir, filename, content) {
56
+ const filePath = resolve(dir, filename);
57
+ mkdirSync(dirname(filePath), { recursive: true });
58
+ writeFileSync(filePath, content, "utf-8");
59
+ }
60
+ __name(writeFile, "writeFile");
61
+ function ensureDir(dir) {
62
+ if (!existsSync(dir)) {
63
+ mkdirSync(dir, { recursive: true });
64
+ }
65
+ }
66
+ __name(ensureDir, "ensureDir");
67
+ async function copyDirRecursive(srcDir, destDir, context) {
68
+ const { readdirSync } = await import("fs");
69
+ const { join: join2 } = await import("path");
70
+ const entries = readdirSync(srcDir, { withFileTypes: true });
71
+ for (const entry of entries) {
72
+ const srcPath = join2(srcDir, entry.name);
73
+ const isHbs = entry.name.endsWith(".hbs");
74
+ const destName = isHbs ? entry.name.slice(0, -4) : entry.name;
75
+ const destPath = join2(destDir, destName);
76
+ if (entry.isDirectory()) {
77
+ ensureDir(destPath);
78
+ await copyDirRecursive(srcPath, destPath, context);
79
+ } else if (isHbs) {
80
+ const content = renderTemplate(srcPath, context);
81
+ writeFile(destDir, destName, content);
82
+ } else {
83
+ const content = readFileSync(srcPath, "utf-8");
84
+ writeFile(destDir, destName, content);
85
+ }
86
+ }
87
+ }
88
+ __name(copyDirRecursive, "copyDirRecursive");
89
+ async function scaffoldProject(targetDir, context, template = "basic") {
90
+ const templateDir = resolve(TEMPLATES_ROOT, template);
91
+ if (!existsSync(templateDir)) {
92
+ throw new Error(`\u6A21\u677F\u4E0D\u5B58\u5728: ${template}\uFF08\u53EF\u7528\u6A21\u677F\u89C1 ${TEMPLATES_ROOT}\uFF09`);
93
+ }
94
+ ensureDir(targetDir);
95
+ await copyDirRecursive(templateDir, targetDir, context);
96
+ }
97
+ __name(scaffoldProject, "scaffoldProject");
98
+
99
+ // packages/cli/src/utils/pm.ts
100
+ import { existsSync as existsSync2 } from "fs";
101
+ import { resolve as resolve2 } from "path";
102
+ import { execSync } from "child_process";
103
+ function installDependencies(targetDir, pm) {
104
+ const cmd = pm === "yarn" ? "yarn" : `${pm} install`;
105
+ execSync(cmd, { cwd: targetDir, stdio: "inherit" });
106
+ }
107
+ __name(installDependencies, "installDependencies");
108
+
109
+ // packages/cli/src/commands/dsh.ts
110
+ var PLATFORM_MODULES = ["react", "react-dom"];
111
+ var vobsVersion = /* @__PURE__ */ __name(() => {
112
+ try {
113
+ const manifest = JSON.parse(
114
+ readFileSync2(new URL("../../package.json", import.meta.url), "utf8")
115
+ );
116
+ return manifest.version ?? "1.7.5";
117
+ } catch {
118
+ return "1.7.5";
119
+ }
120
+ }, "vobsVersion");
121
+ function toRowId(packageName) {
122
+ return packageName.replace(/^@[^/]+\//u, "");
123
+ }
124
+ __name(toRowId, "toRowId");
125
+ async function dshInitCommand(target, options) {
126
+ const name = target ?? await p.text({
127
+ message: "\u63D2\u4EF6\u5305\u540D\uFF08npm \u5305\u540D\uFF0C\u5C0F\u5199\uFF09:",
128
+ placeholder: "dsh-plugin-my-panel",
129
+ 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")
130
+ });
131
+ if (p.isCancel(name)) {
132
+ p.cancel("\u5DF2\u53D6\u6D88");
133
+ return;
134
+ }
135
+ const packageManager = options.pm ?? await p.select({
136
+ message: "\u5305\u7BA1\u7406\u5668:",
137
+ options: [
138
+ { value: "pnpm", label: "pnpm" },
139
+ { value: "npm", label: "npm" }
140
+ ]
141
+ });
142
+ if (p.isCancel(packageManager)) {
143
+ p.cancel("\u5DF2\u53D6\u6D88");
144
+ return;
145
+ }
146
+ const targetDir = options.dir !== void 0 ? resolve3(options.dir) : resolve3(process.cwd(), name);
147
+ const rowId = toRowId(name);
148
+ const displayName = rowId.replace(/^dsh-plugin-/u, "").split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
149
+ logger.step(`\u521B\u5EFA DSH \u63D2\u4EF6\u9879\u76EE ${name} \u2026`);
150
+ await scaffoldProject(
151
+ targetDir,
152
+ { packageName: name, rowId, displayName, vobsVersion: vobsVersion() },
153
+ "dsh-plugin"
154
+ );
155
+ ensureDir(targetDir);
156
+ writeFileSync2(
157
+ resolve3(targetDir, ".gitignore"),
158
+ ["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"),
159
+ "utf8"
160
+ );
161
+ logger.success("\u9879\u76EE\u5DF2\u751F\u6210");
162
+ logger.step("\u5B89\u88C5\u4F9D\u8D56 \u2026");
163
+ try {
164
+ installDependencies(targetDir, packageManager);
165
+ logger.success("\u4F9D\u8D56\u5DF2\u5B89\u88C5");
166
+ } catch {
167
+ logger.warn(`\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u6267\u884C ${packageManager} install`);
168
+ }
169
+ logger.step("\u4E0B\u4E00\u6B65");
170
+ console.log(`
171
+ cd ${name}
172
+ ${packageManager} run dev # \u672C\u5730\u9884\u89C8\uFF0C\u4E0D\u7528\u88C5\u8FDB DSH
173
+ ${packageManager} run build # \u4EA7\u51FA lib/{index,client}.js
174
+
175
+ # \u63D0\u4EA4\u4EA7\u7269\u5E76\u6253 tag \u4E4B\u540E\uFF0C\u5728 DSH \u63D2\u4EF6\u9875\u586B\uFF1A
176
+ github:<owner>/<repo>#v0.1.0&path:/<\u672C\u5305\u5728\u4ED3\u5E93\u4E2D\u7684\u8DEF\u5F84>
177
+ `);
178
+ }
179
+ __name(dshInitCommand, "dshInitCommand");
180
+ async function dshBuildCommand() {
181
+ const projectDir = process.cwd();
182
+ const configFile = resolve3(projectDir, "vite.config.ts");
183
+ if (!existsSync3(configFile)) {
184
+ logger.error("\u5F53\u524D\u76EE\u5F55\u6CA1\u6709 vite.config.ts\uFF0C\u8BF7\u5728\u63D2\u4EF6\u9879\u76EE\u6839\u76EE\u5F55\u8FD0\u884C\u3002");
185
+ process.exitCode = 1;
186
+ return;
187
+ }
188
+ const manifest = readManifest(projectDir);
189
+ if (manifest === void 0) {
190
+ logger.error("\u8BFB\u4E0D\u5230 package.json\u3002");
191
+ process.exitCode = 1;
192
+ return;
193
+ }
194
+ const hostEntry = resolveExport(manifest, ".");
195
+ if (hostEntry === void 0) {
196
+ logger.error('package.json \u7684 exports \u91CC\u6CA1\u6709 "."\uFF0CDSH \u52A0\u8F7D\u4E0D\u5230 Host \u4FA7\u63D2\u4EF6\u3002');
197
+ process.exitCode = 1;
198
+ return;
199
+ }
200
+ const { build } = await import("vite");
201
+ logger.info("\u6784\u5EFA\u5BA2\u6237\u7AEF\u4EA7\u7269 \u2026");
202
+ await build({ configFile, mode: "production" });
203
+ logger.info("\u6784\u5EFA Host \u4EA7\u7269 \u2026");
204
+ const hostTarget = resolve3(projectDir, hostEntry.replace(/^\.\//u, ""));
205
+ const hostEntrySource = resolve3(projectDir, "src", "host", "index.ts");
206
+ if (!existsSync3(hostEntrySource)) {
207
+ logger.warn(`\u6CA1\u6709\u627E\u5230 ${hostEntrySource}\uFF0C\u8DF3\u8FC7 Host \u6784\u5EFA\u3002`);
208
+ return;
209
+ }
210
+ await build({
211
+ configFile: false,
212
+ root: projectDir,
213
+ logLevel: "warn",
214
+ build: {
215
+ outDir: relative(projectDir, dirname2(hostTarget)) || ".",
216
+ emptyOutDir: false,
217
+ target: "es2022",
218
+ minify: false,
219
+ sourcemap: false,
220
+ lib: {
221
+ entry: hostEntrySource,
222
+ formats: ["es"],
223
+ fileName: /* @__PURE__ */ __name(() => basename(hostTarget), "fileName")
224
+ }
225
+ }
226
+ });
227
+ logger.success("\u6784\u5EFA\u5B8C\u6210 \u2192 \u5BA2\u6237\u7AEF\u4E0E Host \u4EA7\u7269\u90FD\u5DF2\u5C31\u4F4D");
228
+ }
229
+ __name(dshBuildCommand, "dshBuildCommand");
230
+ function resolveExport(manifest, key) {
231
+ const exportsField = manifest.exports ?? {};
232
+ const entry = exportsField[key];
233
+ if (typeof entry === "string") return entry;
234
+ if (typeof entry === "object" && entry !== null) {
235
+ const record = entry;
236
+ for (const condition of ["default", "import", "require"]) {
237
+ const value = record[condition];
238
+ if (typeof value === "string") return value;
239
+ }
240
+ }
241
+ return void 0;
242
+ }
243
+ __name(resolveExport, "resolveExport");
244
+ function buildPreviewHtml(options) {
245
+ const name = JSON.stringify(options.packageName).replace(/</gu, "\\u003c");
246
+ const title = (options.title ?? options.packageName).replace(/[<>&]/gu, "");
247
+ return `<!doctype html>
248
+ <html lang="zh-CN">
249
+ <head>
250
+ <meta charset="utf-8">
251
+ <meta name="viewport" content="width=device-width, initial-scale=1">
252
+ <title>vobs preview \xB7 ${title}</title>
253
+ </head>
254
+ <body>
255
+ <div id="root"></div>
256
+
257
+ <!-- 1. \u5148\u88C5\u57AB\u7247\uFF1A\u5FC5\u987B\u5728\u63D2\u4EF6 bundle \u4E4B\u524D\uFF0C\u6355\u83B7\u5B83\u7684 factory \u6CE8\u518C -->
258
+ <script>
259
+ window.__VOBS_DSH_PREVIEW__ = { factories: new Map() };
260
+ window.__ModuleLoader__ = {
261
+ load: function (entry) { window.__VOBS_DSH_PREVIEW__.factories.set(entry.id, entry.factory); }
262
+ };
263
+ </script>
264
+
265
+ <!-- 2. \u63D2\u4EF6\u4EA7\u7269\uFF1A\u5B83\u53EA\u6CE8\u518C factory\uFF0C\u4E0D\u4EA7\u751F\u526F\u4F5C\u7528 -->
266
+ <script src="/client.js"></script>
267
+
268
+ <!-- 3. \u542F\u52A8\u9884\u89C8\u5916\u58F3 -->
269
+ <script type="module">
270
+ import { startPreview } from '/preview.js';
271
+ window.__VOBS_PREVIEW__ = startPreview({
272
+ container: document.getElementById('root'),
273
+ packageName: ${name}
274
+ });
275
+ </script>
276
+
277
+ <!-- 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 -->
278
+ <script>
279
+ if (!location.search.includes('static')) {
280
+ new EventSource('/events').addEventListener('reload', function () { location.reload(); });
281
+ }
282
+ </script>
283
+ </body>
284
+ </html>
285
+ `;
286
+ }
287
+ __name(buildPreviewHtml, "buildPreviewHtml");
288
+ async function dshDevCommand(options) {
289
+ const projectDir = process.cwd();
290
+ const manifest = readManifest(projectDir);
291
+ if (manifest === void 0) {
292
+ logger.error("\u5F53\u524D\u76EE\u5F55\u6CA1\u6709\u53EF\u8BFB\u7684 package.json\u3002");
293
+ process.exitCode = 1;
294
+ return;
295
+ }
296
+ if (readManifest(projectDir)?.dsh === void 0) {
297
+ logger.error("\u8FD9\u4E0D\u662F\u4E00\u4E2A DSH \u63D2\u4EF6\u9879\u76EE\uFF08package.json \u91CC\u6CA1\u6709 dsh \u5B57\u6BB5\uFF09\u3002");
298
+ process.exitCode = 1;
299
+ return;
300
+ }
301
+ const packageName = typeof manifest.name === "string" ? manifest.name : "dsh-plugin";
302
+ const clientEntry = resolveExport(manifest, "./client");
303
+ if (clientEntry === void 0) {
304
+ logger.error('package.json \u7684 exports \u91CC\u6CA1\u6709 "./client"\uFF0C\u9875\u9762\u62FF\u4E0D\u5230\u5BA2\u6237\u7AEF bundle\u3002');
305
+ process.exitCode = 1;
306
+ return;
307
+ }
308
+ const clientFile = resolve3(projectDir, clientEntry.replace(/^\.\//u, ""));
309
+ let previewFile;
310
+ try {
311
+ const projectRequire = createRequire(join(projectDir, "package.json"));
312
+ let packageRoot;
313
+ try {
314
+ packageRoot = dirname2(projectRequire.resolve("@vobs/dsh/package.json"));
315
+ } catch {
316
+ packageRoot = dirname2(dirname2(projectRequire.resolve("@vobs/dsh")));
317
+ }
318
+ const candidate = join(packageRoot, "dist", "preview.js");
319
+ previewFile = existsSync3(candidate) ? candidate : void 0;
320
+ } catch {
321
+ previewFile = void 0;
322
+ }
323
+ if (previewFile === void 0) {
324
+ 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");
325
+ process.exitCode = 1;
326
+ return;
327
+ }
328
+ const port = options.port ?? 5199;
329
+ const clients = /* @__PURE__ */ new Set();
330
+ const broadcast = /* @__PURE__ */ __name((event) => {
331
+ for (const client of clients) client.write(`event: ${event}
332
+ data: 1
333
+
334
+ `);
335
+ }, "broadcast");
336
+ logger.info("\u6784\u5EFA\u4EA7\u7269 \u2026");
337
+ const { build } = await import("vite");
338
+ const configFile = resolve3(projectDir, "vite.config.ts");
339
+ let buildError;
340
+ try {
341
+ const watcher = await build({
342
+ configFile,
343
+ mode: "development",
344
+ logLevel: "warn",
345
+ build: { watch: {} }
346
+ });
347
+ watcher.on("event", (event) => {
348
+ if (event.code === "END") {
349
+ buildError = void 0;
350
+ logger.success("\u91CD\u65B0\u6784\u5EFA\u5B8C\u6210");
351
+ broadcast("reload");
352
+ } else if (event.code === "ERROR") {
353
+ buildError = event.error?.message ?? "\u6784\u5EFA\u5931\u8D25";
354
+ logger.error(buildError);
355
+ }
356
+ });
357
+ process.on("SIGINT", () => {
358
+ void watcher.close().then(() => process.exit(0));
359
+ });
360
+ } catch (error2) {
361
+ logger.error(`\u6784\u5EFA\u5931\u8D25\uFF1A${error2 instanceof Error ? error2.message : String(error2)}`);
362
+ process.exitCode = 1;
363
+ return;
364
+ }
365
+ const server = createServer((request, response) => {
366
+ const url = (request.url ?? "/").split("?")[0];
367
+ if (url === "/events") {
368
+ response.writeHead(200, {
369
+ "content-type": "text/event-stream",
370
+ "cache-control": "no-store",
371
+ connection: "keep-alive"
372
+ });
373
+ response.write(": connected\n\n");
374
+ clients.add(response);
375
+ request.on("close", () => clients.delete(response));
376
+ return;
377
+ }
378
+ const send = /* @__PURE__ */ __name((body, type) => {
379
+ response.writeHead(200, { "content-type": type, "cache-control": "no-store" });
380
+ response.end(body);
381
+ }, "send");
382
+ if (url === "/") {
383
+ send(buildPreviewHtml({ packageName }), "text/html; charset=utf-8");
384
+ return;
385
+ }
386
+ if (url === "/preview.js") {
387
+ void readFile(previewFile).then((body) => send(body, "text/javascript; charset=utf-8"));
388
+ return;
389
+ }
390
+ if (url === "/client.js") {
391
+ if (!existsSync3(clientFile)) {
392
+ response.writeHead(503, { "content-type": "text/plain; charset=utf-8" });
393
+ response.end(`\u8FD8\u6CA1\u6709\u4EA7\u7269\uFF1A${clientEntry}
394
+ ${buildError ?? ""}`);
395
+ return;
396
+ }
397
+ void readFile(clientFile).then((body) => send(body, "text/javascript; charset=utf-8"));
398
+ return;
399
+ }
400
+ response.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
401
+ response.end("not found");
402
+ });
403
+ await new Promise((resolveListen) => {
404
+ server.listen(port, "127.0.0.1", resolveListen);
405
+ });
406
+ logger.success(`\u9884\u89C8\u5DF2\u5C31\u7EEA\uFF1Ahttp://127.0.0.1:${port}/`);
407
+ console.log("\n \u6539\u4EE3\u7801\u4F1A\u81EA\u52A8\u91CD\u5EFA\u5E76\u5237\u65B0\u9875\u9762\uFF1BCtrl+C \u9000\u51FA\u3002\n");
408
+ }
409
+ __name(dshDevCommand, "dshDevCommand");
410
+ function readManifest(dir) {
411
+ try {
412
+ return JSON.parse(readFileSync2(resolve3(dir, "package.json"), "utf8"));
413
+ } catch {
414
+ return void 0;
415
+ }
416
+ }
417
+ __name(readManifest, "readManifest");
418
+ function collectIssues(dir) {
419
+ const result = { errors: [], warnings: [], passed: [] };
420
+ const manifest = readManifest(dir);
421
+ if (manifest === void 0) {
422
+ result.errors.push("\u8BFB\u4E0D\u5230 package.json\uFF08JSON \u8BED\u6CD5\u9519\u8BEF\u6216\u6587\u4EF6\u7F3A\u5931\uFF09");
423
+ return result;
424
+ }
425
+ const name = typeof manifest.name === "string" ? manifest.name : "";
426
+ if (name === "") result.errors.push("package.json \u7F3A\u5C11 name");
427
+ else result.passed.push(`\u5305\u540D ${name}`);
428
+ const dsh = manifest.dsh ?? {};
429
+ const bundle = dsh.bundle ?? {};
430
+ const client = dsh.client ?? {};
431
+ if (typeof bundle.patch !== "string") {
432
+ result.errors.push("\u7F3A\u5C11 dsh.bundle.patch \u2014\u2014 DSH \u4E0D\u4F1A\u628A\u8FD9\u4E2A\u5305\u5F53\u4F5C\u7EC4\u5408\u5305\uFF08bundle\uFF09");
433
+ } else {
434
+ const patchPath = resolve3(dir, bundle.patch.replace(/^\.\//u, ""));
435
+ if (!existsSync3(patchPath)) {
436
+ result.errors.push(`dsh.bundle.patch \u6307\u5411\u7684 ${bundle.patch} \u4E0D\u5B58\u5728`);
437
+ } else {
438
+ const text2 = readFileSync2(patchPath, "utf8");
439
+ if (!text2.includes("insert:")) result.errors.push("cordis.patch.yml \u91CC\u6CA1\u6709 insert: \u6BB5\u843D\uFF0C\u63D2\u4EF6\u884C\u4E0D\u4F1A\u8FDB\u7EC4\u5408\u6811");
440
+ else if (name !== "" && !text2.includes(name)) {
441
+ result.warnings.push(`cordis.patch.yml \u91CC\u6CA1\u6709\u51FA\u73B0\u5305\u540D ${name}\uFF0C\u786E\u8BA4 insert \u7684 name \u5199\u5BF9\u4E86`);
442
+ } else result.passed.push("cordis.patch.yml \u4F1A\u63D2\u5165\u672C\u5305\u7684\u884C");
443
+ }
444
+ }
445
+ if (client.platform !== "web") {
446
+ 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");
447
+ } else result.passed.push("dsh.client.platform = web");
448
+ const exportsField = manifest.exports ?? {};
449
+ const hostEntry = exportsField["."];
450
+ const clientEntry = exportsField["./client"];
451
+ if (typeof hostEntry !== "string") result.errors.push('exports["."] \u672A\u58F0\u660E \u2014\u2014 DSH \u52A0\u8F7D\u4E0D\u5230 Host \u4FA7\u63D2\u4EF6');
452
+ else if (!existsSync3(resolve3(dir, hostEntry.replace(/^\.\//u, "")))) {
453
+ result.errors.push(`exports["."] \u6307\u5411\u7684 ${hostEntry} \u4E0D\u5B58\u5728\uFF0C\u5148\u6784\u5EFA`);
454
+ } else result.passed.push("Host \u5165\u53E3\u5B58\u5728");
455
+ if (typeof clientEntry !== "string") result.errors.push('exports["./client"] \u672A\u58F0\u660E \u2014\u2014 \u9875\u9762\u62FF\u4E0D\u5230\u5BA2\u6237\u7AEF bundle');
456
+ const scripts = manifest.scripts ?? {};
457
+ if (scripts.prepare !== void 0 || scripts.postinstall !== void 0) {
458
+ 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");
459
+ } else result.passed.push("\u6CA1\u6709\u5B89\u88C5\u671F\u751F\u547D\u5468\u671F\u94A9\u5B50");
460
+ const dependencyText = JSON.stringify({
461
+ dependencies: manifest.dependencies,
462
+ peerDependencies: manifest.peerDependencies,
463
+ devDependencies: manifest.devDependencies
464
+ });
465
+ if (dependencyText.includes("workspace:")) {
466
+ 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");
467
+ } else result.passed.push("\u6CA1\u6709 workspace: \u534F\u8BAE\u4F9D\u8D56");
468
+ if (typeof clientEntry === "string") {
469
+ const clientPath = resolve3(dir, clientEntry.replace(/^\.\//u, ""));
470
+ if (!existsSync3(clientPath)) {
471
+ result.errors.push(`\u5BA2\u6237\u7AEF\u4EA7\u7269 ${clientEntry} \u4E0D\u5B58\u5728\uFF0C\u5148\u8FD0\u884C\u6784\u5EFA`);
472
+ } else {
473
+ const code = readFileSync2(clientPath, "utf8");
474
+ const loads = (code.match(/__ModuleLoader__\.load\(/gu) ?? []).length;
475
+ 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`);
476
+ else result.passed.push("\u4EA7\u7269\u5F62\u6001\u662F DSH \u5BA2\u6237\u7AEF\u6A21\u5757\u534F\u8BAE");
477
+ 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");
478
+ const requires = [...code.matchAll(/require\((['"])([^'"]+)\1\)/gu)].map((match) => match[2] ?? "");
479
+ const foreign = requires.filter((id) => !PLATFORM_MODULES.includes(id) && !id.startsWith("@deepseek-ai/"));
480
+ if (foreign.length > 0) {
481
+ 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`);
482
+ } else if (requires.length > 0) {
483
+ result.passed.push(`\u4EA7\u7269\u53EA require \u5E73\u53F0\u6A21\u5757\uFF08${[...new Set(requires)].join(", ")}\uFF09`);
484
+ }
485
+ if (name !== "" && !code.includes(`"${name}"`) && !code.includes(`'${name}'`)) {
486
+ result.warnings.push(`\u4EA7\u7269\u91CC\u7684\u6A21\u5757 id \u4E0E\u5305\u540D ${name} \u4E0D\u4E00\u81F4\uFF0C\u68C0\u67E5 dshBundle({ id })`);
487
+ }
488
+ }
489
+ }
490
+ return result;
491
+ }
492
+ __name(collectIssues, "collectIssues");
493
+ function dshCheckCommand() {
494
+ const dir = process.cwd();
495
+ const result = collectIssues(dir);
496
+ logger.step("DSH \u63D2\u4EF6\u88C5\u524D\u6821\u9A8C");
497
+ for (const item of result.passed) console.log(` \u2714 ${item}`);
498
+ for (const item of result.warnings) console.log(` \u26A0 ${item}`);
499
+ for (const item of result.errors) console.log(` \u2716 ${item}`);
500
+ if (result.errors.length > 0) {
501
+ logger.error(`${result.errors.length} \u9879\u4E0D\u901A\u8FC7\uFF0C\u88C5\u8FDB DSH \u540E\u4E0D\u4F1A\u6B63\u5E38\u5DE5\u4F5C\u3002`);
502
+ process.exitCode = 1;
503
+ return;
504
+ }
505
+ logger.success(`\u5168\u90E8\u901A\u8FC7\uFF08${result.passed.length} \u9879${result.warnings.length > 0 ? `\uFF0C${result.warnings.length} \u6761\u8B66\u544A` : ""}\uFF09`);
506
+ }
507
+ __name(dshCheckCommand, "dshCheckCommand");
508
+ function readPnpmVersion() {
509
+ try {
510
+ return execSync2("pnpm --version", { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
511
+ } catch {
512
+ return void 0;
513
+ }
514
+ }
515
+ __name(readPnpmVersion, "readPnpmVersion");
516
+ var majorOf = /* @__PURE__ */ __name((version) => {
517
+ const major = Number.parseInt((version ?? "").split(".")[0] ?? "", 10);
518
+ return Number.isFinite(major) ? major : 0;
519
+ }, "majorOf");
520
+ function buildInstallSpec(options) {
521
+ if (options.spec !== void 0) return { spec: options.spec };
522
+ if (options.from !== void 0) {
523
+ const target = resolve3(options.from);
524
+ if (!existsSync3(target)) return { error: `--from \u6307\u5411\u7684\u8DEF\u5F84\u4E0D\u5B58\u5728\uFF1A${target}` };
525
+ return { spec: target };
526
+ }
527
+ if (options.repo !== void 0) {
528
+ const ref = options.tag !== void 0 && options.tag !== "" ? `#${options.tag}` : "";
529
+ const sub = options.subpath !== void 0 && options.subpath !== "" ? `${ref === "" ? "#" : "&"}path:${options.subpath}` : "";
530
+ return { spec: `github:${options.repo}${ref}${sub}` };
531
+ }
532
+ return { error: "\u9700\u8981 --spec\u3001--from \u6216 --repo \u4E4B\u4E00\u6765\u6307\u5B9A\u5B89\u88C5\u6765\u6E90\u3002" };
533
+ }
534
+ __name(buildInstallSpec, "buildInstallSpec");
535
+ var CMD_NEEDS_QUOTE = /[\s&|<>^()"']/u;
536
+ function quoteForCmd(part) {
537
+ return CMD_NEEDS_QUOTE.test(part) ? `"${part.replace(/"/gu, '""')}"` : part;
538
+ }
539
+ __name(quoteForCmd, "quoteForCmd");
540
+ function buildShellCommand(exe, args) {
541
+ return [exe, ...args].map(quoteForCmd).join(" ");
542
+ }
543
+ __name(buildShellCommand, "buildShellCommand");
544
+ function spawnDsh(args, dry) {
545
+ if (dry) {
546
+ console.log(`
547
+ ${buildShellCommand("dsh", args)}
548
+ `);
549
+ return 0;
550
+ }
551
+ if (process.platform === "win32") {
552
+ const result2 = spawnSync(buildShellCommand("dsh", args), { stdio: "inherit", shell: true });
553
+ return result2.status ?? 1;
554
+ }
555
+ const result = spawnSync("dsh", args, { stdio: "inherit" });
556
+ return result.status ?? 1;
557
+ }
558
+ __name(spawnDsh, "spawnDsh");
559
+ function dshInstallCommand(options) {
560
+ const profile = options.profile ?? "desktop";
561
+ const { spec, error: error2 } = buildInstallSpec(options);
562
+ if (spec === void 0) {
563
+ logger.error(error2 ?? "\u672A\u77E5\u9519\u8BEF");
564
+ process.exitCode = 1;
565
+ return;
566
+ }
567
+ const usesSubpath = spec.includes("path:");
568
+ const pnpmVersion = readPnpmVersion();
569
+ if (usesSubpath && pnpmVersion !== void 0 && majorOf(pnpmVersion) < 11) {
570
+ logger.warn(
571
+ `\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`
572
+ );
573
+ }
574
+ if (usesSubpath && process.platform === "win32") {
575
+ 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");
576
+ }
577
+ logger.step(`\u5B89\u88C5\u5230 profile\u300C${profile}\u300D`);
578
+ console.log(` spec: ${spec}`);
579
+ if (!isAbsolute(spec) && !spec.startsWith("github:") && !spec.startsWith("git+") && !spec.startsWith("http")) {
580
+ 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");
581
+ }
582
+ const status = spawnDsh(["plugin", "--profile", profile, "add", spec], options.dry === true);
583
+ if (options.dry === true) {
584
+ logger.info("dry run\uFF1A\u4EE5\u4E0A\u547D\u4EE4\u6CA1\u6709\u6267\u884C\u3002");
585
+ return;
586
+ }
587
+ if (status !== 0) {
588
+ logger.error(`\u5B89\u88C5\u5931\u8D25\uFF08\u9000\u51FA\u7801 ${status}\uFF09\u3002\u8BCA\u65AD\u65E5\u5FD7\u5728 ~/.dsh/profiles/${profile}/.plugin-manager/logs/`);
589
+ process.exitCode = status;
590
+ return;
591
+ }
592
+ logger.success("\u5B89\u88C5\u5B8C\u6210 \u2014\u2014 \u5B8C\u5168\u9000\u51FA DSH \u518D\u6253\u5F00\u5373\u53EF\u751F\u6548");
593
+ }
594
+ __name(dshInstallCommand, "dshInstallCommand");
595
+ var ACTIONS = {
596
+ init: "\u521B\u5EFA\u4E00\u4E2A DSH \u63D2\u4EF6\u9879\u76EE",
597
+ dev: "\u672C\u5730\u9884\u89C8\uFF08\u6D4F\u89C8\u5668\u91CC\u770B\u9762\u677F\uFF0C\u4E0D\u7528\u88C5\u8FDB DSH\uFF09",
598
+ build: "\u6784\u5EFA lib/{index,client}.js",
599
+ check: "\u88C5\u524D\u4E00\u81F4\u6027\u6821\u9A8C",
600
+ install: "\u628A\u63D2\u4EF6\u88C5\u8FDB DSH profile"
601
+ };
602
+ async function dshCommand(action, target, options) {
603
+ switch (action) {
604
+ case "init":
605
+ case "create":
606
+ await dshInitCommand(target, options);
607
+ return;
608
+ case "dev":
609
+ await dshDevCommand(options);
610
+ return;
611
+ case "build":
612
+ await dshBuildCommand();
613
+ return;
614
+ case "check":
615
+ dshCheckCommand();
616
+ return;
617
+ case "install":
618
+ dshInstallCommand(options);
619
+ return;
620
+ default:
621
+ logger.error(`\u672A\u77E5\u5B50\u547D\u4EE4: ${action ?? "(\u7A7A)"}`);
622
+ console.log("\n \u53EF\u7528\u5B50\u547D\u4EE4\uFF1A");
623
+ for (const [name, description] of Object.entries(ACTIONS)) {
624
+ console.log(` vobs dsh ${name.padEnd(8)} ${description}`);
625
+ }
626
+ process.exitCode = 1;
627
+ }
628
+ }
629
+ __name(dshCommand, "dshCommand");
630
+ export {
631
+ buildInstallSpec,
632
+ buildPreviewHtml,
633
+ buildShellCommand,
634
+ collectIssues,
635
+ dshCommand,
636
+ resolveExport
637
+ };
638
+ //# sourceMappingURL=dsh.js.map