@mintlify/cli
Version:
The Mintlify CLI
69 lines (68 loc) • 3.18 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());
});
};
import { jsx as _jsx } from "react/jsx-runtime";
import { getTargetMintVersion, downloadTargetMint, SpinnerLog, SuccessLog, ErrorLog, addLog, clearLogs, } from '@mintlify/previewing';
import { execAsync, getLatestCliVersion, getVersions } from './helpers.js';
export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packageName, silent, }) {
if (!silent) {
addLog(_jsx(SpinnerLog, { message: "updating..." }));
}
const { cli: existingCliVersion, client: existingClientVersion } = getVersions();
const latestCliVersion = getLatestCliVersion(packageName);
const latestClientVersion = yield getTargetMintVersion();
const isUpToDate = existingCliVersion &&
existingClientVersion &&
latestClientVersion &&
latestCliVersion &&
latestCliVersion.trim() === existingCliVersion.trim() &&
latestClientVersion.trim() === existingClientVersion.trim();
if (isUpToDate) {
if (!silent) {
addLog(_jsx(SuccessLog, { message: "already up to date" }));
}
return;
}
if (existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
try {
if (!silent) {
clearLogs();
addLog(_jsx(SpinnerLog, { message: `updating ${packageName} package...` }));
}
yield execAsync(`npm install -g ${packageName}@latest --silent`);
}
catch (err) {
if (!silent) {
addLog(_jsx(ErrorLog, { message: `failed to update ${packageName}@latest` }));
}
return;
}
}
if (latestClientVersion && latestClientVersion !== existingClientVersion) {
try {
if (!silent) {
addLog(_jsx(SpinnerLog, { message: `updating mintlify client to ${latestClientVersion}...` }));
}
yield downloadTargetMint({
targetVersion: latestClientVersion,
existingVersion: existingClientVersion !== null && existingClientVersion !== void 0 ? existingClientVersion : null,
});
}
catch (err) {
if (!silent) {
addLog(_jsx(ErrorLog, { message: `failed to update mintlify client to ${latestClientVersion}` }));
}
return;
}
}
if (!silent) {
clearLogs();
addLog(_jsx(SuccessLog, { message: `updated ${packageName} to the latest version: ${latestCliVersion}` }));
}
});