UNPKG

@cto.ai/ops

Version:

šŸ’» CTO.ai Ops - The CLI built for Teams šŸš€

72 lines (71 loc) • 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const sdk_1 = require("@cto.ai/sdk"); const util = require('util'); const exec = util.promisify(require('child_process').exec); const base_1 = tslib_1.__importStar(require("../base")); const get_latest_version_1 = require("../utils/get-latest-version"); const CustomErrors_1 = require("../errors/CustomErrors"); class Update extends base_1.default { async run() { this.parse(Update); try { const latestVersion = await get_latest_version_1.getLatestVersion(); await this.logUpdateMessage(latestVersion); await this.askQuestion(); await this.updateVersion(); await this.trackAnalytics(latestVersion); } catch (err) { this.debug('%O', err); this.config.runHook('error', { err, accessToken: this.accessToken }); } } async logUpdateMessage(latestVersion) { this.log(`${sdk_1.ux.colors.white(`\nšŸ“¦ ${sdk_1.ux.colors.actionBlue('INSTALL UPDATE?')} - You're about to update to ${sdk_1.ux.colors.callOutCyan(`CTO.ai Ops CLI ${latestVersion}`)} ${sdk_1.ux.colors.reset.green('→')}`)}`); } async trackAnalytics(newVersion) { if (this.user) { await this.services.analytics.track({ userId: this.user.email, teamId: this.team.id, cliEvent: 'Ops CLI Update', event: 'Ops CLI Update', properties: { oldVersion: this.config.version, newVersion, }, }, this.accessToken); } } async askQuestion() { const { install } = await sdk_1.ux.prompt({ type: 'confirm', name: 'install', message: `\n${sdk_1.ux.colors.white('Install update?')}`, }); this.log(''); if (!install) { this.log(`${sdk_1.ux.colors.errorRed('āŒ Update cancelled')} ${sdk_1.ux.colors.white("- Let us know when you're ready for some sweet, sweet, updates.")}`); process.exit(); } } async updateVersion() { try { sdk_1.ux.spinner.start('Updating version'); await exec('npm install -g @cto.ai/ops'); sdk_1.ux.spinner.stop('Done!'); } catch (err) { this.debug('%O', err); sdk_1.ux.spinner.stop('Failed'); throw new CustomErrors_1.PermissionsError(err); } } } exports.default = Update; Update.description = 'Update the Ops CLI.'; Update.flags = { help: base_1.flags.help({ char: 'h' }), };