@lenne.tech/cli
Version:
lenne.Tech CLI: lt
77 lines (76 loc) • 3.09 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
/**
* Get the version that a new CLI process would use by running 'lt --version'.
* This is the most reliable way to check if the update was successful,
* as it tests the actual behavior of a new process.
*/
function getNewProcessVersion() {
try {
const result = (0, child_process_1.execSync)('lt --version', {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
});
return result.trim();
}
catch (_a) {
return null;
}
}
/**
* Update @lenne.tech/cli
*/
const NewCommand = {
alias: ['up'],
description: 'Update @lenne.tech/cli',
hidden: false,
name: 'update',
run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () {
// Retrieve the tools we need
const { helper, meta, print: { info, warning }, runtime: { brand }, } = toolbox;
// Store version before update
const versionBefore = meta.version();
// Update cli and show process
yield helper.updateCli({ showInfos: true });
// Check what version a new process would use
const newProcessVersion = getNewProcessVersion();
// Check if update was successful and version changed
if (newProcessVersion && newProcessVersion !== versionBefore) {
info('');
info(`Update successful: ${versionBefore} → ${newProcessVersion}`);
info('');
const shell = process.env.SHELL || '';
if (shell.includes('zsh')) {
info(`To use the new version, run 'rehash' or open a new terminal.`);
}
else if (shell.includes('bash')) {
info(`To use the new version, run 'hash -r' or open a new terminal.`);
}
else {
info(`To use the new version, open a new terminal.`);
}
}
else if (newProcessVersion === versionBefore) {
info('');
info(`CLI is already up to date (${versionBefore}).`);
}
else {
// Could not verify update
warning('');
warning(`Could not verify update. Please run 'lt --version' to check.`);
}
// For tests
return `updated ${brand}`;
}),
};
exports.default = NewCommand;