11import {
2+ ChangeLogPageData ,
23 ParsedFile ,
34 Skip ,
5+ TransformChangelogPage ,
46 UnparsedApexBundle ,
57 UnparsedSourceBundle ,
68 UserDefinedChangelogConfig ,
@@ -12,26 +14,24 @@ import { Changelog, hasChanges, processChangelog, VersionManifest } from './proc
1214import { convertToRenderableChangelog , RenderableChangelog } from './renderable-changelog' ;
1315import { CompilationRequest , Template } from '../template' ;
1416import { changelogTemplate } from './templates/changelog-template' ;
15- import { ReflectionErrors } from '../errors/errors' ;
17+ import { HookError , ReflectionErrors } from '../errors/errors' ;
1618import { apply } from '#utils/fp' ;
1719import { filterScope } from '../reflection/apex/filter-scope' ;
18- import { isInSource , skip } from '../shared/utils' ;
20+ import { isInSource , isSkip , passThroughHook , skip , toFrontmatterString } from '../shared/utils' ;
1921import { reflectCustomFieldsAndObjects } from '../reflection/sobject/reflectCustomFieldsAndObjects' ;
2022import { CustomObjectMetadata } from '../reflection/sobject/reflect-custom-object-sources' ;
2123import { Type } from '@cparra/apex-reflection' ;
2224import { filterApexSourceFiles , filterCustomObjectsAndFields } from '#utils/source-bundle-utils' ;
2325import { CustomFieldMetadata } from '../reflection/sobject/reflect-custom-field-source' ;
26+ import { hookableTemplate } from '../markdown/templates/hookable' ;
2427
25- export type ChangeLogPageData = {
26- content : string ;
27- outputDocPath : string ;
28- } ;
28+ type Config = Omit < UserDefinedChangelogConfig , 'targetGenerator' > ;
2929
3030export function generateChangeLog (
3131 oldBundles : UnparsedSourceBundle [ ] ,
3232 newBundles : UnparsedSourceBundle [ ] ,
33- config : Omit < UserDefinedChangelogConfig , 'targetGenerator' > ,
34- ) : TE . TaskEither < ReflectionErrors , ChangeLogPageData | Skip > {
33+ config : Config ,
34+ ) : TE . TaskEither < ReflectionErrors | HookError , ChangeLogPageData | Skip > {
3535 const convertToPageData = apply ( toPageData , config . fileName ) ;
3636
3737 function handleConversion ( { changelog, newManifest } : { changelog : Changelog ; newManifest : VersionManifest } ) {
@@ -51,6 +51,8 @@ export function generateChangeLog(
5151 newManifest,
5252 } ) ) ,
5353 TE . map ( handleConversion ) ,
54+ TE . flatMap ( transformChangelogPageHook ( config ) ) ,
55+ TE . map ( postHookCompile ) ,
5456 ) ;
5557}
5658
@@ -106,7 +108,45 @@ function compile(renderable: RenderableChangelog): string {
106108
107109function toPageData ( fileName : string , content : string ) : ChangeLogPageData {
108110 return {
111+ frontmatter : null ,
109112 content,
110113 outputDocPath : `${ fileName } .md` ,
111114 } ;
112115}
116+
117+ function transformChangelogPageHook ( config : Config ) {
118+ return ( page : ChangeLogPageData | Skip ) =>
119+ TE . tryCatch (
120+ ( ) => transformChangelogPage ( page , config . transformChangeLogPage ) ,
121+ ( error ) => new HookError ( error ) ,
122+ ) ;
123+ }
124+
125+ async function transformChangelogPage (
126+ page : ChangeLogPageData | Skip ,
127+ hook : TransformChangelogPage = passThroughHook ,
128+ ) : Promise < ChangeLogPageData | Skip > {
129+ if ( isSkip ( page ) ) {
130+ return page ;
131+ }
132+ return {
133+ ...page ,
134+ ...( await hook ( page ) ) ,
135+ } ;
136+ }
137+
138+ function postHookCompile ( page : ChangeLogPageData | Skip ) : ChangeLogPageData | Skip {
139+ if ( isSkip ( page ) ) {
140+ return page ;
141+ }
142+ return {
143+ ...page ,
144+ content : Template . getInstance ( ) . compile ( {
145+ source : {
146+ frontmatter : toFrontmatterString ( page . frontmatter ) ,
147+ content : page . content ,
148+ } ,
149+ template : hookableTemplate ,
150+ } ) ,
151+ } ;
152+ }
0 commit comments