@cto.ai/ops-rc
Version:
š» CTO.ai Ops - The CLI built for Teams š
67 lines (66 loc) ⢠2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const sdk_1 = require("@cto.ai/sdk");
const util = tslib_1.__importStar(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) {
this.services.analytics.track('Ops CLI Update', {
username: this.user.username,
oldVersion: this.config.version,
newVersion,
}, this.state.config);
}
}
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' }),
};