UNPKG

creatrip-agent-rules-builder

Version:

Unified converter for AI coding agent rules across Cursor, Windsurf, and Claude

47 lines (35 loc) 1.26 kB
import * as fs from "fs"; import * as path from "path"; import { ParsedContent } from "../types"; export function generateCursorRules( parsedContent: ParsedContent, baseDir: string = process.cwd() ): void { const { rules, config } = parsedContent; const cursorConfig = config.cursor || {}; const cursorDir = path.join(baseDir, ".cursor", "rules"); const filename = cursorConfig.filename || "rules"; const filePath = path.join(cursorDir, `${filename}.mdc`); // 디렉토리 생성 fs.mkdirSync(cursorDir, { recursive: true }); let content = ""; // frontmatter 항상 추가 content += "---\n"; // description (기본값: 빈 문자열) const description = cursorConfig.description || ""; content += `description: ${description}\n`; // globs (기본값: 빈 문자열) let globsString = ""; if (cursorConfig.globs) { globsString = Array.isArray(cursorConfig.globs) ? cursorConfig.globs.join(",") : cursorConfig.globs; } content += `globs: ${globsString}\n`; // alwaysApply (기본값: false) const alwaysApply = cursorConfig.alwaysApply ?? false; content += `alwaysApply: ${alwaysApply}\n`; content += "---\n\n"; content += rules; fs.writeFileSync(filePath, content, "utf8"); }