UNPKG

aicm

Version:

A TypeScript CLI tool for managing AI IDE rules across different projects and teams

103 lines (98 loc) 3.27 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runCli = runCli; const arg_1 = __importDefault(require("arg")); const chalk_1 = __importDefault(require("chalk")); const init_1 = require("./commands/init"); const install_1 = require("./commands/install"); const list_1 = require("./commands/list"); const clean_1 = require("./commands/clean"); // Define version from package.json // eslint-disable-next-line @typescript-eslint/no-require-imports const pkg = require("../package.json"); async function runCli() { const args = (0, arg_1.default)({ "--help": Boolean, "--version": Boolean, "--ci": Boolean, "--verbose": Boolean, "--dry-run": Boolean, "-h": "--help", "-v": "--version", }, { permissive: true, argv: process.argv.slice(2), }); // Show version if (args["--version"]) { console.log(pkg.version); process.exit(0); } // Show help if (args["--help"]) { showHelp(); process.exit(0); } const command = args._.length > 0 ? args._[0] : null; try { switch (command) { case "init": (0, init_1.initCommand)(); break; case "install": await (0, install_1.installCommand)(args["--ci"], args["--verbose"], args["--dry-run"]); break; case "list": await (0, list_1.listCommand)(); break; case "clean": await (0, clean_1.cleanCommand)(args["--verbose"]); break; default: showHelp(); break; } } catch (error) { logError(error, args["--verbose"]); process.exit(1); } } function showHelp() { console.log(` ${chalk_1.default.bold("aicm")} - A CLI tool for managing AI IDE configurations ${chalk_1.default.bold("USAGE")} $ aicm [command] [options] ${chalk_1.default.bold("COMMANDS")} init Initialize a new aicm configuration file install Install rules from configured sources list List all configured rules and their status clean Remove all files and directories created by aicm ${chalk_1.default.bold("OPTIONS")} -h, --help Show this help message -v, --version Show version number --ci Run in CI environments (default: \`false\`) --verbose Show detailed output and stack traces for debugging --dry-run Simulate installation without writing files, useful for validating presets in CI ${chalk_1.default.bold("EXAMPLES")} $ aicm init $ aicm install $ aicm install --dry-run $ aicm list `); } function logError(error, verbose) { if (error instanceof Error) { console.error(chalk_1.default.red(`Error: ${error.message}`)); if (verbose && error.stack) { console.error(chalk_1.default.gray(error.stack)); } } else { console.error(chalk_1.default.red(`Error: ${String(error)}`)); } }