alwaysai
Version:
The alwaysAI command-line interface (CLI)
80 lines • 2.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkForUpdatesAndPrompt = void 0;
const boxen = require("boxen");
const chalk = require("chalk");
const environment_1 = require("../../environment");
const infrastructure_1 = require("../../infrastructure");
const util_1 = require("../../util");
const version_1 = require("../../version");
const appPrompt = 'Please open the alwaysAI Desktop app to update. ';
const npmPrompt = "Please run 'npm install -g alwaysai' to update. ";
const updatePrompt = `A new version of the CLI is available! \n\n`;
async function getManifest(manifestName) {
let bucket;
switch ((0, infrastructure_1.getSystemId)()) {
case 'development': {
bucket = 'alwaysai-artifacts-dev';
break;
}
case 'qa': {
bucket = 'alwaysai-artifacts-qa';
break;
}
case 'production':
case 'local':
default:
bucket = 'alwaysai-artifacts-prod';
}
const aaiCLIArtifactsURL = `https://${bucket}.s3.us-west-1.amazonaws.com/cli`;
const manifest = (await (0, util_1.downloadJson)(`${aaiCLIArtifactsURL}/${manifestName}`));
return manifest.version;
}
async function getLatestVersion() {
let latestVer = '';
try {
switch (environment_1.ALWAYSAI_OS_PLATFORM) {
case 'win32':
latestVer = await getManifest('cli-win.json');
break;
case 'darwin':
latestVer = await getManifest('cli-macos.json');
break;
case 'linux':
latestVer = await (0, util_1.getLatestVersionFromNpm)('alwaysai');
break;
default:
throw new Error(`Unsupported OS: ${environment_1.ALWAYSAI_OS_PLATFORM}`);
}
}
catch (error) {
util_1.logger.error((0, util_1.stringifyError)(error));
}
return latestVer;
}
function constructPrompt(props) {
const { CLIversion, latestVer } = props;
let platformPrompt = appPrompt;
if (environment_1.ALWAYSAI_OS_PLATFORM === 'linux') {
platformPrompt = npmPrompt;
}
const prompt = `${chalk.bold(updatePrompt)}${platformPrompt}\nYour version: ${CLIversion}. Newest version: ${latestVer}`;
return prompt;
}
async function checkForUpdatesAndPrompt() {
try {
const latestVersion = await getLatestVersion();
const CLIversion = version_1.version;
if (CLIversion !== latestVersion) {
(0, util_1.echo)(`${chalk.yellow(boxen(constructPrompt({
CLIversion,
latestVer: latestVersion
}), { borderStyle: 'round', textAlignment: 'center', padding: 1 }))}`);
}
}
catch (error) {
util_1.logger.error((0, util_1.stringifyError)(error));
}
}
exports.checkForUpdatesAndPrompt = checkForUpdatesAndPrompt;
//# sourceMappingURL=check-for-updates.js.map