UNPKG

@mintlify/previewing

Version:

Preview Mintlify docs locally

37 lines (36 loc) 2.15 kB
import { getLatestClientVersion, tryDownloadTargetMint, getCompatibleClientVersion } from "./client.js"; import { LOCAL_LINKED_CLI_VERSION } from "../constants.js"; export const silentUpdateClient = async ({ versionString, clientVersion, cliVersion }) => { const latestClientVersion = await getLatestClientVersion(); const hasLatestClientVersion = latestClientVersion && versionString && versionString.trim() === latestClientVersion.trim(); if (clientVersion) { // always download specific client version if provided const error = await tryDownloadTargetMint({ targetVersion: clientVersion, existingVersion: versionString }); return { needsUpdate: false, error }; } else if ((!versionString || cliVersion === LOCAL_LINKED_CLI_VERSION) && latestClientVersion) { // if no version exists, download latest const error = await tryDownloadTargetMint({ targetVersion: latestClientVersion, existingVersion: null }); return { needsUpdate: false, error }; } else if (cliVersion && !hasLatestClientVersion) { // if not on latest, check whether to download latest or max const maxClientVersion = await getCompatibleClientVersion({ cliVersion }); const hasMaxClientVersion = maxClientVersion && versionString && versionString.trim() === maxClientVersion.trim(); if (maxClientVersion === "latest" && latestClientVersion) { // if latest, download latest const error = await tryDownloadTargetMint({ targetVersion: latestClientVersion, existingVersion: versionString }); return { needsUpdate: false, error }; } else if (maxClientVersion && !hasMaxClientVersion) { // if maxxed out, needs update const error = await tryDownloadTargetMint({ targetVersion: maxClientVersion, existingVersion: versionString }); return { needsUpdate: true, error }; } else { // if compatible client version not found, needs update return { needsUpdate: true, error: undefined }; } } return { needsUpdate: false, error: undefined }; };