@@ -82,6 +82,7 @@ class CodeInjector implements ICodeInjector {
8282 adminforth : AdminForth ;
8383 allComponentNames : { [ key : string ] : string } = { } ;
8484 srcFoldersToSync : { [ key : string ] : string } = { } ;
85+ publicFoldersToSync : { [ key : string ] : string } = { } ;
8586 devServerPort : number = null ;
8687
8788 spaTmpPath ( ) : string {
@@ -327,6 +328,17 @@ class CodeInjector implements ICodeInjector {
327328 return spaDir ;
328329 }
329330
331+ registerPluginPublicFoldersToSync ( ) {
332+ this . publicFoldersToSync = { } ;
333+
334+ for ( const plugin of this . adminforth . activatedPlugins ) {
335+ const pluginPublicFolderPath = path . join ( plugin . customFolderPath , 'public' ) ;
336+ if ( fs . existsSync ( pluginPublicFolderPath ) ) {
337+ this . publicFoldersToSync [ pluginPublicFolderPath ] = `./plugins/${ plugin . className } /` ;
338+ }
339+ }
340+ }
341+
330342 async updatePartials ( { filesUpdated } : { filesUpdated : string [ ] } ) {
331343 const spaDir = this . getSpaDir ( ) ;
332344
@@ -477,6 +489,8 @@ class CodeInjector implements ICodeInjector {
477489 this . srcFoldersToSync [ customCompAbsPath ] = './'
478490 }
479491
492+ this . registerPluginPublicFoldersToSync ( ) ;
493+
480494 // if this.adminforth.config.customization.favicon is set, copy it to assets
481495 const customFav = this . adminforth . config . customization ?. favicon ;
482496 if ( customFav ) {
@@ -501,6 +515,16 @@ class CodeInjector implements ICodeInjector {
501515 } ) ;
502516 }
503517
518+ for ( const [ src , dest ] of Object . entries ( this . publicFoldersToSync ) ) {
519+ const to = path . join ( this . spaTmpPath ( ) , 'public' , dest ) ;
520+ process . env . HEAVY_DEBUG && console . log ( `🪲⚙️ publicFoldersToSync: fsExtra.copy from ${ src } , ${ to } ` ) ;
521+
522+ await fsExtra . copy ( src , to , {
523+ recursive : true ,
524+ dereference : true ,
525+ } ) ;
526+ }
527+
504528 //collect all 'icon' fields from resources bulkActions
505529 this . adminforth . config . resources . forEach ( ( resource ) => {
506530 if ( resource . options ?. bulkActions ) {
@@ -860,7 +884,11 @@ class CodeInjector implements ICodeInjector {
860884 this . allWatchers . push ( watcher ) ;
861885 }
862886
863- async watchCustomComponentsForCopy ( { customComponentsDir, destination } ) {
887+ async watchCustomComponentsForCopy ( { customComponentsDir, destination, targetRoot = path . join ( 'src' , 'custom' ) } : {
888+ customComponentsDir : string ,
889+ destination : string ,
890+ targetRoot ?: string ,
891+ } ) {
864892 if ( ! customComponentsDir ) {
865893 return ;
866894 }
@@ -917,7 +945,7 @@ class CodeInjector implements ICodeInjector {
917945 process . env . HEAVY_DEBUG && console . log ( `🔎 destination ${ destination } ` ) ;
918946 const isFile = fs . lstatSync ( fileOrDir ) . isFile ( ) ;
919947 if ( isFile ) {
920- const destPath = path . join ( this . spaTmpPath ( ) , 'src' , 'custom' , destination , relativeFilename ) ;
948+ const destPath = path . join ( this . spaTmpPath ( ) , targetRoot , destination , relativeFilename ) ;
921949 process . env . HEAVY_DEBUG && console . log ( `🔎 Copying file ${ fileOrDir } to ${ destPath } ` ) ;
922950 await fsExtra . copy ( fileOrDir , destPath ) ;
923951 return ;
@@ -1033,6 +1061,13 @@ class CodeInjector implements ICodeInjector {
10331061 destination : dest ,
10341062 } ) ;
10351063 } ) ,
1064+ ...Object . entries ( this . publicFoldersToSync ) . map ( async ( [ src , dest ] ) => {
1065+ await this . watchCustomComponentsForCopy ( {
1066+ customComponentsDir : src ,
1067+ destination : dest ,
1068+ targetRoot : 'public' ,
1069+ } ) ;
1070+ } ) ,
10361071 ] ) ;
10371072 }
10381073
0 commit comments