@neurolint/cli
Version:
NeuroLint CLI for React/Next.js modernization with advanced 6-layer orchestration and intelligent AST transformations
262 lines (224 loc) • 9.94 kB
text/typescript
import { Command } from "commander";
import chalk from "chalk";
import ora from "ora";
import inquirer from "inquirer";
import { analyzeCommand } from "./commands/analyze";
import { fixCommand } from "./commands/fix-fixed";
import { configCommand } from "./commands/config";
import { initCommand } from "./commands/init";
import { statusCommand } from "./commands/status";
import { loginCommand, logoutCommand } from "./commands/login";
import { analyticsCommand } from "./commands/analytics";
import { pluginCommand } from "./commands/plugin";
import { cacheCommand } from "./commands/cache";
import { migrateCommand } from "./commands/migrate";
const program = new Command();
program
.name("neurolint")
.description("NeuroLint CLI - Advanced code analysis and transformation")
.version("1.0.0");
// Welcome message
console.log(chalk.white.bold("NeuroLint CLI"));
console.log(chalk.gray("Advanced code analysis and transformation\n"));
// Initialize project command
program
.command("init")
.description("Initialize NeuroLint in your project")
.option("-f, --force", "Overwrite existing configuration")
.action(initCommand);
// Authentication commands
program
.command("login")
.description("Authenticate with NeuroLint service")
.option("--api-key <key>", "API key for authentication")
.option("--url <url>", "API server URL")
.action(loginCommand);
program
.command("logout")
.description("Clear authentication credentials")
.action(logoutCommand);
// Configuration command
program
.command("config")
.description("Manage NeuroLint configuration")
.option("--show", "Show current configuration")
.option("--set <key=value>", "Set configuration value")
.option("--unset <key>", "Remove configuration value")
.option("--reset", "Reset to defaults")
.action(configCommand);
// Status command
program
.command("status")
.description("Show project status and configuration")
.action(statusCommand);
// Code analysis command
program
.command("analyze")
.description("Analyze code for issues and improvements")
.argument("[path]", "Path to analyze (default: current directory)")
.option("-l, --layers <layers>", "Specify layers to run (1-6)")
.option("-f, --files <pattern>", "File pattern to include")
.option("-e, --exclude <pattern>", "File pattern to exclude")
.option("-o, --output <format>", "Output format (table|json|detailed-json|compact-json|html|summary)", "table")
.option("--output-file <file>", "Save output to file (required for HTML format)")
.option("-v, --verbose", "Verbose output")
.option("--recursive", "Analyze directories recursively")
.option("--max-files <number>", "Maximum number of files to analyze")
.action(analyzeCommand);
// Code fixing command
program
.command("fix")
.description("Fix code issues and apply transformations")
.argument("[path]", "Path to fix (default: current directory)")
.option("-l, --layers <layers>", "Specify layers to run (1-6)")
.option("-f, --files <pattern>", "File pattern to include")
.option("-e, --exclude <pattern>", "File pattern to exclude")
.option("-o, --output <format>", "Output format (table|json|detailed-json|html)", "table")
.option("--output-file <file>", "Save output to file")
.option("--dry-run", "Preview changes without applying")
.option("--backup", "Create backup before applying fixes")
.option("--recursive", "Fix directories recursively")
.option("-v, --verbose", "Verbose output")
.action(fixCommand);
// One-time migration command
program
.command("migrate")
.description("Perform one-time enterprise migration (React 16→18, Next.js 12→14)")
.argument("[path]", "Path to migrate (default: current directory)")
.option("--dry-run", "Preview migration without applying changes")
.option("--no-backup", "Disable automatic backup creation")
.option("-o, --output <format>", "Output format (table|json|detailed-json)", "table")
.option("--recursive", "Migrate directories recursively", true)
.option("-v, --verbose", "Verbose output")
.action(migrateCommand);
// Analytics command
program
.command("analytics")
.description("View detailed analytics and usage insights")
.option("-t, --time-range <range>", "Time range (day|week|month|quarter|year)", "week")
.option("-o, --output <format>", "Output format (table|json|detailed-json|html|csv)", "table")
.option("--output-file <file>", "Save output to file")
.option("--detailed", "Include detailed metrics and trends")
.option("--team-id <id>", "Include team analytics")
.action(analyticsCommand);
// Plugin management command
program
.command("plugin")
.description("Manage NeuroLint plugins")
.argument("<action>", "Action to perform (install|remove|list|enable|disable|update|search|create|info)")
.argument("[target]", "Plugin name or source")
.option("-v, --verbose", "Verbose output")
.option("-f, --force", "Force action without confirmation")
.option("--author <name>", "Author name (for create command)")
.option("--description <desc>", "Plugin description (for create command)")
.option("--enabled", "Show only enabled plugins (for list command)")
.option("--disabled", "Show only disabled plugins (for list command)")
.action(pluginCommand);
// Cache management command
program
.command("cache")
.description("Manage performance cache")
.argument("<action>", "Action to perform (stats|clear|warmup|cleanup|config)")
.option("-v, --verbose", "Verbose output")
.option("-f, --force", "Force action without confirmation")
.option("--detailed", "Show detailed information")
.option("--pattern <glob>", "File pattern for warmup", "**/*.{ts,tsx,js,jsx}")
.option("--max-files <n>", "Maximum files to warmup", "100")
.action(cacheCommand);
// Interactive mode
program
.command("interactive")
.alias("i")
.description("Interactive mode for guided operations")
.action(async () => {
console.log(chalk.white.bold("NeuroLint Interactive Mode\n"));
const { action } = await inquirer.prompt([
{
type: "list",
name: "action",
message: "What would you like to do?",
choices: [
{ name: "Analyze project", value: "analyze" },
{ name: "Fix issues", value: "fix" },
{ name: "Configure settings", value: "config" },
{ name: "Check status", value: "status" },
{ name: "Exit", value: "exit" },
],
},
]);
switch (action) {
case "analyze":
console.log(chalk.white("Starting code analysis..."));
break;
case "fix":
console.log(chalk.white("Starting code fixes..."));
break;
case "config":
console.log(chalk.white("Opening configuration..."));
break;
case "status":
console.log(chalk.white("Checking project status..."));
break;
default:
console.log(chalk.white("Goodbye"));
process.exit(0);
}
});
// Help command
program
.command("help")
.description("Show help and examples")
.action(() => {
console.log(chalk.white.bold("\nNeuroLint CLI Examples:\n"));
console.log(chalk.white("Initialize project:"));
console.log(chalk.gray(" neurolint init\n"));
console.log(chalk.white("Analyze specific files:"));
console.log(chalk.gray(" neurolint analyze src/components/*.tsx\n"));
console.log(chalk.white("Fix all TypeScript files:"));
console.log(
chalk.gray(' neurolint fix --recursive --include="**/*.ts,**/*.tsx"\n'),
);
console.log(chalk.white("Run specific layers:"));
console.log(chalk.gray(" neurolint analyze --layers=1,3,4 src/\n"));
console.log(chalk.white("Generate detailed JSON report:"));
console.log(chalk.gray(" neurolint analyze --output=detailed-json --output-file=report.json\n"));
console.log(chalk.white("Generate HTML report:"));
console.log(chalk.gray(" neurolint analyze --output=html --output-file=report.html\n"));
console.log(chalk.white("Compact JSON for CI/CD:"));
console.log(chalk.gray(" neurolint analyze --output=compact-json src/\n"));
console.log(chalk.white("View analytics dashboard:"));
console.log(chalk.gray(" neurolint analytics --time-range=month --detailed\n"));
console.log(chalk.white("Export analytics to CSV:"));
console.log(chalk.gray(" neurolint analytics --output=csv --output-file=report.csv\n"));
console.log(chalk.white("Create custom plugin:"));
console.log(chalk.gray(" neurolint plugin create my-custom-rules\n"));
console.log(chalk.white("Install plugin from file:"));
console.log(chalk.gray(" neurolint plugin install ./my-plugin.js\n"));
console.log(chalk.white("List installed plugins:"));
console.log(chalk.gray(" neurolint plugin list --verbose\n"));
console.log(chalk.white("Check cache performance:"));
console.log(chalk.gray(" neurolint cache stats --detailed\n"));
console.log(chalk.white("Warm up cache for faster analysis:"));
console.log(chalk.gray(" neurolint cache warmup --pattern='src/**/*.tsx'\n"));
console.log(chalk.white("Preview fixes without applying:"));
console.log(chalk.gray(" neurolint fix --dry-run src/components/\n"));
console.log(chalk.white("Interactive mode:"));
console.log(chalk.gray(" neurolint interactive\n"));
});
// Error handling
program.exitOverride();
try {
program.parse();
} catch (err: any) {
if (err.code === "commander.unknownOption") {
console.error(chalk.red(`Unknown option: ${err.message}`));
console.log(chalk.gray("Use 'neurolint --help' to see available options"));
} else if (err.code === "commander.unknownCommand") {
console.error(chalk.red(`Unknown command: ${err.message}`));
console.log(chalk.gray("Use 'neurolint --help' to see available commands"));
} else {
console.error(chalk.red(`Error: ${err.message}`));
}
process.exit(1);
}