@42ailab/42plugin 0.1.11 → 0.1.12

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 (3) hide show
  1. package/package.json +1 -1
  2. package/src/cli.ts +21 -5
  3. package/src/utils.ts +43 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "活水插件",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/cli.ts CHANGED
@@ -15,16 +15,32 @@ import {
15
15
  checkCommand,
16
16
  } from './commands';
17
17
 
18
- // 版本号在构建时通过 --define 注入
19
- declare const __VERSION__: string;
20
- const version: string = typeof __VERSION__ !== 'undefined' ? __VERSION__ : '0.0.0-dev';
18
+ // 版本号处理:
19
+ // - Homebrew(编译后):构建时通过 --define __VERSION__ 注入
20
+ // - npm/dev(源码):fallback package.json
21
+ declare const __VERSION__: string | undefined;
22
+
23
+ function getVersion(): string {
24
+ // 1. 优先使用构建时注入的版本(Homebrew 二进制)
25
+ if (typeof __VERSION__ !== 'undefined') {
26
+ return __VERSION__;
27
+ }
28
+ // 2. 源码运行时从 package.json 读取(npm/dev)
29
+ try {
30
+ return require('../package.json').version;
31
+ } catch {
32
+ return '0.0.0-dev';
33
+ }
34
+ }
35
+
36
+ const VERSION = getVersion();
21
37
 
22
38
  const program = new Command();
23
39
 
24
40
  program
25
41
  .name('42plugin')
26
42
  .description('活水插件 - AI 插件管理工具')
27
- .version(version, '-v, --version', '显示版本号')
43
+ .version(VERSION, '-v, --version', '显示版本号')
28
44
  .option('--verbose', '详细输出')
29
45
  .option('--no-color', '禁用颜色输出');
30
46
 
@@ -44,7 +60,7 @@ program
44
60
  .command('version')
45
61
  .description('显示版本信息')
46
62
  .action(() => {
47
- console.log(`42plugin v${version}`);
63
+ console.log(`42plugin v${VERSION}`);
48
64
  });
49
65
 
50
66
  export { program };
package/src/utils.ts CHANGED
@@ -11,31 +11,58 @@ import { TargetType, type ParsedTarget, type PluginType } from './types';
11
11
  /**
12
12
  * 解析安装目标
13
13
  *
14
- * - Plugin: author/name
15
- * - Kit: author/kit/slug
14
+ * 格式:
15
+ * - Plugin (2段): author/name (e.g., alice/smart-reviewer)
16
+ * - Plugin (3段): author/kit-name/plugin-name (e.g., anthropics/claude-code/create-plugin)
17
+ * - Kit: author/kit/slug (中间必须是 "kit" 关键字)
16
18
  */
17
19
  export function parseTarget(target: string): ParsedTarget {
18
- // Kit: author/kit/slug
19
- if (target.includes('/kit/')) {
20
- const [author, , slug] = target.split('/');
20
+ const parts = target.split('/');
21
+
22
+ // Kit format: author/kit/slug (3段,中间是 "kit" 关键字)
23
+ if (parts.length === 3 && parts[1] === 'kit') {
24
+ const [author, , slug] = parts;
21
25
  if (!author || !slug) {
22
26
  throw new Error(`无效的套包格式: ${target}\n正确格式: author/kit/slug`);
23
27
  }
24
- return { type: TargetType.Kit, fullName: target, author, name: slug };
28
+ return {
29
+ type: TargetType.Kit,
30
+ fullName: target,
31
+ author,
32
+ name: slug,
33
+ };
25
34
  }
26
35
 
27
- // Plugin: author/name
28
- const parts = target.split('/');
29
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
30
- throw new Error(`无效的插件格式: ${target}\n正确格式: author/name`);
36
+ // Plugin format (2段): author/name
37
+ if (parts.length === 2) {
38
+ const [author, name] = parts;
39
+ if (!author || !name) {
40
+ throw new Error(`无效的安装目标格式: ${target}\n正确格式: author/name`);
41
+ }
42
+ return {
43
+ type: TargetType.Plugin,
44
+ fullName: target,
45
+ author,
46
+ name,
47
+ };
48
+ }
49
+
50
+ // Plugin format (3段): author/kit-name/plugin-name
51
+ if (parts.length === 3) {
52
+ const [author, kitName, pluginName] = parts;
53
+ if (!author || !kitName || !pluginName) {
54
+ throw new Error(`无效的安装目标格式: ${target}\n正确格式: author/kit-name/plugin-name`);
55
+ }
56
+ // 将 3 段格式传给 API,API 会处理
57
+ return {
58
+ type: TargetType.Plugin,
59
+ fullName: target,
60
+ author,
61
+ name: `${kitName}/${pluginName}`, // 组合成 API 期望的路径格式
62
+ };
31
63
  }
32
64
 
33
- return {
34
- type: TargetType.Plugin,
35
- fullName: target,
36
- author: parts[0],
37
- name: parts[1],
38
- };
65
+ throw new Error(`无效的安装目标格式: ${target}\n正确格式: author/name 或 author/kit-name/plugin-name 或 author/kit/slug`);
39
66
  }
40
67
 
41
68
  // ============================================================================