UNPKG

@lucidcms/core

Version:

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

1 lines 4.3 kB
{"version":3,"file":"load-build-project.mjs","names":[],"sources":["../../../src/libs/compile/load-build-project.ts"],"sourcesContent":["import type { ZodType } from \"zod\";\nimport { LucidError } from \"../../utils/errors/index.js\";\nimport validateEnvVars from \"../cli/services/validate-env-vars.js\";\nimport getConfigPath from \"../config/get-config-path.js\";\nimport loadConfigFile from \"../config/load-config-file.js\";\nimport type { RenderedTemplates } from \"../email/types.js\";\nimport prepareTranslations from \"../i18n/prepare-translations.js\";\nimport type { TranslationStore } from \"../i18n/types.js\";\nimport generateTypes from \"../type-generation/index.js\";\n\ntype LoadConfigResult = Awaited<ReturnType<typeof loadConfigFile>>;\ntype PreparedLoadConfigResult = LoadConfigResult & {\n\ttranslationStore: TranslationStore;\n};\n\nexport type LoadBuildProjectResult = {\n\tconfigPath: string;\n\tloaded: PreparedLoadConfigResult;\n\temailTemplates?: RenderedTemplates;\n};\n\n/**\n * Centralises the build-time Lucid bootstrap steps so CLI and integrations can\n * resolve the same config, env and generated side effects without duplicating\n * the setup sequence in each host.\n */\nconst loadBuildProject = async (props?: {\n\tconfigPath?: string;\n\tsilent?: boolean;\n\tvalidateEnv?: boolean;\n\tgenerateTypes?: boolean;\n\tloadEmailTemplates?: boolean;\n\t/** Collects local config imports for development watchers. */\n\tcollectConfigDependencies?: boolean;\n\tenvSchema?: ZodType;\n\tconfigureLucidPath?: string;\n\tprepareRuntime?: boolean;\n}): Promise<LoadBuildProjectResult> => {\n\tconst configPath = props?.configPath ?? getConfigPath(process.cwd());\n\tconst loaded = await loadConfigFile({\n\t\tpath: configPath,\n\t\tsilent: props?.silent,\n\t\tcollectConfigDependencies: props?.collectConfigDependencies,\n\t\tconfigureLucidPath: props?.configureLucidPath,\n\t\tprepareRuntime: props?.prepareRuntime,\n\t\tvalidateEnvSchema: false,\n\t\tprocessConfigOptions: {\n\t\t\tmode: \"build\",\n\t\t},\n\t});\n\tconst translations = await prepareTranslations({\n\t\tconfig: loaded.config,\n\t\tprojectRoot: loaded.projectRoot,\n\t});\n\tconst preparedLoaded = {\n\t\t...loaded,\n\t\ttranslationStore: translations.translationStore,\n\t};\n\n\tconst [envValid, _typeGen, emailTemplates] = await Promise.all([\n\t\tprops?.validateEnv &&\n\t\t\tvalidateEnvVars({\n\t\t\t\tenvSchema: props.envSchema ?? preparedLoaded.envSchema,\n\t\t\t\tenv: preparedLoaded.env,\n\t\t\t}),\n\t\tprops?.generateTypes !== false &&\n\t\t\tgenerateTypes({\n\t\t\t\tenvSchema: props?.envSchema ?? preparedLoaded.envSchema,\n\t\t\t\tconfigPath,\n\t\t\t\tprojectRoot: preparedLoaded.projectRoot,\n\t\t\t\tcollections: preparedLoaded.config.collections,\n\t\t\t\tlocalization: preparedLoaded.config.localization,\n\t\t\t}),\n\t\tprops?.loadEmailTemplates\n\t\t\t? import(\"../email/templates/load-email-templates.js\").then(\n\t\t\t\t\t({ default: loadEmailTemplates }) =>\n\t\t\t\t\t\tloadEmailTemplates({\n\t\t\t\t\t\t\tconfig: preparedLoaded.config,\n\t\t\t\t\t\t\tsilent: props?.silent,\n\t\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t: undefined,\n\t]);\n\n\tif (props?.validateEnv && !envValid) {\n\t\tthrow new LucidError({\n\t\t\tmessage:\n\t\t\t\t\"Lucid build could not validate the environment variables for lucid.config.ts.\",\n\t\t});\n\t}\n\n\treturn {\n\t\tconfigPath,\n\t\tloaded: preparedLoaded,\n\t\temailTemplates,\n\t};\n};\n\nexport default loadBuildProject;\n"],"mappings":"8RA0BA,MAAM,EAAmB,KAAO,IAWO,CACtC,IAAM,EAAa,GAAO,YAAc,EAAc,QAAQ,IAAI,CAAC,EAC7D,EAAS,MAAM,EAAe,CACnC,KAAM,EACN,OAAQ,GAAO,OACf,0BAA2B,GAAO,0BAClC,mBAAoB,GAAO,mBAC3B,eAAgB,GAAO,eACvB,kBAAmB,GACnB,qBAAsB,CACrB,KAAM,OACP,CACD,CAAC,EACK,EAAe,MAAM,EAAoB,CAC9C,OAAQ,EAAO,OACf,YAAa,EAAO,WACrB,CAAC,EACK,EAAiB,CACtB,GAAG,EACH,iBAAkB,EAAa,gBAChC,EAEM,CAAC,EAAU,EAAU,GAAkB,MAAM,QAAQ,IAAI,CAC9D,GAAO,aACN,EAAgB,CACf,UAAW,EAAM,WAAa,EAAe,UAC7C,IAAK,EAAe,GACrB,CAAC,EACF,GAAO,gBAAkB,IACxB,EAAc,CACb,UAAW,GAAO,WAAa,EAAe,UAC9C,aACA,YAAa,EAAe,YAC5B,YAAa,EAAe,OAAO,YACnC,aAAc,EAAe,OAAO,YACrC,CAAC,EACF,GAAO,mBACJ,OAAO,8CAA6C,CAAC,MACpD,CAAE,QAAS,KACX,EAAmB,CAClB,OAAQ,EAAe,OACvB,OAAQ,GAAO,MAChB,CAAC,CACH,EACC,IAAA,EACJ,CAAC,EAED,GAAI,GAAO,aAAe,CAAC,EAC1B,MAAM,IAAI,EAAW,CACpB,QACC,+EACF,CAAC,EAGF,MAAO,CACN,aACA,OAAQ,EACR,gBACD,CACD"}