deno.land / x / lume@v2.1.4 / cli / upgrade.ts
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485import { log } from "../core/utils/log.ts";import { getCurrentVersion, getLatestDevelopmentVersion, getLatestVersion,} from "../core/utils/lume_version.ts";import { readDenoConfig, updateLumeVersion, writeDenoConfig,} from "../core/utils/deno_config.ts";
interface Options { dev?: boolean; version?: string;}export default function ({ dev, version }: Options) { return upgrade(dev, version);}
/** Upgrade the Lume installation to the latest version */export async function upgrade(dev: boolean | string = false, version?: string) { const latest = version ? version : dev ? await getLatestDevelopmentVersion() : await getLatestVersion(); const url = getVersionUrl(latest, dev);
if (latest === getCurrentVersion()) { const message = version ? `You're already using this version of Lume:` : dev ? "You're using the latest version of Lume:" : "You're using the latest development version of Lume:";
log.info(`${message} <green>${latest}</green>`); return; }
log.info( version ? `Updating Lume to <green>${latest}</green>...` : `New version available. Updating Lume to <green>${latest}</green>...`, );
const denoConfig = await readDenoConfig();
if (!denoConfig) { throw new Error("No Deno config file found"); }
updateLumeVersion(url, denoConfig);
// Remove deno.lock file try { await Deno.remove("deno.lock"); } catch { // Ignore }
await writeDenoConfig(denoConfig);
log.info("Update successful!");
if (!dev) { log.info( `See the changes in <gray>https://github.com/lumeland/lume/blob/${latest}/CHANGELOG.md</gray>`, ); }}
function getVersionUrl(version: string, dev: boolean | string = false): URL { // Prepend automatically "v" to the version if it's missing if (!dev && !version.startsWith("v")) { version = `v${version}`; }
return new URL( dev ? `https://cdn.jsdelivr.net/gh/lumeland/lume@${version}/` : `https://deno.land/x/lume@${version}/`, );}
Version Info