@@ -56,26 +56,66 @@ export default async (pluginConfig, context) => {
5656 debug ( "milestones: %o" , milestones ) ;
5757
5858 if ( assets && assets . length > 0 ) {
59+ // Apply template expansion to assets BEFORE globbing, but only when templates are present
60+ const needsTemplateExpansion = ( str ) => str && typeof str === 'string' && str . includes ( '${' ) ;
61+
62+ const templatedAssets = assets . map ( ( asset ) => {
63+ if ( isPlainObject ( asset ) ) {
64+ const templatedAsset = { ...asset } ;
65+ if ( asset . path && needsTemplateExpansion ( asset . path ) ) {
66+ templatedAsset . path = template ( asset . path ) ( context ) ;
67+ }
68+ if ( asset . url && needsTemplateExpansion ( asset . url ) ) {
69+ templatedAsset . url = template ( asset . url ) ( context ) ;
70+ }
71+ if ( asset . label && needsTemplateExpansion ( asset . label ) ) {
72+ templatedAsset . label = template ( asset . label ) ( context ) ;
73+ }
74+ if ( asset . type && needsTemplateExpansion ( asset . type ) ) {
75+ templatedAsset . type = template ( asset . type ) ( context ) ;
76+ }
77+ if ( asset . filepath && needsTemplateExpansion ( asset . filepath ) ) {
78+ templatedAsset . filepath = template ( asset . filepath ) ( context ) ;
79+ }
80+ if ( asset . target && needsTemplateExpansion ( asset . target ) ) {
81+ templatedAsset . target = template ( asset . target ) ( context ) ;
82+ }
83+ if ( asset . status && needsTemplateExpansion ( asset . status ) ) {
84+ templatedAsset . status = template ( asset . status ) ( context ) ;
85+ }
86+ return templatedAsset ;
87+ } else if ( Array . isArray ( asset ) ) {
88+ // Handle array of glob patterns - only apply templates if needed
89+ return asset . map ( pattern => needsTemplateExpansion ( pattern ) ? template ( pattern ) ( context ) : pattern ) ;
90+ } else {
91+ // String asset path - only apply template if needed
92+ return needsTemplateExpansion ( asset ) ? template ( asset ) ( context ) : asset ;
93+ }
94+ } ) ;
95+
5996 // Skip glob if url is provided
60- const urlAssets = assets . filter ( ( asset ) => asset . url ) ;
97+ const urlAssets = templatedAssets . filter ( ( asset ) => asset . url ) ;
6198 debug ( "url assets: %o" , urlAssets ) ;
6299 const globbedAssets = await getAssets (
63100 context ,
64- assets . filter ( ( asset ) => ! asset . url )
101+ templatedAssets . filter ( ( asset ) => ! asset . url )
65102 ) ;
66103 debug ( "globbed assets: %o" , globbedAssets ) ;
67104 const allAssets = [ ...urlAssets , ...globbedAssets ] ;
68105 debug ( "all assets: %o" , allAssets ) ;
69106
70107 await Promise . all (
71108 allAssets . map ( async ( asset ) => {
72- const path = template ( ( isPlainObject ( asset ) ? asset : { path : asset } ) . path ) ( context ) ;
73- const _url = asset . url ? template ( asset . url ) ( context ) : undefined ;
74- const label = asset . label ? template ( asset . label ) ( context ) : undefined ;
75- const type = asset . type ? template ( asset . type ) ( context ) : undefined ;
76- const filepath = asset . filepath ? template ( asset . filepath ) ( context ) : undefined ;
77- const target = asset . target ? template ( asset . target ) ( context ) : undefined ;
78- const status = asset . status ? template ( asset . status ) ( context ) : undefined ;
109+ // Templates may have been expanded before globbing, but we need to handle remaining cases
110+ const needsTemplateExpansion = ( str ) => str && typeof str === 'string' && str . includes ( '${' ) ;
111+
112+ const path = isPlainObject ( asset ) ? asset . path : asset ;
113+ const _url = asset . url ? ( needsTemplateExpansion ( asset . url ) ? template ( asset . url ) ( context ) : asset . url ) : undefined ;
114+ const label = asset . label ? ( needsTemplateExpansion ( asset . label ) ? template ( asset . label ) ( context ) : asset . label ) : undefined ;
115+ const type = asset . type ? ( needsTemplateExpansion ( asset . type ) ? template ( asset . type ) ( context ) : asset . type ) : undefined ;
116+ const filepath = asset . filepath ? ( needsTemplateExpansion ( asset . filepath ) ? template ( asset . filepath ) ( context ) : asset . filepath ) : undefined ;
117+ const target = asset . target ? ( needsTemplateExpansion ( asset . target ) ? template ( asset . target ) ( context ) : asset . target ) : undefined ;
118+ const status = asset . status ? ( needsTemplateExpansion ( asset . status ) ? template ( asset . status ) ( context ) : asset . status ) : undefined ;
79119
80120 if ( _url ) {
81121 assetsList . push ( { label, rawUrl : _url , type, filepath } ) ;
0 commit comments