@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.
- package/package.json +1 -1
- package/src/cli.ts +21 -5
- package/src/utils.ts +43 -16
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -15,16 +15,32 @@ import {
|
|
|
15
15
|
checkCommand,
|
|
16
16
|
} from './commands';
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
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(
|
|
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${
|
|
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
|
-
*
|
|
15
|
-
* -
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 {
|
|
28
|
+
return {
|
|
29
|
+
type: TargetType.Kit,
|
|
30
|
+
fullName: target,
|
|
31
|
+
author,
|
|
32
|
+
name: slug,
|
|
33
|
+
};
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
// Plugin: author/name
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
// ============================================================================
|