UNPKG

@gabimoncha/cursor-rules

Version:

A CLI for bootstrapping Cursor rules to a project

43 lines 1.69 kB
import { existsSync } from "node:fs"; import fs from "node:fs/promises"; import path from "node:path"; import pc from "picocolors"; import { logger } from "../../shared/logger.js"; export async function runListRulesAction() { try { // Create .cursor directory if it doesn't exist const cursorDir = path.join(process.cwd(), ".cursor", "rules"); if (!existsSync(cursorDir)) { logger.warn("\n No .cursor/rules found.\n"); throw new Error("folder empty"); } const files = await fs.readdir(cursorDir); if (files.length === 0) { logger.warn("\n .cursor/rules folder is empty.\n"); throw new Error("folder empty"); } let count = 0; logger.log('\n'); logger.prompt.intro(`Found ${files.length} Cursor rules:`); for (const file of files) { logger.prompt.message(file); count++; } logger.prompt.outro(``); logger.quiet(`\n Found ${files.length} Cursor rules`); return; } catch (error) { if (error.message === "folder empty") { logger.info("Run `cursor-rules init` to initialize the project."); logger.info("Run `cursor-rules help` to see all commands."); logger.quiet(pc.yellow("\n No .cursor/rules found.")); logger.quiet(pc.cyan("\n Run `cursor-rules init` to initialize the project.")); return; } // Handle case where we might not be in a project (e.g., global install) logger.error("\n Failed to list cursor rules:", error); process.exit(1); } } //# sourceMappingURL=listRulesAction.js.map