@@ -85,22 +85,34 @@ const writePackageMetadata = async (ctx: PluginContext) => {
8585 )
8686}
8787
88+ const applyTemplateVariables = ( template : string , variables : Record < string , string > ) => {
89+ return Object . entries ( variables ) . reduce ( ( acc , [ key , value ] ) => {
90+ return acc . replaceAll ( key , value )
91+ } , template )
92+ }
93+
8894/** Get's the content of the handler file that will be written to the lambda */
8995const getHandlerFile = async ( ctx : PluginContext ) : Promise < string > => {
9096 const templatesDir = join ( ctx . pluginDir , 'dist/build/templates' )
9197
98+ const templateVariables : Record < string , string > = {
99+ '{{useRegionalBlobs}}' : ctx . useRegionalBlobs . toString ( ) ,
100+ }
92101 // In this case it is a monorepo and we need to use a own template for it
93102 // as we have to change the process working directory
94103 if ( ctx . relativeAppDir . length !== 0 ) {
95104 const template = await readFile ( join ( templatesDir , 'handler-monorepo.tmpl.js' ) , 'utf-8' )
96105
97- return template
98- . replaceAll ( '{{cwd }}' , posixJoin ( ctx . lambdaWorkingDirectory ) )
99- . replace ( '{{nextServerHandler}}' , posixJoin ( ctx . nextServerHandler ) )
100- . replace ( '{{useRegionalBlobs}}' , ctx . useRegionalBlobs . toString ( ) )
106+ templateVariables [ '{{cwd}}' ] = posixJoin ( ctx . lambdaWorkingDirectory )
107+ templateVariables [ '{{nextServerHandler }}' ] = posixJoin ( ctx . nextServerHandler )
108+
109+ return applyTemplateVariables ( template , templateVariables )
101110 }
102111
103- return await readFile ( join ( templatesDir , 'handler.tmpl.js' ) , 'utf-8' )
112+ return applyTemplateVariables (
113+ await readFile ( join ( templatesDir , 'handler.tmpl.js' ) , 'utf-8' ) ,
114+ templateVariables ,
115+ )
104116}
105117
106118const writeHandlerFile = async ( ctx : PluginContext ) => {
0 commit comments