@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 4.07 kB
Source Map (JSON)
{"version":3,"file":"process-build-artifacts.mjs","names":["cliLogger"],"sources":["../../../../src/libs/cli/services/process-build-artifacts.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n\tRuntimeBuildArtifact,\n\tRuntimeBuildArtifactCompile,\n\tRuntimeBuildArtifactCustom,\n\tRuntimeBuildArtifactFile,\n\tRuntimeBuildArtifacts,\n} from \"../../runtime/types.js\";\nimport cliLogger from \"../logger.js\";\n\nexport const CORE_ARTIFACT_TYPES = [\"file\", \"compile\"];\n\n/**\n * Responsible for processing the artifacts collected from the plugins.\n * Writes file and compile artifacts to the output directory.\n * Returns the artifacts formatted for the runtime adapter.\n */\nconst processBuildArtifacts = async (props: {\n\tartifacts: RuntimeBuildArtifact[];\n\toutDir: string;\n\tsilent: boolean;\n\tcustomArtifactTypes?: string[];\n}): Promise<RuntimeBuildArtifacts> => {\n\tconst result: RuntimeBuildArtifacts = {\n\t\tcompile: {},\n\t\tcustom: [],\n\t};\n\n\tawait Promise.all(\n\t\tprops.artifacts.map(async (artifact) => {\n\t\t\tif (props.customArtifactTypes?.includes(artifact.type)) {\n\t\t\t\tresult.custom.push(artifact as RuntimeBuildArtifactCustom);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!CORE_ARTIFACT_TYPES.includes(artifact.type)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet artifactPathData: { path: string; content: string };\n\n\t\t\tif (artifact.type === \"compile\") {\n\t\t\t\tconst compileArtifact = artifact as RuntimeBuildArtifactCompile;\n\t\t\t\tconst dirname = path.dirname(compileArtifact.path);\n\t\t\t\tconst filename = path.basename(compileArtifact.path);\n\t\t\t\tartifactPathData = {\n\t\t\t\t\tpath: path.join(dirname, `temp-${filename}`),\n\t\t\t\t\tcontent: compileArtifact.content,\n\t\t\t\t};\n\t\t\t} else if (artifact.type === \"file\") {\n\t\t\t\tartifactPathData = {\n\t\t\t\t\tpath: (artifact as RuntimeBuildArtifactFile).path,\n\t\t\t\t\tcontent: (artifact as RuntimeBuildArtifactFile).content,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst relativePath = artifactPathData.path.replace(/^[/\\\\]+/, \"\");\n\t\t\tconst artifactPath = path.join(props.outDir, relativePath);\n\t\t\tawait fs.mkdir(path.dirname(artifactPath), { recursive: true });\n\t\t\tawait fs.writeFile(artifactPath, artifactPathData.content);\n\t\t\tcliLogger.info(\n\t\t\t\t\"Plugin artifact built:\",\n\t\t\t\tcliLogger.color.green(`./${relativePath}`),\n\t\t\t\t{\n\t\t\t\t\tsilent: props.silent,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (artifact.type === \"compile\") {\n\t\t\t\tconst compileArtifact = artifact as RuntimeBuildArtifactCompile;\n\t\t\t\tconst ext = path.extname(compileArtifact.path);\n\t\t\t\tconst nameWithoutExt = path.basename(compileArtifact.path, ext);\n\t\t\t\tconst dir = path.dirname(compileArtifact.path);\n\t\t\t\tconst key = path.join(dir, nameWithoutExt);\n\t\t\t\tresult.compile[key] = artifactPath;\n\t\t\t}\n\t\t}),\n\t);\n\n\treturn result;\n};\n\nexport default processBuildArtifacts;\n"],"mappings":"sFAWA,MAAa,EAAsB,CAAC,OAAQ,SAAS,EAO/C,EAAwB,KAAO,IAKC,CACrC,IAAM,EAAgC,CACrC,QAAS,CAAC,EACV,OAAQ,CAAC,CACV,EAuDA,OArDA,MAAM,QAAQ,IACb,EAAM,UAAU,IAAI,KAAO,IAAa,CACvC,GAAI,EAAM,qBAAqB,SAAS,EAAS,IAAI,EAAG,CACvD,EAAO,OAAO,KAAK,CAAsC,EACzD,MACD,CAEA,GAAI,CAAC,EAAoB,SAAS,EAAS,IAAI,EAC9C,OAGD,IAAI,EAEJ,GAAI,EAAS,OAAS,UAAW,CAChC,IAAM,EAAkB,EAClB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