@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 3.26 kB
JavaScript
import e from"../../../constants/constants.mjs";import{startLoggerBuffering as t,stopLoggerBuffering as n}from"../../logger/index.mjs";import r from"../../i18n/prepare-translations.mjs";import{createTranslator as i}from"../../i18n/translate.mjs";import a from"../logger.mjs";import o from"../../config/get-config-path.mjs";import s from"../../config/load-config-file.mjs";import c from"../services/validate-env-vars.mjs";import l from"./migrate.mjs";import u from"../../type-generation/index.mjs";import d from"../../plugins/check-all-plugins-compatibility.mjs";import f from"../../email/templates/prepare-email-templates.mjs";import p from"../../vite/index.mjs";import m from"../services/copy-public-assets.mjs";import h from"../services/update-available.mjs";const g=async()=>{t();let g=o(process.cwd()),_,v=h(),y,b=()=>(y??=(async()=>{try{await _?.()}catch(e){e instanceof Error?a.errorInstance(e,`Error during shutdown`):a.error(`Error during shutdown`,`Unknown error`)}await n(),process.exit(0)})(),y);try{let t=await s({path:g,prepareRuntime:!0}),o=(await r({config:t.config,projectRoot:t.projectRoot,outputPath:t.config.build.paths.outDir})).translationStore,h=i({store:o,locale:`en`}),y=t.adapter.cli;y||(a.error(`Lucid could not load CLI handlers from the "${t.adapter.key}" runtime adapter.`),await n(),process.exit(1));let b=await c({envSchema:t.envSchema,env:t.env});u({envSchema:t.envSchema,configPath:g,projectRoot:t.projectRoot,collections:t.config.collections,localization:t.config.localization}),b||(await n(),process.exit(1)),await l({config:t.config,env:t.env,runtimeContext:t.runtimeContext,translationStore:o,projectRoot:t.projectRoot,mode:`return`})({skipSyncSteps:!1,skipEnvValidation:!0})||(await n(),process.exit(2));let x=await p.buildApp(t.config);x.error&&(a.error(h.english(x.error.message)??`Failed to build app`),process.exit(1));let[S,C]=await Promise.all([f({config:t.config,silent:!1,verbose:!1}),m({config:t.config,silent:!1,verbose:!1})]);S.error&&(a.error(h.english(S.error.message)??`Failed to prepare email templates`),process.exit(1)),C.error&&(a.error(h.english(C.error.message)??`Failed to copy public assets`),process.exit(1)),a.success(`Email templates and public assets prepared`,a.color.green(`successfully`));let w=await y.serve({config:t.config,translationStore:o,logger:{instance:a,silent:!1},onListening:async t=>{let r=typeof t.address==`string`?t.address:t.address?`http://${t.address.address===`::`?`localhost`:t.address.address}:${t.address.port}`:`unknown`,i=await v;i.renderUpdateBox(),a.log(a.createBadge(`LUCID CMS`),`Development server ready`,{spaceBefore:!i.show,spaceAfter:!0}),a.log(`🔐 Admin panel `,a.color.blue(`${r}/lucid`),{symbol:`line`}),a.log(`📖 Documentation `,a.color.blue(e.documentation),{symbol:`line`}),a.log(a.color.gray(`Press CTRL-C to stop the server`),{spaceBefore:!0,spaceAfter:!0}),await n()}});_=w?.destroy,await d({runtimeContext:w.runtimeContext,config:t.config}),await w?.onComplete?.()}catch(e){await _?.(),e instanceof Error?a.errorInstance(e,`Failed to start the server`):a.error(`Failed to start the server`,`Unknown error`),await n(),process.exit(1)}process.on(`SIGINT`,b),process.on(`SIGTERM`,b)};export{g as default};
//# sourceMappingURL=serve.mjs.map