@wot-ui/cli 0.0.1-beta.10 → 0.0.1-beta.11

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.
Binary file
@@ -1,10 +1,13 @@
1
1
  {
2
- "latest": "2.0.0-alpha.5",
2
+ "latest": "2.0.4",
3
3
  "supported": [
4
- "2.0.0-alpha.5"
4
+ "2.0.4"
5
5
  ],
6
6
  "aliases": {
7
- "v2": "2.0.0-alpha.5",
8
- "latest": "2.0.0-alpha.5"
7
+ "v2": "2.0.4",
8
+ "latest": "2.0.4"
9
+ },
10
+ "v2": {
11
+ "2.0": "2.0.4"
9
12
  }
10
13
  }
Binary file
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as resolveVersion, i as listComponents, n as lintProject, o as loadMetadataFile, r as findComponent, s as version, t as analyzeUsage } from "./scanner-_isnOGJK.mjs";
2
+ import { a as detectVersion, c as version, i as listComponents, n as lintProject, o as resolveVersion, r as findComponent, s as loadMetadataFile, t as analyzeUsage } from "./scanner-Dsl3i2de.mjs";
3
3
  import process from "node:process";
4
4
  import { Command } from "commander";
5
5
  import { existsSync, readFileSync } from "node:fs";
@@ -22,9 +22,12 @@ function addQueryOptions(command) {
22
22
  return command.option("--format <format>", "output format: text, json, markdown", "text").option("--version <version>", "target wot-ui version");
23
23
  }
24
24
  function normalizeQueryOptions(options) {
25
+ const format = options.format === "json" || options.format === "markdown" ? options.format : "text";
26
+ const info = detectVersion(typeof options.version === "string" ? options.version : void 0);
27
+ if (info.source === "fallback") process.stderr.write(`[wot] version not detected in project, falling back to ${info.version}\n`);
25
28
  return {
26
- format: options.format === "json" || options.format === "markdown" ? options.format : "text",
27
- version: typeof options.version === "string" ? options.version : void 0
29
+ format,
30
+ version: info.version
28
31
  };
29
32
  }
