UNPKG

@mintlify/cli

Version:

The Mintlify CLI

42 lines (41 loc) 2.27 kB
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 { SpinnerLog, SuccessLog, ErrorLog, addLog, clearLogs } from '@mintlify/previewing'; import { execAsync, getLatestCliVersion, getVersions, detectPackageManager } from './helpers.js'; export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packageName }) { addLog(_jsx(SpinnerLog, { message: "updating..." })); const { cli: existingCliVersion } = getVersions(); const latestCliVersion = getLatestCliVersion(packageName); const isUpToDate = existingCliVersion && latestCliVersion && latestCliVersion.trim() === existingCliVersion.trim(); if (isUpToDate) { addLog(_jsx(SuccessLog, { message: "already up to date" })); return; } if (existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) { try { clearLogs(); addLog(_jsx(SpinnerLog, { message: `updating ${packageName} package...` })); const packageManager = yield detectPackageManager({ packageName }); if (packageManager === 'pnpm') { yield execAsync(`pnpm install -g ${packageName}@latest --silent`); } else { yield execAsync(`npm install -g ${packageName}@latest --silent`); } } catch (err) { addLog(_jsx(ErrorLog, { message: `failed to update ${packageName}@latest` })); return; } } clearLogs(); addLog(_jsx(SuccessLog, { message: `updated ${packageName} to the latest version: ${latestCliVersion}` })); });