{"version":3,"file":"handle-runtime.mjs","names":[],"sources":["../../../../src/libs/plugins/hooks/handle-runtime.ts"],"sourcesContent":["import type {\n\tLucidConfigDefinition,\n\tRuntimeBuildArtifact,\n} from \"../../../libs/runtime/types.js\";\nimport type { Config } from \"../../../types/config.js\";\nimport type { ServiceResponse } from \"../../../types.js\";\nimport cliLogger from \"../../cli/logger.js\";\nimport { copy, createTranslator } from \"../../i18n/index.js\";\nimport type { TranslationStore } from \"../../i18n/types.js\";\n\n/**\n * Responsible for running the plugin runtime hooks and collecting artifacts.\n */\nconst handlePluginRuntimeHooks = async (props: {\n\tconfig: Config;\n\ttranslationStore: TranslationStore;\n\tdefinition: LucidConfigDefinition;\n\tsilent?: boolean;\n\tconfigPath: string;\n\toutputPath: string;\n\toutputRelativeConfigPath: string;\n}): ServiceResponse<RuntimeBuildArtifact[]> => {\n\ttry {\n\t\tconst pluginArtifacts: Array<RuntimeBuildArtifact> = [];\n\t\tconst silent = props.silent ?? false;\n\t\tconst translate = createTranslator({\n\t\t\tstore: props.translationStore,\n\t\t\tlocale: \"en\",\n\t\t});\n\n\t\tawait Promise.all(\n\t\t\tprops.config.plugins.map(async (plugin) => {\n\t\t\t\tif (!plugin.hooks?.runtime) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst res = await plugin.hooks.runtime({\n\t\t\t\t\tphase: \"build\",\n\t\t\t\t\tdefinition: props.definition,\n\t\t\t\t\tpaths: {\n\t\t\t\t\t\tconfigPath: props.configPath,\n\t\t\t\t\t\toutputPath: props.outputPath,\n\t\t\t\t\t\toutputRelativeConfigPath: props.outputRelativeConfigPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (res.error) {\n\t\t\t\t\tcliLogger.error(\n\t\t\t\t\t\ttranslate.english(res.error.message) ??\n\t\t\t\t\t\t\t`An unknown error occurred while running the ${plugin.key} plugin runtime hook`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsilent,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (res.data?.artifacts) {\n\t\t\t\t\tpluginArtifacts.push(...res.data.artifacts);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\terror: undefined,\n\t\t\tdata: pluginArtifacts,\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\tmessage: copy(\"server:core.plugins.build.failed\", {\n\t\t\t\t\tdefaultMessage:\n\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t: \"An unknown error occurred while preparing plugin runtime artifacts\",\n\t\t\t\t}),\n\t\t\t\tstatus: 500,\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n};\n\nexport default handlePluginRuntimeHooks;\n"],"mappings":"2IAaA,MAAM,EAA2B,KAAO,IAQO,CAC9C,GAAI,CACH,IAAM,EAA+C,CAAC,EAChD,EAAS,EAAM,QAAU,GACzB,EAAY,EAAiB,CAClC,MAAO,EAAM,iBACb,OAAQ,IACT,CAAC,EA+BD,OA7BA,MAAM,QAAQ,IACb,EAAM,OAAO,QAAQ,IAAI,KAAO,IAAW,CAC1C,GAAI,CAAC,EAAO,OAAO,QAClB,OAED,IAAM,EAAM,MAAM,EAAO,MAAM,QAAQ,CACtC,MAAO,QACP,WAAY,EAAM,WAClB,MAAO,CACN,WAAY,EAAM,WAClB,WAAY,EAAM,WAClB,yBAA0B,EAAM,wBACjC,CACD,CAAC,EACG,EAAI,OACP,EAAU,MACT,EAAU,QAAQ,EAAI,MAAM,OAAO,GAClC,+CAA+C,EAAO,IAAI,sBAC3D,CACC,QACD,CACD,EAEG,EAAI,MAAM,WACb,EAAgB,KAAK,GAAG,EAAI,KAAK,SAAS,CAE5C,CAAC,CACF,EAEO,CACN,MAAO,IAAA,GACP,KAAM,CACP,CACD,OAAS,EAAO,CACf,MAAO,CACN,MAAO,CACN,QAAS,EAAK,mCAAoC,CACjD,eACC,aAAiB,MACd,EAAM,QACN,oEACL,CAAC,EACD,OAAQ,GACT,EACA,KAAM,IAAA,EACP,CACD,CACD"}