@unito/integration-cli
Version:
Integration CLI
73 lines (72 loc) • 2.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const child_process_1 = tslib_1.__importDefault(require("child_process"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const baseCommand_1 = require("../baseCommand");
const errors_1 = require("../errors");
class Upgrade extends baseCommand_1.BaseCommand {
static description = 'Upgrade the CLI';
static examples = ['<%= config.bin %> <%= command.id %>'];
/* istanbul ignore next */
async catch(error) {
if ((0, errors_1.handleError)(this, error)) {
this.exit(-1);
}
throw error;
}
async run() {
//
// Global command options
//
const packageName = '@unito/integration-cli';
const execOptions = { env: { ...process.env } };
const npmOptions = ['--global'].join(' ');
//
// Current version
//
core_1.ux.action.start('Checking the current version', undefined, { stdout: true });
const currentVersion = child_process_1.default
.execSync(`npm list ${npmOptions} --depth 0 | grep ${packageName} | sed "s/.*@\\([^@]*\\)$/\\1/"`, execOptions)
.toString()
.trim();
core_1.ux.action.stop(currentVersion);
//
// Next version
//
core_1.ux.action.start('Checking the available version', undefined, { stdout: true });
const newVersion = child_process_1.default
.execSync(`npm show ${npmOptions} ${packageName} version`, execOptions)
.toString()
.trim();
core_1.ux.action.stop(newVersion);
//
// Latest version
//
const latestVersion = currentVersion === newVersion;
if (latestVersion) {
core_1.ux.log(chalk_1.default.yellowBright("You already have the latest version but let's make sure it is working properly!"));
}
//
// Validate / Upgrade the package globally.
//
core_1.ux.action.start(`${latestVersion ? 'Validating' : 'Upgrading'} the package`, undefined, { stdout: true });
// To make sure we have a clean version of the CLI, with updated packages, we force the re-installation.
child_process_1.default.execSync(`npm install --force ${npmOptions} ${packageName}`, {
...execOptions,
stdio: ['ignore', 'ignore', 'inherit'],
});
core_1.ux.action.stop();
//
// Validated / Upgraded.
//
if (latestVersion) {
core_1.ux.log(chalk_1.default.greenBright(`The CLI is valid! Enjoy!`));
}
else {
core_1.ux.log(chalk_1.default.greenBright(`Upgraded from ${currentVersion} to ${newVersion}! Enjoy!`));
}
}
}
exports.default = Upgrade;