@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 2.27 kB
JavaScript
import e from"../../utils/errors/lucid-error.mjs";import{collectRuntimePrepareArtifacts as t,createRuntimePrepareArtifacts as n}from"../runtime/prepare-artifacts.mjs";import r from"../runtime/resolve-database-adapter.mjs";import i from"./process-config.mjs";const a={info:()=>{},warn:()=>{},error:()=>{},log:()=>{},success:()=>{},color:{blue:e=>String(e),green:e=>String(e)}},o=`Lucid config must default export configureLucid({ runtime, db, config }).`,s=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return t.runtime!==void 0&&t.db!==void 0&&typeof t.config==`function`},c=t=>{if(!s(t))throw new e({message:o});return t},l=async t=>{let n=await(typeof t==`function`?t():t);if(!n||typeof n!=`object`)throw new e({message:"Lucid could not resolve the configured runtime adapter. Pass a runtime adapter instance to `configureLucid({ runtime })`."});return n},u=async e=>{let o=c(e.definition),s=await l(o.runtime),u=e.logger??{instance:a,silent:!0},d={runtime:s.key,compiled:!1,getConnectionInfo:()=>({}),configEntryPoint:null},f=(e.configureLucid??s.configureLucid??(e=>e))({...o,runtime:s},e.meta),p=e.prepareRuntime&&s.cli?.prepare&&e.configPath&&e.projectRoot?{prepare:s.cli.prepare,configPath:e.configPath,projectRoot:e.projectRoot}:void 0;p&&await p.prepare({configPath:p.configPath,projectRoot:p.projectRoot,prepareArtifacts:n(),logger:u});let m=e.env??(s.getEnvVars?await s.getEnvVars({logger:u}):void 0),h=e.envSchema,g=e.validateEnvSchema??!0,_=e=>{!g||!h||!e||h.parse(e)};_(m),await s.resolveOptions?.(m??{});let v=f.config(m||{}),y=p?await t({db:f.db,plugins:v.plugins??[],env:m??{},definition:f,paths:{configPath:p.configPath,projectRoot:p.projectRoot},customArtifactTypes:s.config?.customPrepareArtifacts}):n();p&&y.custom.length>0&&(await p.prepare({configPath:p.configPath,projectRoot:p.projectRoot,prepareArtifacts:y,logger:u}),!e.env&&s.getEnvVars&&(m=await s.getEnvVars({logger:u}),_(m),await s.resolveOptions?.(m??{}),v=f.config(m||{})));let b=await r(f.db,m);return{config:await i(v,{...e.processConfigOptions??{},recipe:f.recipe,resolvedDb:b}),adapter:s,runtimeContext:d,envSchema:h,env:m,definition:f}};export{u as default,u as resolveConfigDefinition,o as invalidConfigDefinitionMessage};
//# sourceMappingURL=resolve-config-definition.mjs.map