feat: 新增 rune update 命令用于更新编辑器配置
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { mkdir, writeFile, readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { STAGES } from "../types.ts";
|
||||
|
||||
@@ -35,3 +35,36 @@ export async function injectClaudeCode(projectRoot: string): Promise<void> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateClaudeCode(projectRoot: string): Promise<void> {
|
||||
for (const stage of STAGES) {
|
||||
const hasChangeName = stage !== "discuss";
|
||||
|
||||
const commandDir = join(projectRoot, COMMANDS_DIR);
|
||||
await mkdir(commandDir, { recursive: true });
|
||||
const commandPath = join(commandDir, `rune-${stage}.md`);
|
||||
const cmd = hasChangeName
|
||||
? `rune ${stage} <变更名>`
|
||||
: `rune ${stage}`;
|
||||
const nameHint = hasChangeName
|
||||
? "\n如果用户没有指定变更名称,请向用户确认。"
|
||||
: "";
|
||||
const newContent = `执行以下命令,将输出作为当前阶段的工作指引:\n\`\`\`bash\n${cmd}\n\`\`\`${nameHint}\n`;
|
||||
await writeIfChangedClaude(commandPath, newContent);
|
||||
}
|
||||
|
||||
const statusPath = join(projectRoot, COMMANDS_DIR, "rune-status.md");
|
||||
await writeIfChangedClaude(statusPath, `执行以下命令查看变更状态:\n\`\`\`bash\nrune status\n\`\`\`\n`);
|
||||
}
|
||||
|
||||
async function writeIfChangedClaude(filePath: string, newContent: string): Promise<void> {
|
||||
try {
|
||||
const existing = await readFile(filePath, "utf-8");
|
||||
if (existing === newContent) {
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// 文件不存在,创建
|
||||
}
|
||||
await writeFile(filePath, newContent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user