structure-validation
Version:
A Node.js CLI tool for validating codebase folder and file structure using a clean declarative configuration. Part of the guardz ecosystem for comprehensive TypeScript development.
120 lines • 4.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProgressIndicator = void 0;
const chalk_1 = __importDefault(require("chalk"));
/**
* Infrastructure service for displaying progress indicators
*/
class ProgressIndicator {
constructor() {
this.startTime = 0;
this.totalFiles = 0;
this.processedFiles = 0;
this.isActive = false;
}
/**
* Start progress tracking
*/
start(totalFiles, operation) {
this.totalFiles = totalFiles;
this.processedFiles = 0;
this.startTime = Date.now();
this.isActive = true;
console.log(chalk_1.default.blue(`🔄 ${operation} (${totalFiles} files)`));
this.updateProgress();
}
/**
* Update progress
*/
update(increment = 1) {
if (!this.isActive)
return;
this.processedFiles += increment;
this.updateProgress();
}
/**
* Complete progress tracking
*/
complete() {
if (!this.isActive)
return;
this.processedFiles = this.totalFiles;
this.updateProgress();
const duration = Date.now() - this.startTime;
const filesPerSecond = (this.totalFiles / (duration / 1000)).toFixed(1);
console.log(chalk_1.default.green(`✅ Completed in ${duration}ms (${filesPerSecond} files/sec)`));
console.log('');
this.isActive = false;
}
/**
* Update the progress display
*/
updateProgress() {
if (!this.isActive)
return;
const percentage = Math.round((this.processedFiles / this.totalFiles) * 100);
const progressBar = this.createProgressBar(percentage);
const elapsed = Date.now() - this.startTime;
// Clear the current line and update progress
process.stdout.write(`\r${chalk_1.default.blue('🔄')} ${progressBar} ${percentage}% (${this.processedFiles}/${this.totalFiles}) - ${elapsed}ms`);
}
/**
* Create a visual progress bar
*/
createProgressBar(percentage) {
const barLength = 20;
const filledLength = Math.round((percentage / 100) * barLength);
const emptyLength = barLength - filledLength;
const filled = '█'.repeat(filledLength);
const empty = '░'.repeat(emptyLength);
return `[${filled}${empty}]`;
}
/**
* Show a simple spinner for operations without known total
*/
showSpinner(message) {
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
let frameIndex = 0;
const interval = setInterval(() => {
if (!this.isActive) {
clearInterval(interval);
return;
}
const frame = frames[frameIndex];
process.stdout.write(`\r${chalk_1.default.blue(frame)} ${message}`);
frameIndex = (frameIndex + 1) % frames.length;
}, 80);
}
/**
* Stop spinner
*/
stopSpinner() {
this.isActive = false;
process.stdout.write('\r' + ' '.repeat(50) + '\r'); // Clear the line
}
/**
* Show file discovery progress
*/
showFileDiscovery() {
console.log(chalk_1.default.blue('🔍 Discovering files...'));
}
/**
* Show validation progress
*/
showValidationProgress(current, total) {
const percentage = Math.round((current / total) * 100);
const progressBar = this.createProgressBar(percentage);
process.stdout.write(`\r${chalk_1.default.yellow('⚡')} Validating ${progressBar} ${percentage}% (${current}/${total})`);
}
/**
* Show git operations progress
*/
showGitProgress(operation) {
console.log(chalk_1.default.blue(`🔧 ${operation}...`));
}
}
exports.ProgressIndicator = ProgressIndicator;
//# sourceMappingURL=ProgressIndicator.js.map