UNPKG

stack-performance-analyzer

Version:

A comprehensive application stack analyzer that evaluates MEAN, MERN, and other Node.js-based applications across 15 performance criteria

69 lines (55 loc) 2.06 kB
#!/usr/bin/env node const { Command } = require('commander'); const path = require('path'); const ApplicationAnalyzer = require('../index'); const chalk = require('chalk'); const program = new Command(); program .name('analyze-stack') .description('Comprehensive Node.js application stack analyzer') .version('1.0.0') .argument('[path]', 'Path to the project to analyze', '.') .option('-v, --verbose', 'Show verbose output') .option('-o, --output <format>', 'Output format (console, json)', 'console') .option('--save <file>', 'Save results to file') .action(async (projectPath, options) => { try { const absolutePath = path.resolve(projectPath); if (options.verbose) { console.log(chalk.blue(`Analyzing project at: ${absolutePath}`)); } const analyzer = new ApplicationAnalyzer({ projectPath: absolutePath, verbose: options.verbose }); const results = await analyzer.analyze(absolutePath); if (options.output === 'json') { console.log(JSON.stringify(results, null, 2)); } if (options.save) { const fs = require('fs-extra'); await fs.writeJson(options.save, results, { spaces: 2 }); console.log(chalk.green(`\n✅ Results saved to ${options.save}`)); } } catch (error) { console.error(chalk.red('❌ Analysis failed:'), error.message); if (options.verbose) { console.error(error.stack); } process.exit(1); } }); // Add help examples program.addHelpText('after', ` Examples: $ analyze-stack # Analyze current directory $ analyze-stack /path/to/project # Analyze specific project $ analyze-stack . --save results.json # Save results to file $ analyze-stack . --output json # Output as JSON $ analyze-stack . --verbose # Show detailed output `); program.parse(); // If no arguments provided, show help if (process.argv.length === 2) { program.help(); }