smartui-migration-tool
Version:
Enterprise-grade CLI tool for migrating visual testing platforms to LambdaTest SmartUI
344 lines • 13.2 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIPolish = void 0;
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
class UIPolish {
constructor(verbose = false) {
this.currentSpinner = null;
this.verbose = verbose;
}
/**
* Enhanced progress spinner with better styling
*/
createProgressSpinner(options) {
const spinnerOptions = {
text: options.text,
spinner: options.spinner || 'dots',
color: options.color || 'blue',
interval: options.interval || 100
};
const spinner = (0, ora_1.default)(spinnerOptions);
this.currentSpinner = spinner;
return spinner;
}
/**
* Enhanced success message with styling
*/
showSuccess(message, details) {
console.log(chalk_1.default.green.bold('✅'), chalk_1.default.white.bold(message));
if (details && details.length > 0) {
details.forEach(detail => {
console.log(chalk_1.default.gray(` ${detail}`));
});
}
}
/**
* Enhanced error message with styling
*/
showError(message, details) {
console.log(chalk_1.default.red.bold('❌'), chalk_1.default.white.bold(message));
if (details && details.length > 0) {
details.forEach(detail => {
console.log(chalk_1.default.red(` ${detail}`));
});
}
}
/**
* Enhanced warning message with styling
*/
showWarning(message, details) {
console.log(chalk_1.default.yellow.bold('⚠️'), chalk_1.default.white.bold(message));
if (details && details.length > 0) {
details.forEach(detail => {
console.log(chalk_1.default.yellow(` ${detail}`));
});
}
}
/**
* Enhanced info message with styling
*/
showInfo(message, details) {
console.log(chalk_1.default.blue.bold('ℹ️'), chalk_1.default.white.bold(message));
if (details && details.length > 0) {
details.forEach(detail => {
console.log(chalk_1.default.gray(` ${detail}`));
});
}
}
/**
* Create a beautiful table
*/
createTable(options) {
const { headers, rows, columnWidths, alignment, colors } = options;
// Calculate column widths if not provided
const widths = columnWidths || this.calculateColumnWidths(headers, rows);
const alignments = alignment || headers.map(() => 'left');
const headerColors = colors || headers.map(() => 'white');
// Create separator line
const separator = '─'.repeat(widths.reduce((sum, width) => sum + width + 3, 0));
// Print header
console.log(chalk_1.default.gray('┌' + separator + '┐'));
let headerRow = '│';
headers.forEach((header, index) => {
const paddedHeader = this.padText(header, widths[index] || header.length, alignments[index] || 'left');
const colorName = headerColors[index] || 'white';
let coloredHeader;
if (colorName === 'white') {
coloredHeader = chalk_1.default.white(paddedHeader);
}
else if (colorName === 'red') {
coloredHeader = chalk_1.default.red(paddedHeader);
}
else if (colorName === 'green') {
coloredHeader = chalk_1.default.green(paddedHeader);
}
else if (colorName === 'blue') {
coloredHeader = chalk_1.default.blue(paddedHeader);
}
else if (colorName === 'yellow') {
coloredHeader = chalk_1.default.yellow(paddedHeader);
}
else {
coloredHeader = chalk_1.default.white(paddedHeader);
}
headerRow += ` ${chalk_1.default.bold(coloredHeader)} │`;
});
console.log(headerRow);
console.log(chalk_1.default.gray('├' + separator + '┤'));
// Print rows
rows.forEach((row, rowIndex) => {
let rowText = '│';
row.forEach((cell, cellIndex) => {
const paddedCell = this.padText(cell, widths[cellIndex] || cell.length, alignments[cellIndex] || 'left');
const cellColor = colors && colors[cellIndex] ? colors[cellIndex] : 'white';
let coloredCell;
if (cellColor === 'white') {
coloredCell = chalk_1.default.white(paddedCell);
}
else if (cellColor === 'red') {
coloredCell = chalk_1.default.red(paddedCell);
}
else if (cellColor === 'green') {
coloredCell = chalk_1.default.green(paddedCell);
}
else if (cellColor === 'blue') {
coloredCell = chalk_1.default.blue(paddedCell);
}
else if (cellColor === 'yellow') {
coloredCell = chalk_1.default.yellow(paddedCell);
}
else {
coloredCell = chalk_1.default.white(paddedCell);
}
rowText += ` ${coloredCell} │`;
});
console.log(rowText);
});
console.log(chalk_1.default.gray('└' + separator + '┘'));
}
/**
* Create a progress bar
*/
createProgressBar(total, current, text) {
const percentage = Math.round((current / total) * 100);
const filled = Math.round((current / total) * 20);
const empty = 20 - filled;
const bar = '█'.repeat(filled) + '░'.repeat(empty);
const progressText = `${text} |${bar}| ${percentage}% (${current}/${total})`;
process.stdout.write(`\r${chalk_1.default.blue(progressText)}`);
if (current === total) {
process.stdout.write('\n');
}
}
/**
* Create a section header
*/
createSectionHeader(title, subtitle) {
console.log('\n' + chalk_1.default.blue.bold('='.repeat(60)));
console.log(chalk_1.default.blue.bold(` ${title}`));
if (subtitle) {
console.log(chalk_1.default.gray(` ${subtitle}`));
}
console.log(chalk_1.default.blue.bold('='.repeat(60)));
}
/**
* Create a feature list
*/
createFeatureList(features, title = 'Features') {
console.log(chalk_1.default.blue.bold(`\n${title}:`));
features.forEach((feature, index) => {
console.log(chalk_1.default.gray(` ${index + 1}.`), chalk_1.default.white(feature));
});
}
/**
* Create a status summary
*/
createStatusSummary(stats) {
const { total, completed, failed, warnings } = stats;
const successRate = total > 0 ? Math.round((completed / total) * 100) : 0;
console.log(chalk_1.default.blue.bold('\n📊 Status Summary:'));
console.log(chalk_1.default.green(` ✅ Completed: ${completed}/${total} (${successRate}%)`));
if (failed > 0) {
console.log(chalk_1.default.red(` ❌ Failed: ${failed}`));
}
if (warnings > 0) {
console.log(chalk_1.default.yellow(` ⚠️ Warnings: ${warnings}`));
}
}
/**
* Create a loading animation
*/
createLoadingAnimation(text, duration = 2000) {
return new Promise((resolve) => {
const spinner = this.createProgressSpinner({ text });
spinner.start();
setTimeout(() => {
spinner.stop();
resolve();
}, duration);
});
}
/**
* Create a countdown timer
*/
createCountdown(seconds, text = 'Starting in') {
return new Promise((resolve) => {
let remaining = seconds;
const interval = setInterval(() => {
process.stdout.write(`\r${chalk_1.default.yellow(`${text}: ${remaining}s`)}`);
remaining--;
if (remaining < 0) {
clearInterval(interval);
process.stdout.write('\n');
resolve();
}
}, 1000);
});
}
/**
* Create a confirmation prompt with styling
*/
createConfirmationPrompt(question, defaultValue = true) {
const defaultText = defaultValue ? 'Y/n' : 'y/N';
const prompt = `${chalk_1.default.blue.bold('?')} ${chalk_1.default.white(question)} ${chalk_1.default.gray(`(${defaultText})`)}`;
return prompt;
}
/**
* Create a file tree display
*/
createFileTree(files, rootPath = '') {
console.log(chalk_1.default.blue.bold('\n📁 File Structure:'));
const tree = this.buildFileTree(files, rootPath);
this.printFileTree(tree, '');
}
/**
* Create a performance summary
*/
createPerformanceSummary(metrics) {
console.log(chalk_1.default.blue.bold('\n⚡ Performance Summary:'));
console.log(chalk_1.default.white(` Operations: ${metrics.totalOperations}`));
console.log(chalk_1.default.white(` Average Duration: ${metrics.averageDuration}ms`));
console.log(chalk_1.default.white(` Memory Usage: ${metrics.totalMemoryUsage}KB`));
console.log(chalk_1.default.white(` Cache Size: ${metrics.cacheStats.size} entries`));
console.log(chalk_1.default.white(` Cache Hit Rate: ${metrics.cacheStats.hitRate}%`));
}
// Private methods
calculateColumnWidths(headers, rows) {
const widths = [];
headers.forEach((header, index) => {
let maxWidth = header.length;
rows.forEach(row => {
if (row[index]) {
maxWidth = Math.max(maxWidth, row[index].length);
}
});
widths.push(Math.min(maxWidth + 2, 50)); // Cap at 50 characters
});
return widths;
}
padText(text, width, alignment) {
if (text.length >= width) {
return text.substring(0, width - 3) + '...';
}
const padding = width - text.length;
switch (alignment) {
case 'center':
const leftPad = Math.floor(padding / 2);
const rightPad = padding - leftPad;
return ' '.repeat(leftPad) + text + ' '.repeat(rightPad);
case 'right':
return ' '.repeat(padding) + text;
default: // left
return text + ' '.repeat(padding);
}
}
buildFileTree(files, rootPath) {
const tree = {};
files.forEach(file => {
const relativePath = rootPath ? file.replace(rootPath + '/', '') : file;
const parts = relativePath.split('/');
let current = tree;
parts.forEach((part, index) => {
if (index === parts.length - 1) {
current[part] = 'file';
}
else {
if (!current[part]) {
current[part] = {};
}
current = current[part];
}
});
});
return tree;
}
printFileTree(tree, prefix) {
const keys = Object.keys(tree).sort();
keys.forEach((key, index) => {
const isLast = index === keys.length - 1;
const connector = isLast ? '└── ' : '├── ';
const nextPrefix = prefix + (isLast ? ' ' : '│ ');
if (tree[key] === 'file') {
console.log(prefix + connector + chalk_1.default.white(key));
}
else {
console.log(prefix + connector + chalk_1.default.blue(key) + '/');
this.printFileTree(tree[key], nextPrefix);
}
});
}
/**
* Stop current spinner
*/
stopSpinner() {
if (this.currentSpinner) {
this.currentSpinner.stop();
this.currentSpinner = null;
}
}
/**
* Clear screen
*/
clearScreen() {
console.clear();
}
/**
* Create a banner
*/
createBanner(text) {
const banner = `
╔══════════════════════════════════════════════════════════════╗
║ ║
║ ${text.padEnd(58)} ║
║ ║
╚══════════════════════════════════════════════════════════════╝
`;
console.log(chalk_1.default.blue.bold(banner));
}
}
exports.UIPolish = UIPolish;
//# sourceMappingURL=UIPolish.js.map
;