77import { ensureDirSync , existsSync } from "fs/mod.ts" ;
88import { dirname , isAbsolute , join , relative } from "../../deno_ral/path.ts" ;
99import { info , warning } from "../../deno_ral/log.ts" ;
10+ import { mergeProjectMetadata } from "../../config/metadata.ts" ;
1011
1112import * as colors from "fmt/colors.ts" ;
1213
@@ -72,6 +73,8 @@ import { Format } from "../../config/types.ts";
7273import { fileExecutionEngine } from "../../execute/engine.ts" ;
7374import { projectContextForDirectory } from "../../project/project-context.ts" ;
7475import { ProjectType } from "../../project/types/types.ts" ;
76+ import { ProjectConfig as ProjectConfig_Project } from "../../resources/types/schema-types.ts" ;
77+ import { Extension } from "../../extension/types.ts" ;
7578
7679const noMutationValidations = (
7780 projType : ProjectType ,
@@ -217,14 +220,7 @@ const computeProjectRenderConfig = async (
217220
218221const getProjectRenderScripts = async (
219222 context : ProjectContext ,
220- pOptions : RenderOptions ,
221223) => {
222- const extensions = await pOptions . services . extension . extensions (
223- undefined ,
224- context . config ,
225- context . isSingleFile ? undefined : context . dir ,
226- { builtIn : false } ,
227- ) ;
228224 const preRenderScripts : string [ ] = [ ] ,
229225 postRenderScripts : string [ ] = [ ] ;
230226 if ( context . config ?. project ?. [ kProjectPreRender ] ) {
@@ -237,35 +233,40 @@ const getProjectRenderScripts = async (
237233 ...asArray ( context . config ?. project ?. [ kProjectPostRender ] ! ) ,
238234 ) ;
239235 }
240- extensions . forEach ( ( extension ) => {
241- if ( extension . contributes . metadata ?. project ) {
242- const project = extension . contributes . metadata . project as Record <
243- string ,
244- unknown
245- > ;
246- if ( project [ kProjectPreRender ] ) {
247- preRenderScripts . push (
248- ...asArray ( project [ kProjectPreRender ] as string | string [ ] ) ,
249- ) ;
250- }
251- if ( project [ kProjectPostRender ] ) {
252- postRenderScripts . push (
253- ...asArray ( project [ kProjectPostRender ] as string | string [ ] ) ,
254- ) ;
255- }
256- }
257- } ) ;
258236 return { preRenderScripts, postRenderScripts } ;
259237} ;
260238
239+ const mergeExtensionMetadata = async (
240+ context : ProjectContext ,
241+ pOptions : RenderOptions ,
242+ ) => {
243+ // this will mutate context.config.project to merge
244+ // in any project metadata from extensions
245+ if ( context . config ) {
246+ const extensions = await pOptions . services . extension . extensions (
247+ undefined ,
248+ context . config ,
249+ context . isSingleFile ? undefined : context . dir ,
250+ { builtIn : false } ,
251+ ) ;
252+ const projectMetadata = extensions . map ( ( extension ) =>
253+ extension . contributes . metadata ?. project
254+ ) . filter ( ( project ) => project ) as ProjectConfig_Project [ ] ;
255+ context . config . project = mergeProjectMetadata (
256+ context . config . project ,
257+ ...projectMetadata ,
258+ ) ;
259+ }
260+ } ;
261+
261262export async function renderProject (
262263 context : ProjectContext ,
263264 pOptions : RenderOptions ,
264265 pFiles ?: string [ ] ,
265266) : Promise < RenderResult > {
267+ mergeExtensionMetadata ( context , pOptions ) ;
266268 const { preRenderScripts, postRenderScripts } = await getProjectRenderScripts (
267269 context ,
268- pOptions ,
269270 ) ;
270271
271272 // lookup the project type
0 commit comments