adspecs 0.1.14 → 0.1.15
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
CHANGED
package/src/commands/plugin.js
CHANGED
|
@@ -39,13 +39,21 @@ function getPluginName() {
|
|
|
39
39
|
/**
|
|
40
40
|
* 安装(注册)插件到 Claude Code
|
|
41
41
|
*
|
|
42
|
+
* Claude Code 的 marketplace 命令期望路径指向包含 `.claude-plugin/marketplace.json`
|
|
43
|
+
* 的目录,因此传入 PLUGIN_DIR(而非 PLUGIN_DIR/.claude-plugin)。
|
|
44
|
+
*
|
|
42
45
|
* @param {object} options
|
|
43
46
|
* @param {string} options.scope - 安装范围: user|project
|
|
44
47
|
*/
|
|
45
48
|
exports.install = async function install(options) {
|
|
46
49
|
const scope = options.scope || 'user';
|
|
47
50
|
const pluginName = getPluginName();
|
|
48
|
-
|
|
51
|
+
|
|
52
|
+
// marketplace.json 必须存在,否则无法注册
|
|
53
|
+
const marketplaceJson = path.join(PLUGIN_DIR, '.claude-plugin', 'marketplace.json');
|
|
54
|
+
if (!fs.existsSync(marketplaceJson)) {
|
|
55
|
+
throw new Error(`未找到 marketplace 清单: ${marketplaceJson}`);
|
|
56
|
+
}
|
|
49
57
|
|
|
50
58
|
console.log(chalk.cyan('🔌 adspecs 插件注册'));
|
|
51
59
|
console.log('');
|
|
@@ -65,25 +73,36 @@ exports.install = async function install(options) {
|
|
|
65
73
|
process.exit(1);
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
// 2. 注册 marketplace
|
|
76
|
+
// 2. 注册 marketplace
|
|
77
|
+
// 注意:传入 PLUGIN_DIR,claude 会去找 <PLUGIN_DIR>/.claude-plugin/marketplace.json
|
|
69
78
|
console.log(chalk.gray(' → 注册 marketplace...'));
|
|
79
|
+
let marketplaceRegistered = false;
|
|
70
80
|
try {
|
|
71
81
|
execSync(
|
|
72
|
-
`claude plugins marketplace add "${
|
|
82
|
+
`claude plugins marketplace add "${PLUGIN_DIR}" --scope ${scope}`,
|
|
73
83
|
{ stdio: 'pipe' }
|
|
74
84
|
);
|
|
75
85
|
console.log(chalk.green(' ✅ marketplace 注册成功'));
|
|
86
|
+
marketplaceRegistered = true;
|
|
76
87
|
} catch (err) {
|
|
77
88
|
const stderr = err.stderr ? err.stderr.toString() : '';
|
|
78
|
-
|
|
89
|
+
const stdout = err.stdout ? err.stdout.toString() : '';
|
|
90
|
+
const combined = stderr + stdout;
|
|
91
|
+
if (combined.includes('already exists') || combined.includes('already registered')) {
|
|
79
92
|
console.log(chalk.yellow(' ⏭ marketplace 已存在,跳过'));
|
|
93
|
+
marketplaceRegistered = true; // 已存在也视为可用
|
|
80
94
|
} else {
|
|
81
|
-
|
|
95
|
+
// 把真实错误输出,方便排查,不再静默吞掉
|
|
96
|
+
console.log(chalk.red(` ❌ marketplace 注册失败: ${combined.trim() || err.message}`));
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
99
|
|
|
85
100
|
// 3. 安装插件
|
|
101
|
+
// 只有 marketplace 注册成功(或已存在)时,才能按名称安装
|
|
86
102
|
console.log(chalk.gray(' → 安装插件...'));
|
|
103
|
+
if (!marketplaceRegistered) {
|
|
104
|
+
throw new Error('marketplace 未注册成功,无法按名称安装插件,请检查上方错误');
|
|
105
|
+
}
|
|
87
106
|
try {
|
|
88
107
|
execSync(`claude plugins install ${pluginName} --scope ${scope}`, {
|
|
89
108
|
stdio: 'pipe',
|
|
@@ -91,10 +110,12 @@ exports.install = async function install(options) {
|
|
|
91
110
|
console.log(chalk.green(` ✅ ${pluginName} 插件安装成功`));
|
|
92
111
|
} catch (err) {
|
|
93
112
|
const stderr = err.stderr ? err.stderr.toString() : '';
|
|
94
|
-
|
|
113
|
+
const stdout = err.stdout ? err.stdout.toString() : '';
|
|
114
|
+
const combined = stderr + stdout;
|
|
115
|
+
if (combined.includes('already installed')) {
|
|
95
116
|
console.log(chalk.yellow(` ⏭ ${pluginName} 已安装,跳过`));
|
|
96
117
|
} else {
|
|
97
|
-
throw new Error(`插件安装失败: ${
|
|
118
|
+
throw new Error(`插件安装失败: ${combined.trim() || err.message}`);
|
|
98
119
|
}
|
|
99
120
|
}
|
|
100
121
|
|