@@ -85,22 +85,34 @@ const writePackageMetadata = async (ctx: PluginContext) => {
85
85
)
86
86
}
87
87
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
+
88
94
/** Get's the content of the handler file that will be written to the lambda */
89
95
const getHandlerFile = async ( ctx : PluginContext ) : Promise < string > => {
90
96
const templatesDir = join ( ctx . pluginDir , 'dist/build/templates' )
91
97
98
+ const templateVariables : Record < string , string > = {
99
+ '{{useRegionalBlobs}}' : ctx . useRegionalBlobs . toString ( ) ,
100
+ }
92
101
// In this case it is a monorepo and we need to use a own template for it
93
102
// as we have to change the process working directory
94
103
if ( ctx . relativeAppDir . length !== 0 ) {
95
104
const template = await readFile ( join ( templatesDir , 'handler-monorepo.tmpl.js' ) , 'utf-8' )
96
105
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 )
101
110
}
102
111
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
+ )
104
116
}
105
117
106
118
const writeHandlerFile = async ( ctx : PluginContext ) => {
0 commit comments