UNPKG

@lucidcms/core

Version:

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

2 lines 4.09 kB
import e from"../../../constants/constants.mjs";import{startLoggerBuffering as t,stopLoggerBuffering as n}from"../../logger/index.mjs";import{writeTranslationArtifact as r}from"../../i18n/prepare-translations.mjs";import{createTranslator as i}from"../../i18n/translate.mjs";import a from"../logger.mjs";import o from"../../compile/load-build-project.mjs";import s from"../../compile/prepare-build-artifacts.mjs";import c from"../../plugins/check-all-plugins-compatibility.mjs";import l from"../../email/templates/prepare-email-templates.mjs";import u from"../../vite/index.mjs";import d from"../services/calculate-outdir-size.mjs";import f from"../services/copy-public-assets.mjs";import{mkdir as p,readdir as m,rm as h,stat as g}from"node:fs/promises";import _,{join as v}from"node:path";const y=async m=>{t();let g=a.startTimer(),v=m?.silent??!1;try{let{configPath:t,loaded:y}=await o({silent:v,loadEmailTemplates:!1,prepareRuntime:!0}),x=i({store:y.translationStore,locale:`en`}),S=y.adapter,C=S.cli;C||(a.error(`Lucid could not load CLI handlers from the "${y.adapter.key}" runtime adapter.`,{silent:v}),await n(),process.exit(1)),await c({runtimeContext:y.runtimeContext,config:y.config}),m?.cacheSpa?await b(y.config.build.paths.outDir):(await h(y.config.build.paths.outDir,{recursive:!0,force:!0}),await p(y.config.build.paths.outDir));let w=_.relative(process.cwd(),t);a.info(`Loaded config from:`,a.color.green(`./${w}`),{silent:v});let T=_.relative(y.config.build.paths.outDir,t).replace(/\.ts$/,`.js`);await r({translationStore:y.translationStore,outputPath:y.config.build.paths.outDir});let[E,D]=await Promise.all([l({config:y.config,silent:v,verbose:!0}),f({config:y.config,silent:v,verbose:!0})]);E.error&&(a.error(x.english(E.error.message)??`Failed to prepare email templates`,{silent:v}),await n(),process.exit(1)),D.error&&(a.error(x.english(D.error.message)??`Failed to copy public assets`,{silent:v}),await n(),process.exit(1));let O=y.translationStore,k=await s({config:y.config,translationStore:O,definition:y.definition,silent:v,configPath:t,outputPath:y.config.build.paths.outDir,outputRelativeConfigPath:T,customArtifactTypes:S.config?.customBuildArtifacts}),[A,j]=await Promise.all([u.buildApp(y.config),C.build({config:y.config,translationStore:O,definition:y.definition,configPath:t,outputPath:y.config.build.paths.outDir,outputRelativeConfigPath:T,buildArtifacts:k,logger:{instance:a,silent:v}})]);A.error&&(a.error(x.english(A.error.message)??`There was an error while building the SPA or component plugins`,{silent:v}),await n(),process.exit(1)),await c({runtimeContext:j.runtimeContext,config:y.config});let M=_.relative(process.cwd(),y.config.build.paths.outDir);a.info(`SPA and component plugins built:`,a.color.green(`./${M}/${e.directories.public}/${e.directories.base}`),{silent:v});let N=0,P=new Set,F=new Set;for(let e of y.config.collections)if(e.key){P.add(e.key);for(let t of e.brickInstances)F.has(t.key)||(F.add(t.key),N+=t.flatFields.length);N+=e.flatFields.length}a.info(a.color.yellow(P.size),`collection${P.size===1?``:`s`} with`,a.color.yellow(F.size),`brick${F.size===1?``:`s`} and`,a.color.yellow(N),`field${N===1?``:`s`}`,{silent:v}),a.info(a.color.yellow(y.config.plugins.length),`plugin${y.config.plugins.length===1?``:`s`} loaded`,{silent:v}),await j?.onComplete?.();let I=g(),L=await d(y.config.build.paths.outDir);a.log(a.createBadge(`LUCID CMS`),`Build completed`,`successfully`,`in`,a.color.green(a.formatMilliseconds(I)),a.color.green(`(${a.formatBytes(L)})`),{spaceAfter:!0,spaceBefore:!0,silent:v}),await n(),process.exit(0)}catch(e){e instanceof Error?a.errorInstance(e,`Failed to build the application`):a.error(`Failed to build the application`,`Unknown error`),await n(),process.exit(1)}},b=async t=>{if(!t)return;let n=await m(t,{recursive:!0}),r=[_.join(e.directories.public,e.directories.base)];for(let e of n){let n=v(t,e);try{if(!(await g(n)).isFile())continue}catch{continue}r.some(r=>e.includes(r)||e===r||n.includes(r)||n===v(t,r))||await h(n,{force:!0})}};export{y as default}; //# sourceMappingURL=build.mjs.map