UNPKG

@re-shell/cli

Version:

Full-stack development platform uniting microservices and microfrontends. Build complete applications with .NET (ASP.NET Core Web API, Minimal API), Java (Spring Boot, Quarkus, Micronaut, Vert.x), Rust (Actix-Web, Warp, Rocket, Axum), Python (FastAPI, Dja

226 lines (225 loc) 13.2 kB
#!/usr/bin/env node "use strict"; /** * Optimized CLI entry point with lazy loading and performance improvements */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); // Start profiling immediately const startTime = Date.now(); // Minimal imports for startup const performance_profiler_1 = require("./utils/performance-profiler"); performance_profiler_1.profiler.start(process.argv.slice(2).join(' ')); performance_profiler_1.profiler.mark('imports-start'); // Core imports only - defer everything else const commander_1 = require("commander"); const fs_1 = require("fs"); const path_1 = require("path"); performance_profiler_1.profiler.mark('core-imports-done'); // Read package.json once const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf-8')); performance_profiler_1.profiler.mark('package-json-loaded'); // Lazy load utilities const lazyLoad = { checkUpdate: null, spinner: null, chalk: null, detectFramework: null, env: null }; // Configure program commander_1.program .name('re-shell') .description('Re-Shell CLI - Universal Full-Stack Development Platform') .version(packageJson.version, '-v, --version') .option('-d, --debug', 'Enable debug mode') .option('--no-update-check', 'Skip update check') .option('--profile', 'Enable performance profiling') .hook('preAction', async (thisCommand, actionCommand) => { // Enable profiling if requested if (thisCommand.opts().profile || process.env.RESHELL_PROFILE === 'true') { process.env.RESHELL_PROFILE = 'true'; } // Skip update check for performance-critical commands const skipUpdateCommands = ['--version', '-v', 'help', 'completion']; const shouldCheckUpdate = !thisCommand.opts().noUpdateCheck && !skipUpdateCommands.includes(actionCommand.name()); if (shouldCheckUpdate) { performance_profiler_1.profiler.mark('update-check-start'); lazyLoad.checkUpdate = lazyLoad.checkUpdate || (await Promise.resolve().then(() => __importStar(require('./utils/checkUpdate')))).checkForUpdates; await lazyLoad.checkUpdate(); performance_profiler_1.profiler.mark('update-check-done'); } }); performance_profiler_1.profiler.mark('program-configured'); // Command loaders with lazy imports const commandLoaders = { 'init': () => Promise.resolve().then(() => __importStar(require('./commands/init'))), 'add': () => Promise.resolve().then(() => __importStar(require('./commands/add'))), 'serve': () => Promise.resolve().then(() => __importStar(require('./commands/serve'))), 'build': () => Promise.resolve().then(() => __importStar(require('./commands/build'))), 'list': () => Promise.resolve().then(() => __importStar(require('./commands/list'))), 'remove': () => Promise.resolve().then(() => __importStar(require('./commands/remove'))), 'update': () => Promise.resolve().then(() => __importStar(require('./commands/plugin'))).then(m => ({ updatePlugins: m.updatePlugins })), 'analyze': () => Promise.resolve().then(() => __importStar(require('./commands/analyze'))), 'doctor': () => Promise.resolve().then(() => __importStar(require('./commands/doctor'))), 'workspace': () => Promise.resolve().then(() => __importStar(require('./commands/workspace'))), 'config': () => Promise.resolve().then(() => __importStar(require('./commands/config'))), 'plugin': () => Promise.resolve().then(() => __importStar(require('./commands/plugin'))), 'create': () => Promise.resolve().then(() => __importStar(require('./commands/create'))), 'generate': () => Promise.resolve().then(() => __importStar(require('./commands/generate'))), 'migrate': () => Promise.resolve().then(() => __importStar(require('./commands/migrate'))), 'validate': () => Promise.resolve().then(() => __importStar(require('./commands/validate'))), 'template': () => Promise.resolve().then(() => __importStar(require('./commands/template'))), 'backup': () => Promise.resolve().then(() => __importStar(require('./commands/backup'))), 'cicd': () => Promise.resolve().then(() => __importStar(require('./commands/cicd'))), 'environment': () => Promise.resolve().then(() => __importStar(require('./commands/environment'))), 'submodule': () => Promise.resolve().then(() => __importStar(require('./commands/submodule'))), 'migration': () => Promise.resolve().then(() => __importStar(require('./commands/migration'))), 'project-config': () => Promise.resolve().then(() => __importStar(require('./commands/project-config'))), 'dev-mode': () => Promise.resolve().then(() => __importStar(require('./commands/dev-mode'))), 'workspace-config': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-config'))), 'workspace-definition': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-definition'))), 'workspace-template': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-template'))), 'workspace-backup': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-backup'))), 'workspace-migration': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-migration'))), 'workspace-conflict': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-conflict'))), 'workspace-graph': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-graph'))), 'workspace-health': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-health'))), 'workspace-state': () => Promise.resolve().then(() => __importStar(require('./commands/workspace-state'))), 'file-watcher': () => Promise.resolve().then(() => __importStar(require('./commands/file-watcher'))), 'change-detector': () => Promise.resolve().then(() => __importStar(require('./commands/change-detector'))), 'change-impact': () => Promise.resolve().then(() => __importStar(require('./commands/change-impact'))), 'incremental-build': () => Promise.resolve().then(() => __importStar(require('./commands/incremental-build'))), 'platform-test': () => Promise.resolve().then(() => __importStar(require('./commands/platform-test'))), 'plugin-dependency': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-dependency'))), 'plugin-marketplace': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-marketplace'))), 'plugin-security': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-security'))), 'plugin-command': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-command'))), 'plugin-middleware': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-middleware'))), 'plugin-conflicts': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-conflicts'))), 'plugin-docs': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-docs'))), 'plugin-validation': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-validation'))), 'plugin-cache': () => Promise.resolve().then(() => __importStar(require('./commands/plugin-cache'))), 'config-diff': () => Promise.resolve().then(() => __importStar(require('./commands/config-diff'))) }; // Register commands with lazy loading Object.entries(commandLoaders).forEach(([name, loader]) => { const cmd = commander_1.program.command(name); // Set up command metadata without loading the module switch (name) { case 'init': cmd.description('Initialize a new Re-Shell project') .action(async (...args) => { performance_profiler_1.profiler.mark(`${name}-load-start`); const module = await loader(); performance_profiler_1.profiler.mark(`${name}-load-done`); // Execute the function directly if ('initMonorepo' in module && typeof module.initMonorepo === 'function') { await module.initMonorepo(...args); } }); break; case 'add': cmd.description('Add a new microfrontend or service') .action(async (...args) => { performance_profiler_1.profiler.mark(`${name}-load-start`); const module = await loader(); performance_profiler_1.profiler.mark(`${name}-load-done`); // Execute the function directly if ('addMicrofrontend' in module && typeof module.addMicrofrontend === 'function') { await module.addMicrofrontend(...args); } }); break; // Add other commands similarly... default: cmd.description(`${name} command`) .action(async (...args) => { performance_profiler_1.profiler.mark(`${name}-load-start`); const module = await loader(); performance_profiler_1.profiler.mark(`${name}-load-done`); const setupFn = module[`setup${name.charAt(0).toUpperCase() + name.slice(1)}Command`]; if (setupFn) { setupFn(commander_1.program); await commander_1.program.parseAsync(process.argv); } }); } }); performance_profiler_1.profiler.mark('commands-registered'); // Fast path for version check if (process.argv.includes('--version') || process.argv.includes('-v')) { // Display version immediately without loading anything else if (!lazyLoad.chalk) { lazyLoad.chalk = require('chalk'); } const chalk = lazyLoad.chalk; console.log(chalk.cyan(` ██████╗ ███████╗ ███████╗██╗ ██╗███████╗██╗ ██╗ ██╔══██╗██╔════╝ ██╔════╝██║ ██║██╔════╝██║ ██║ ██████╔╝█████╗ ████████╗ ███████╗███████║█████╗ ██║ ██║ ██╔══██╗██╔══╝ ╚═══════╝ ╚════██║██╔══██║██╔══╝ ██║ ██║ ██║ ██║███████╗ ███████║██║ ██║███████╗███████╗███████╗ ╚═╝ ╚═╝╚══════╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝ v${packageJson.version} `)); console.log(packageJson.version); performance_profiler_1.profiler.mark('version-displayed'); performance_profiler_1.profiler.end(); // Exit quickly process.exit(0); } // Parse commands performance_profiler_1.profiler.mark('parse-start'); commander_1.program.parse(process.argv); performance_profiler_1.profiler.mark('parse-done'); // Show help if no command provided if (!process.argv.slice(2).length) { commander_1.program.outputHelp(); } // End profiling const report = performance_profiler_1.profiler.end(); // In debug mode, show startup time if (process.env.DEBUG === 'true' && report) { console.log(`\nStartup time: ${report.totalDuration.toFixed(2)}ms`); const bottlenecks = performance_profiler_1.profiler.analyzeBottlenecks(); if (bottlenecks.length > 0) { console.log('\nTop bottlenecks:'); bottlenecks.slice(0, 5).forEach(b => { console.log(` ${b.phase}: ${b.duration.toFixed(2)}ms (${b.percentage.toFixed(1)}%)`); }); } }