30
33
  function printError(message, format) {
@@ -321,7 +324,7 @@ function registerListCommand(program) {
321
324
  //#region src/commands/mcp.ts
322
325
  function registerMcpCommand(program) {
323
326
  program.command("mcp").description("Start the wot-ui MCP server").action(async () => {
324
- const { startMcpServer } = await import("./server-BLoIUV7u.mjs");
327
+ const { startMcpServer } = await import("./server-CbHpaCNz.mjs");
325
328
  await startMcpServer();
326
329
  });
327
330
  }
@@ -392,7 +395,7 @@ function registerUsageCommand(program) {
392
395
  //#region src/app.ts
393
396
  function createCliProgram() {
394
397
  const program = new Command();
395
- program.name("wot").description("wot-ui AI toolkit CLI").version(version);
398
+ program.name("wot").description("wot-ui AI toolkit CLI").version(version, "-V", "output the current version");
396
399
  registerListCommand(program);
397
400
  registerInfoCommand(program);
398
401
  registerDocCommand(program);
@@ -1,3 +1,4 @@
1
+ import process from "node:process";
1
2
  import { existsSync, readFileSync, readdirSync } from "node:fs";
2
3
  import { dirname, join, relative, resolve } from "node:path";
3
4
  import { fileURLToPath } from "node:url";
@@ -5,7 +6,7 @@ import { gunzipSync } from "node:zlib";
5
6
  import { parse } from "@vue/compiler-sfc";
6
7
 
7
8
  //#region package.json
8
- var version = "0.0.1-beta.10";
9
+ var version = "0.0.1-beta.11";
9
10
 
10
11
  //#endregion
11
12
  //#region src/data/loader.ts
@@ -39,14 +40,91 @@ function loadMetadataFile(versionKey) {
39
40
 
40
41
  //#endregion
41
42
  //#region src/data/version.ts
42
- const VERSION_KEY = "v2";
43
+ /** Strip semver range operators (^, ~, >=, >, <=, <, =, whitespace). */
44
+ function stripRange(ver) {
45
+ return ver.replace(/[\^~>=<\s]/g, "");
46
+ }
47
+ /**
48
+ * Returns all stable version strings for major key 'v2',
49
+ * sorted ascending by semver.
50
+ */
51
+ function stableV2Versions() {
52
+ const map = loadVersionsFile().v2 ?? {};
53
+ return Object.values(map).filter((v) => !v.includes("-")).sort((a, b) => {
54
+ const pa = a.split(".").map(Number);
55
+ const pb = b.split(".").map(Number);
56
+ for (let i = 0; i < 3; i++) {
57
+ const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
58
+ if (diff !== 0) return diff;
59
+ }
60
+ return 0;
61
+ });
62
+ }
63
+ /**
64
+ * Auto-detect the wot-ui version to use.
65
+ *
66
+ * Priority:
67
+ * 1. --version flag (flagVersion arg)
68
+ * 2. node_modules/@wot-ui/ui/package.json in cwd
69
+ * 3. package.json dependencies[@wot-ui/ui] in cwd
70
+ * 4. Fallback to latest stable version from versions.json
71
+ */
72
+ function detectVersion(flagVersion, cwd) {
73
+ const dir = cwd ?? process.cwd();
74
+ if (flagVersion) return {
75
+ version: flagVersion,
76
+ source: "flag"
77
+ };
78
+ const nmPath = join(dir, "node_modules", "@wot-ui", "ui", "package.json");
79
+ if (existsSync(nmPath)) try {
80
+ const pkg = JSON.parse(readFileSync(nmPath, "utf8"));
81
+ if (pkg.version) return {
82
+ version: pkg.version,
83
+ source: "node_modules"
84
+ };
85
+ } catch {}
86
+ const pkgPath = join(dir, "package.json");
87
+ if (existsSync(pkgPath)) try {
88
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
89
+ const depVersion = pkg.dependencies?.["@wot-ui/ui"] ?? pkg.devDependencies?.["@wot-ui/ui"] ?? pkg.peerDependencies?.["@wot-ui/ui"];
90
+ if (depVersion) return {
91
+ version: stripRange(depVersion),
92
+ source: "package.json"
93
+ };
94
+ } catch {}
95
+ return {
96
+ version: stableV2Versions().at(-1) ?? "2.0.0",
97
+ source: "fallback"
98
+ };
99
+ }
100
+ /**
101
+ * Resolve a version string (from detectVersion or CLI flag) to a data file key.
102
+ *
103
+ * Examples:
104
+ * undefined / 'v2' → 'v2' (major alias, data/v2.json)
105
+ * 'latest' → 'v2.0.4' (latest stable snapshot)
106
+ * '2.0' → 'v2.0.4' (minor → lookup in versions.json)
107
+ * '2.0.4' → 'v2.0.4' (exact patch)
108
+ * '2.0.0-alpha.5' → 'v2.0.0-alpha.5' (pre-release exact)
109
+ */
43
110
  function resolveVersion(requested) {
44
- const versions = loadVersionsFile();
45
- if (!requested) return VERSION_KEY;
111
+ if (!requested || requested === "v2") return "v2";
46
112
  const normalized = requested.trim();
47
- if (versions.aliases[normalized]) return VERSION_KEY;
48
- if (versions.supported.includes(normalized)) return VERSION_KEY;
49
- if (normalized === VERSION_KEY) return VERSION_KEY;
113
+ if (normalized === "latest") {
114
+ const latest = stableV2Versions().at(-1);
115
+ if (!latest) return "v2";
116
+ return `v${latest}`;
117
+ }
118
+ const map = loadVersionsFile().v2 ?? {};
119
+ if (/^\d+\.\d+$/.test(normalized)) {
120
+ const patch = map[normalized];
121
+ if (!patch) throw new Error(`Unsupported wot-ui version: ${requested}`);
122
+ return `v${patch}`;
123
+ }
124
+ if (/^\d+\.\d+\.\d+/.test(normalized)) {
125
+ if (normalized.split(".")[0] !== "2") throw new Error(`Unsupported wot-ui version: ${requested}`);
126
+ return `v${normalized}`;
127
+ }
50
128
  throw new Error(`Unsupported wot-ui version: ${requested}`);
51
129
  }
52
130
 
@@ -200,4 +278,4 @@ function lintProject(targetDir, version$1) {
200
278
  }
201
279
 
202
280
  //#endregion
203
- export { resolveVersion as a, listComponents as i, lintProject as n, loadMetadataFile as o, findComponent as r, version as s, analyzeUsage as t };
281
+ export { detectVersion as a, version as c, listComponents as i, lintProject as n, resolveVersion as o, findComponent as r, loadMetadataFile as s, analyzeUsage as t };
@@ -1,4 +1,4 @@
1
- import { a as resolveVersion, i as listComponents, n as lintProject, o as loadMetadataFile, r as findComponent, s as version } from "./scanner-_isnOGJK.mjs";
1
+ import { c as version, i as listComponents, n as lintProject, o as resolveVersion, r as findComponent, s as loadMetadataFile } from "./scanner-Dsl3i2de.mjs";
2
2
  import process from "node:process";
3
3
  import { McpServer, StdioServerTransport } from "@modelcontextprotocol/server";
4
4
  import * as z from "zod/v4";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wot-ui/cli",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.10",
4
+ "version": "0.0.1-beta.11",
5
5
  "description": "面向 wot-ui 的 CLI、MCP 与数据提取工具集",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/antfu",
@@ -67,16 +67,16 @@
67
67
  "build": "tsdown",
68
68
  "dev": "tsdown --watch",
69
69
  "extract": "tsx scripts/extract.ts",
70
- "extract:cli": "pnpm extract",
71
70
  "extract:clone": "rm -rf /tmp/open-wot-wot-ui && git clone --depth 1 https://github.com/wot-ui/wot-ui.git /tmp/open-wot-wot-ui && pnpm extract --wot-dir /tmp/open-wot-wot-ui --output data/v2.json",
71
+ "sync": "tsx scripts/sync.ts",
72
+ "sync:clone": "rm -rf /tmp/open-wot-wot-ui && git clone --filter=tree:0 --no-checkout https://github.com/wot-ui/wot-ui.git /tmp/open-wot-wot-ui && pnpm sync --wot-dir /tmp/open-wot-wot-ui",
73
+ "compress": "tsx scripts/compress.ts",
72
74
  "lint": "eslint",
73
75
  "release": "bumpp",
74
76
  "start": "tsx src/index.ts",
75
77
  "test": "vitest run",
76
78
  "test:coverage": "vitest run --coverage --coverage.reporter=lcov --coverage.reporter=text",
77
79
  "test:watch": "vitest",
78
- "typecheck": "tsc --noEmit",
79
- "typecheck:all": "pnpm typecheck",
80
- "typecheck:cli": "pnpm typecheck"
80
+ "typecheck": "tsc --noEmit"
81
81
  }
82
82
  }