UNPKG

smartui-migration-tool

Version:

Enterprise-grade CLI tool for migrating visual testing platforms to LambdaTest SmartUI

111 lines • 6.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const chalk_1 = __importDefault(require("chalk")); const child_process_1 = require("child_process"); class Update extends core_1.Command { async run() { const { flags } = await this.parse(Update); const packageJson = require('../../package.json'); const currentVersion = packageJson.version; console.log(chalk_1.default.cyan.bold('šŸ”„ SmartUI Migration Tool - Update\n')); console.log(chalk_1.default.white(`Current version: ${chalk_1.default.green.bold(currentVersion)}\n`)); try { // Check for updates console.log(chalk_1.default.yellow('šŸ” Checking for updates...')); const latestVersion = (0, child_process_1.execSync)('npm view smartui-migration-tool version', { encoding: 'utf8', stdio: 'pipe' }).trim(); console.log(chalk_1.default.white(`Latest version: ${chalk_1.default.green.bold(latestVersion)}\n`)); if (latestVersion === currentVersion && !flags.force) { console.log(chalk_1.default.green('āœ… You are already running the latest version!')); if (!flags.check) { console.log(chalk_1.default.cyan('\nšŸ’” To force update, run: smartui-migrator update --force')); } return; } if (flags.check) { console.log(chalk_1.default.yellow('šŸ“¦ Update available!')); console.log(chalk_1.default.cyan('\nšŸ’” To install the update, run: smartui-migrator update')); return; } // Perform the update console.log(chalk_1.default.yellow('šŸ“¦ Updating SmartUI Migration Tool...\n')); // Check if running as root (not recommended) if (process.getuid && process.getuid() === 0) { console.log(chalk_1.default.yellow('āš ļø Warning: Running as root. This is not recommended.')); console.log(chalk_1.default.gray(' Consider using a Node.js version manager like nvm.\n')); } // Update the package console.log(chalk_1.default.blue('šŸ”„ Installing latest version...')); (0, child_process_1.execSync)('npm update -g smartui-migration-tool', { stdio: 'inherit', encoding: 'utf8' }); // Verify the update console.log(chalk_1.default.blue('\nšŸ” Verifying installation...')); const newVersion = (0, child_process_1.execSync)('smartui-migrator version', { encoding: 'utf8', stdio: 'pipe' }).match(/Version: (.+)/)?.[1]?.trim(); if (newVersion && newVersion !== currentVersion) { console.log(chalk_1.default.green('\nāœ… Update successful!')); console.log(chalk_1.default.white(` Previous version: ${chalk_1.default.gray(currentVersion)}`)); console.log(chalk_1.default.white(` New version: ${chalk_1.default.green.bold(newVersion)}`)); // Show what's new console.log(chalk_1.default.cyan('\nšŸŽ‰ What\'s new in this version:')); console.log(chalk_1.default.white(' • Enhanced package.json transformation')); console.log(chalk_1.default.white(' • Improved CI/CD pipeline migration')); console.log(chalk_1.default.white(' • Better error handling and logging')); console.log(chalk_1.default.white(' • New CLI commands and improved UX')); console.log(chalk_1.default.cyan('\nšŸ’” To get started, run: smartui-migrator')); } else { console.log(chalk_1.default.yellow('\nāš ļø Update completed, but version verification failed')); console.log(chalk_1.default.gray(' The tool may have been updated successfully')); console.log(chalk_1.default.cyan('\nšŸ’” Try running: smartui-migrator version')); } } catch (error) { console.error(chalk_1.default.red('\nāŒ Update failed:')); if (error instanceof Error) { if (error.message.includes('EACCES')) { console.error(chalk_1.default.red(' Permission denied. Try running with sudo or use a Node.js version manager.')); console.error(chalk_1.default.cyan('\nšŸ’” Alternative: npm install -g smartui-migration-tool@latest')); } else if (error.message.includes('ENOTFOUND') || error.message.includes('network')) { console.error(chalk_1.default.red(' Network error. Check your internet connection.')); console.error(chalk_1.default.cyan('\nšŸ’” Try again later or check npm registry status.')); } else { console.error(chalk_1.default.red(` ${error.message}`)); } } else { console.error(chalk_1.default.red(' Unknown error occurred')); } console.error(chalk_1.default.cyan('\nšŸ’” For manual update: npm install -g smartui-migration-tool@latest')); this.exit(1); } } } Update.description = 'Update SmartUI Migration Tool to the latest version'; Update.flags = { help: core_1.Flags.help({ char: 'h' }), force: core_1.Flags.boolean({ char: 'f', description: 'Force update even if already on latest version', default: false, }), check: core_1.Flags.boolean({ char: 'c', description: 'Only check for updates without installing', default: false, }), }; exports.default = Update; //# sourceMappingURL=update.js.map