UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

104 lines (103 loc) 4.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgressTracker = void 0; const ora_1 = __importDefault(require("ora")); const picocolors_1 = __importDefault(require("picocolors")); class ProgressTracker { constructor(stepDescriptions) { this.steps = stepDescriptions.map((description) => ({ description, completed: false, startTime: 0, duration: 0, })); this.currentStep = 0; this.startTime = 0; this.spinner = (0, ora_1.default)({ text: "Starting analysis...", color: "cyan", }); this.isCompleted = false; } getProgressBar(percentage) { const width = 30; const filledWidth = Math.round((percentage / 100) * width); const emptyWidth = width - filledWidth; return picocolors_1.default.cyan("█".repeat(filledWidth)) + picocolors_1.default.gray("░".repeat(emptyWidth)); } updateSpinnerText() { if (this.isCompleted) return; const completedSteps = Math.min(this.currentStep, this.steps.length); const percentage = Math.round((completedSteps / this.steps.length) * 100); if (this.currentStep < this.steps.length) { const progressBar = `[${this.getProgressBar(percentage)}] ${percentage}%`; const currentStepDescription = this.steps[this.currentStep].description; this.spinner.text = `${progressBar} - ${currentStepDescription}`; } } start() { if (this.isCompleted) return; console.log(picocolors_1.default.cyan(picocolors_1.default.bold("🚀 Analysis in Progress"))); this.startTime = Date.now(); this.steps[0].startTime = Date.now(); this.updateSpinnerText(); this.spinner.start(); } incrementProgress() { if (this.isCompleted || this.currentStep >= this.steps.length) return; // Complete current step this.steps[this.currentStep].completed = true; this.steps[this.currentStep].duration = Date.now() - this.steps[this.currentStep].startTime; const completedStep = this.steps[this.currentStep]; const duration = (completedStep.duration / 1000).toFixed(2); // Log the completed step above the spinner this.spinner.stop(); console.log(picocolors_1.default.green(`✓ ${completedStep.description} ${picocolors_1.default.gray(`(${duration}s)`)}`)); this.currentStep++; // Start next step if available if (this.currentStep < this.steps.length) { this.steps[this.currentStep].startTime = Date.now(); this.updateSpinnerText(); this.spinner.start(); } else { this.complete(); } } complete() { if (this.isCompleted) return; // Complete any remaining steps while (this.currentStep < this.steps.length) { this.steps[this.currentStep].completed = true; this.steps[this.currentStep].duration = Date.now() - (this.steps[this.currentStep].startTime || this.startTime); const completedStep = this.steps[this.currentStep]; const duration = (completedStep.duration / 1000).toFixed(2); console.log(picocolors_1.default.green(`✓ ${completedStep.description} ${picocolors_1.default.gray(`(${duration}s)`)}`)); this.currentStep++; } this.spinner.stop(); const totalDuration = ((Date.now() - this.startTime) / 1000).toFixed(2); console.log(picocolors_1.default.green(picocolors_1.default.bold(`✨ Analysis completed in ${totalDuration}s. Results saved to analysis-results.json`))); console.log(picocolors_1.default.cyan(`📤 You can now upload the JSON file to ${picocolors_1.default.bold("sicualabs.com")} for detailed insights and recommendations.`)); this.isCompleted = true; } getCurrentStep() { return this.currentStep; } getTotalSteps() { return this.steps.length; } getSteps() { return this.steps; } } exports.ProgressTracker = ProgressTracker;