UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

3 lines 1.99 kB
import{name as e,version as t}from"../../../packages/core/package.mjs";import{ensureLucidDirectoryExists as n}from"../../../utils/helpers/lucid-directory.mjs";import{readFile as r,writeFile as i}from"node:fs/promises";import{join as a}from"node:path";import o from"picocolors";import{existsSync as s}from"node:fs";import c from"boxen";import l from"semver";const u=async e=>{if(!s(e))return null;try{let t=await r(e,`utf-8`),n=JSON.parse(t),i=typeof n.checkedAt==`number`?n.checkedAt:null,a=typeof n.latestVersion==`string`||n.latestVersion===null?n.latestVersion:null,o=typeof n.currentVersion==`string`?n.currentVersion:null;return i===null||o===null?null:{checkedAt:i,latestVersion:a,currentVersion:o}}catch{return null}},d=async(e,t)=>{await i(e,JSON.stringify(t,null,2),`utf-8`)},f=async e=>{try{return(await(await fetch(`https://registry.npmjs.org/${e}/latest`)).json()).version}catch{return null}},p=t=>{if(!t.show||!t.available)return;let{currentVersion:n,latestVersion:r}=t,i=[`Current: ${o.yellow(n)}`,`Latest: ${o.green(r??`unknown`)}`],a=o.cyan(`npm install ${e}@latest`),s=c([`A new version of Lucid CMS is available!`,``,...i,``,`Run ${a} to update`,``,o.dim(`View the changelog: `)+o.cyan(`https://github.com/buildlucid/lucid-cms/releases`),o.dim(`Remember to back up your database before updating or running migrations.`)].join(` `),{padding:1,margin:1,borderStyle:`round`,borderColor:`yellow`,title:`Update Available`,titleAlignment:`left`});console.log(s)},m=async()=>{let r=a(await n(),`update-available.json`),i=await u(r),o=Date.now(),s=t,c=!i||i.currentVersion!==s,m=i?o-i.checkedAt<864e5&&!c:!1,h=m?i?.latestVersion??null:null;m||(h=await f(e),await d(r,{checkedAt:o,latestVersion:h,currentVersion:s}));let g=h&&l.valid(h)&&l.valid(s)?l.gt(h,s):!1;return{available:g,show:!m&&g,latestVersion:h,currentVersion:s,renderUpdateBox:()=>p({available:g,show:!m&&g,latestVersion:h,currentVersion:s})}};export{m as default}; //# sourceMappingURL=update-available.mjs.map