@@ -9,7 +9,7 @@ import { BlockObjectResponse } from "@notionhq/client/build/src/api-endpoints";
99import { DocuNotionOptions } from "../pull" ;
1010import { LayoutStrategy } from "../LayoutStrategy" ;
1111import defaultConfig from "./default.docunotion.config" ;
12- import { error , info , verbose } from "../log" ;
12+ import { error , info , logDebug , verbose } from "../log" ;
1313import { TypeScriptLoader } from "cosmiconfig-typescript-loader" ;
1414
1515// wrap this into something with a bit better name than the raw thing
@@ -44,6 +44,9 @@ export type IPlugin = {
4444
4545 // simple regex replacements on the markdown output
4646 regexMarkdownModifications ?: IRegexMarkdownModification [ ] ;
47+
48+ // allow a plugin to perform an async operation before it can deliver its operations
49+ init ?( plugin : IPlugin ) : Promise < void > ;
4750} ;
4851
4952export type IRegexMarkdownModification = {
@@ -97,6 +100,21 @@ export async function loadConfigAsync(): Promise<IDocuNotionConfig> {
97100 verbose ( `Did not find configuration file, using defaults.` ) ;
98101 }
99102
103+ const pluginsWithInitializers = found ?. config ?. plugins ?. filter (
104+ ( p : IPlugin ) => p . init !== undefined
105+ ) ;
106+ const initializers = pluginsWithInitializers ?. map (
107+ ( p : IPlugin ) => ( ) => p ! . init ! ( p )
108+ ) ;
109+
110+ await Promise . all ( initializers || [ ] ) ;
111+
112+ found ?. config ?. plugins ?. forEach ( async ( plugin : IPlugin ) => {
113+ if ( plugin . init !== undefined ) {
114+ verbose ( `Initializing plugin ${ plugin . name } ...` ) ;
115+ await plugin . init ( plugin ) ;
116+ }
117+ } ) ;
100118 // for now, all we have is plugins
101119 config = {
102120 plugins : defaultConfig . plugins . concat ( found ?. config ?. plugins || [ ] ) ,
@@ -108,12 +126,6 @@ export async function loadConfigAsync(): Promise<IDocuNotionConfig> {
108126 return config ;
109127}
110128
111- export interface IPlug {
112- name : string ;
113- sayHello : ( block : IFoo ) => string ;
114- }
115- export interface IFoo { }
116-
117129// export function getMDConversions(): Array<{
118130// type: string;
119131// transformer: ICustomNotionToMarkdownConversion;
0 commit comments