UNPKG

veriqa

Version:

šŸŽÆ Smart Manual QA Test Advisor with AI-Powered Regression Suggestions and Advanced Git Integration

142 lines (118 loc) • 4.19 kB
const { execSync } = require('child_process'); const chalk = require('chalk'); /** * UpdateChecker - Check for updates and notify users */ class UpdateChecker { constructor() { try { this.currentVersion = require('../../package.json').version; } catch (error) { this.currentVersion = '3.0.2'; // fallback version } this.packageName = 'veriqa'; } async checkForUpdates() { try { const latestVersion = await this.getLatestVersion(); if (this.isNewerVersion(latestVersion, this.currentVersion)) { this.showUpdateNotification(latestVersion); return true; } return false; } catch (error) { // Silent fail - don't interrupt user workflow return false; } } async getLatestVersion() { try { const result = execSync(`npm view ${this.packageName} version`, { encoding: 'utf8', stdio: 'pipe' }); return result.trim(); } catch (error) { throw new Error('Could not check for updates'); } } isNewerVersion(latest, current) { const latestParts = latest.split('.').map(Number); const currentParts = current.split('.').map(Number); for (let i = 0; i < 3; i++) { if (latestParts[i] > currentParts[i]) return true; if (latestParts[i] < currentParts[i]) return false; } return false; } showUpdateNotification(latestVersion) { console.log(chalk.yellow('\n' + '═'.repeat(60))); console.log(chalk.yellow('šŸ“¦ VeriQA Update Available!')); console.log(chalk.gray(`Current: v${this.currentVersion}`)); console.log(chalk.green(`Latest: v${latestVersion}`)); console.log(chalk.cyan('\nšŸš€ To upgrade:')); console.log(chalk.white(' npm update -g veriqa')); console.log(chalk.gray('\nšŸ’” Or reinstall:')); console.log(chalk.white(' npm uninstall -g veriqa && npm install -g veriqa@latest')); console.log(chalk.yellow('═'.repeat(60) + '\n')); } async autoUpgrade() { try { console.log(chalk.yellow('šŸ”„ Upgrading VeriQA to latest version...')); execSync('npm update -g veriqa', { stdio: 'inherit' }); console.log(chalk.green('āœ… VeriQA upgraded successfully!')); return true; } catch (error) { console.log(chalk.red('āŒ Auto-upgrade failed. Please run:')); console.log(chalk.white(' npm update -g veriqa')); return false; } } detectOldVersion() { try { // Check if old veriqa config exists const fs = require('fs'); const path = require('path'); const oldConfig = path.join(process.cwd(), '.veriqa-config.json'); if (fs.existsSync(oldConfig)) { console.log(chalk.yellow('\nšŸ”„ VeriQA v2.x configuration detected!')); console.log(chalk.cyan('šŸ“ Migration will automatically update your config.')); return true; } return false; } catch (error) { return false; } } migrateOldConfig() { try { const fs = require('fs'); const path = require('path'); const oldConfig = path.join(process.cwd(), '.veriqa-config.json'); const newConfig = path.join(process.cwd(), '.veriqa.json'); if (fs.existsSync(oldConfig) && !fs.existsSync(newConfig)) { // Copy old config to new format const oldData = JSON.parse(fs.readFileSync(oldConfig, 'utf8')); const newData = { ...oldData, version: this.currentVersion, migrated: true, migrationDate: new Date().toISOString() }; fs.writeFileSync(newConfig, JSON.stringify(newData, null, 2)); console.log(chalk.green('āœ… Configuration migrated successfully!')); // Backup old config fs.renameSync(oldConfig, `${oldConfig}.backup`); console.log(chalk.gray('šŸ“„ Old config backed up as .veriqa-config.json.backup')); return true; } return false; } catch (error) { console.log(chalk.yellow('āš ļø Manual config migration may be needed')); return false; } } } module.exports = UpdateChecker;