ripple-ai-detector
Version:
🌊 Ripple AI Bug Detector - Built by an AI that knows its flaws. Catch AI-generated bugs before you commit.
88 lines • 4.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateCommand = validateCommand;
const logger_1 = require("../utils/logger");
const config_1 = require("../config/config");
const git_manager_1 = require("../git/git-manager");
const analyzer_1 = require("../analysis/analyzer");
const usage_tracker_1 = require("../usage/usage-tracker");
const formatter_1 = require("../output/formatter");
async function validateCommand(options) {
try {
// Load configuration
await config_1.configManager.loadConfig();
const config = config_1.configManager.getConfig();
// Check usage limits
const usageTracker = new usage_tracker_1.UsageTracker();
const canValidate = await usageTracker.canValidate();
if (!canValidate) {
const usage = await usageTracker.getUsage();
logger_1.logger.error(`Monthly validation limit reached (${usage.current}/${usage.limit})`);
logger_1.logger.money('You\'ve saved hours of debugging this month!');
logger_1.logger.upgrade('Upgrade to Pro for unlimited validations: $49/month');
logger_1.logger.tip('Visit: https://ripple.dev/upgrade');
process.exit(1);
}
// Show header
if (options.format === 'console') {
logger_1.logger.header();
}
// Determine files to analyze
let filesToAnalyze = [];
if (options.files) {
filesToAnalyze = options.files;
}
else if (options.all) {
// Analyze all files in project
const gitManager = new git_manager_1.GitManager();
filesToAnalyze = await gitManager.getAllJSFiles();
}
else {
// Default: analyze staged files
const gitManager = new git_manager_1.GitManager();
filesToAnalyze = await gitManager.getStagedFiles();
if (filesToAnalyze.length === 0) {
logger_1.logger.warning('No staged files found');
logger_1.logger.tip('Stage some files with "git add" or use --all to analyze entire project');
return;
}
}
// Filter for supported files
filesToAnalyze = filesToAnalyze.filter(file => file.endsWith('.js') || file.endsWith('.jsx') ||
file.endsWith('.ts') || file.endsWith('.tsx'));
if (filesToAnalyze.length === 0) {
logger_1.logger.warning('No JavaScript/TypeScript files to analyze');
return;
}
// Start analysis
logger_1.logger.startSpinner(`Analyzing ${filesToAnalyze.length} files...`);
const analyzer = new analyzer_1.RippleAnalyzer(config);
const results = await analyzer.analyze(filesToAnalyze);
logger_1.logger.stopSpinner(true, `Analysis complete`);
// Track usage
await usageTracker.trackValidation(filesToAnalyze.length, results.aiGenerated);
// Format and display results
const formatter = new formatter_1.OutputFormatter(options.format);
await formatter.displayResults(results);
// Show usage status
if (options.format === 'console') {
const usage = await usageTracker.getUsage();
logger_1.logger.newLine();
logger_1.logger.usageStatus(usage.current, usage.limit);
// Show upgrade prompt if getting close to limit
if (usage.current >= usage.limit * 0.8) {
logger_1.logger.upgrade('Upgrade to Pro for unlimited validations: ripple.dev/pro');
}
}
// Exit with error code if issues found
if (results.issues.some(issue => issue.severity === 'error')) {
process.exit(1);
}
}
catch (error) {
logger_1.logger.stopSpinner(false, 'Analysis failed');
logger_1.logger.error(`Validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
process.exit(1);
}
}
//# sourceMappingURL=validate.js.map