修复安装脚本:fallback 补装 agents、错误处理、参数校验

- fallback 安装现在也会安装 agents 到 .claude/agents/
- install 函数添加 try-catch 和 SKILLS_SRC 存在性检查
- 未知 CLI 参数显示警告并输出帮助
- 帮助文本补充 agents 相关说明
This commit is contained in:
jiangnan
2026-03-21 00:17:52 +08:00
parent 6fa291f09c
commit 74a9b7c1f0

View File

@@ -30,7 +30,7 @@ function showHelp() {
superpowers-zh v${PKG.version} — AI 编程超能力中文版
用法:
npx superpowers-zh 安装 skills 到当前项目
npx superpowers-zh 安装 skills(及 agents到当前项目
npx superpowers-zh --help 显示帮助
npx superpowers-zh --version 显示版本
@@ -38,14 +38,22 @@ function showHelp() {
自动检测当前项目使用的 AI 编程工具:
Claude Code / Cursor / Codex / Kiro / Trae / Antigravity / VS Code
${countDirs(SKILLS_SRC)} 个 skills 安装到对应目录。
如果未检测到任何工具,默认安装到 .claude/skills/。
Claude Code 还会额外安装 agents 到 .claude/agents/。
如果未检测到任何工具,默认安装到 .claude/skills/ 和 .claude/agents/。
项目https://github.com/jnMetaCode/superpowers-zh
`);
}
function install() {
try {
console.log(`\n superpowers-zh v${PKG.version} — AI 编程超能力中文版\n`);
if (!existsSync(SKILLS_SRC)) {
console.error(' ❌ 错误skills 源目录不存在,请重新安装 superpowers-zh。');
process.exit(1);
}
console.log(` 源: ${countDirs(SKILLS_SRC)} 个 skills`);
console.log(` 目标项目: ${PROJECT_DIR}\n`);
@@ -75,9 +83,20 @@ function install() {
mkdirSync(dest, { recursive: true });
cpSync(SKILLS_SRC, dest, { recursive: true });
console.log(` ✅ 默认安装: ${countDirs(dest)} 个 skills -> ${dest}`);
if (existsSync(AGENTS_SRC)) {
const agentsDest = resolve(PROJECT_DIR, '.claude', 'agents');
mkdirSync(agentsDest, { recursive: true });
cpSync(AGENTS_SRC, agentsDest, { recursive: true });
console.log(` ✅ 默认安装: agents -> ${agentsDest}`);
}
}
console.log('\n 安装完成!重启你的 AI 编程工具即可生效。\n');
} catch (err) {
console.error(` ❌ 安装失败:${err.message}`);
process.exit(1);
}
}
const arg = process.argv[2];
@@ -85,6 +104,10 @@ if (arg === '--help' || arg === '-h') {
showHelp();
} else if (arg === '--version' || arg === '-v') {
console.log(PKG.version);
} else if (arg && arg.startsWith('-')) {
console.warn(` 未知参数: ${arg}\n`);
showHelp();
process.exit(1);
} else {
install();
}