agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
91 lines (76 loc) • 3.37 kB
JavaScript
#!/usr/bin/env node
/**
* @file Command-line interface for frontend-backend integration analysis and API mismatch detection
* @description Single responsibility: Provide interactive CLI for identifying integration issues between frontend and backend
*
* This CLI tool serves as the integration analysis interface for the AgentSqripts platform,
* detecting API endpoint mismatches, unused routes, missing endpoints, and communication
* problems between frontend and backend code. It implements cross-layer analysis, route
* normalization, and comprehensive reporting to support integration testing workflows.
*
* Design rationale:
* - Integration-focused analysis prevents runtime failures before deployment
* - Cross-layer endpoint matching identifies missing or unused API definitions
* - Route normalization enables accurate comparison across different coding styles
* - Framework-agnostic detection supports diverse technology stacks
* - Comprehensive reporting enables systematic integration issue resolution
*/
const fs = require('fs');
const path = require('path');
const { getProcessArgs } = require('../lib/utils/processHelpers');
const { shouldShowHelp } = require('../lib/utils/cliHelpers');
const { analyzeProjectIntegration } = require('../lib/frontend-backend/analyzeFrontendBackend');
// Import focused modules
const { parseFrontendBackendArgs, showFrontendBackendUsage } = require('./lib/frontendBackendCommandParser');
const { formatResults } = require('./lib/frontendBackendOutputFormatter');
const { handleAnalysisError } = require('./lib/errorHandler');
/**
* Main function
*/
async function main() {
const args = getProcessArgs();
if (shouldShowHelp(args)) {
showFrontendBackendUsage();
return;
}
try {
// Parse command line arguments using dedicated parser
const { options, targetPath: rawTargetPath } = parseFrontendBackendArgs(args);
// Resolve target path
const targetPath = path.resolve(rawTargetPath);
// Build analysis options
const analysisOptions = {
frontendExtensions: options.frontendExtensions,
backendExtensions: options.backendExtensions,
excludePatterns: ['node_modules', '.git', 'dist', 'build', 'coverage', 'test']
};
// Apply directory overrides if specified
if (options.frontendDir) {
analysisOptions.frontendDir = path.resolve(targetPath, options.frontendDir);
}
if (options.backendDir) {
analysisOptions.backendDir = path.resolve(targetPath, options.backendDir);
}
// Analyze integration (await the async function)
const results = await analyzeProjectIntegration(targetPath, analysisOptions);
// Output results using dedicated formatter
const formatted = formatResults(results, options.outputFormat, {
severity: options.severity,
category: options.category
});
console.log(formatted);
// Exit with error code if high-impact issues found
const hasHighImpact = results.summary?.severityBreakdown?.HIGH > 0;
if (hasHighImpact) {
process.exit(1);
}
} catch (error) {
handleAnalysisError(error, 'frontend-backend integration');
}
}
if (require.main === module) {
main().catch(error => {
console.error('Error running frontend-backend analysis:', error.message);
process.exit(1);
});
}