veriqa
Version:
šÆ Smart Manual QA Test Advisor with AI-Powered Regression Suggestions and Advanced Git Integration
142 lines (118 loc) ⢠4.19 kB
JavaScript
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;