stack-performance
Version:
A comprehensive application stack analyzer that evaluates MEAN, MERN, and other Node.js-based applications across 15 performance criteria
153 lines (131 loc) ⢠4.82 kB
JavaScript
const StackAnalyzer = require('./lib/StackAnalyzer');
const path = require('path');
/**
* Main entry point for the Stack Performance Analyzer
* Analyzes applications based on 15 comprehensive criteria
*/
class ApplicationAnalyzer {
constructor(options = {}) {
this.analyzer = new StackAnalyzer(options);
this.projectPath = options.projectPath || process.cwd();
}
/**
* Analyze the application and return comprehensive results
* @param {string} projectPath - Path to the project to analyze
* @returns {Object} Analysis results with scores and recommendations
*/
async analyze(projectPath = this.projectPath) {
try {
console.log('š Starting Stack Performance Analysis...\n');
// Initialize analysis
await this.analyzer.initialize(projectPath);
// Run all 15 criteria analyses
const results = await this.analyzer.runFullAnalysis();
// Display results
this.displayResults(results);
return results;
} catch (error) {
console.error('ā Analysis failed:', error.message);
throw error;
}
}
/**
* Display formatted analysis results to console
* @param {Object} results - Analysis results
*/
displayResults(results) {
const chalk = require('chalk');
console.log(chalk.bold.cyan('š STACK PERFORMANCE ANALYSIS RESULTS'));
console.log(chalk.gray('=' .repeat(60)));
// Display individual criteria scores
results.criteria.forEach(criterion => {
const scoreColor = this.getScoreColor(criterion.score);
const remarkColor = this.getRemarkColor(criterion.remark);
console.log(
`${chalk.bold(criterion.name.padEnd(35))} | ` +
`${chalk.hex(this.getScoreColorHex(criterion.score))(criterion.score.toString().padStart(3))}/100 | ` +
`${chalk.hex(this.getRemarkColorHex(criterion.remark))(criterion.remark)}`
);
});
console.log(chalk.gray('-'.repeat(60)));
// Overall score
const overallColor = this.getScoreColor(results.overall.score);
const overallRemarkColor = this.getRemarkColor(results.overall.remark);
console.log(
`${chalk.bold.white('OVERALL PERFORMANCE'.padEnd(35))} | ` +
`${chalk.bold.hex(this.getScoreColorHex(results.overall.score))(results.overall.score.toString().padStart(3))}/100 | ` +
`${chalk.bold.hex(this.getRemarkColorHex(results.overall.remark))(results.overall.remark)}`
);
console.log('\n' + chalk.bold.green('ā
Analysis Complete'));
// Display stack information
console.log(chalk.bold.blue('\nš§ Detected Stack Information:'));
console.log(`Stack Type: ${results.stackInfo.type}`);
console.log(`Technologies: ${results.stackInfo.technologies.join(', ')}`);
console.log(`Node.js Version: ${results.stackInfo.nodeVersion || 'Not detected'}`);
}
/**
* Get appropriate color for score display
* @param {number} score - Score out of 100
* @returns {string} Color name
*/
getScoreColor(score) {
if (score >= 90) return 'green';
if (score >= 80) return 'cyan';
if (score >= 70) return 'yellow';
if (score >= 60) return 'orange';
return 'red';
}
/**
* Get appropriate color for remark display
* @param {string} remark - Performance remark
* @returns {string} Color name
*/
getRemarkColor(remark) {
const remarkColors = {
'Excellent': 'green',
'Best': 'green',
'Good': 'cyan',
'Average': 'yellow',
'Poor': 'red'
};
return remarkColors[remark] || 'white';
}
/**
* Get hex color for score display
* @param {number} score - Score out of 100
* @returns {string} Hex color
*/
getScoreColorHex(score) {
if (score >= 90) return '#00ff00'; // green
if (score >= 80) return '#00ffff'; // cyan
if (score >= 70) return '#ffff00'; // yellow
if (score >= 60) return '#ffa500'; // orange
return '#ff0000'; // red
}
/**
* Get hex color for remark display
* @param {string} remark - Performance remark
* @returns {string} Hex color
*/
getRemarkColorHex(remark) {
const remarkColors = {
'Excellent': '#00ff00',
'Best': '#00ff00',
'Good': '#00ffff',
'Average': '#ffff00',
'Poor': '#ff0000'
};
return remarkColors[remark] || '#ffffff';
}
}
module.exports = ApplicationAnalyzer;
// If run directly
if (require.main === module) {
const analyzer = new ApplicationAnalyzer();
analyzer.analyze(process.argv[2])
.then(() => process.exit(0))
.catch(error => {
console.error('Analysis failed:', error);
process.exit(1);
});
}