@@ -45,13 +45,18 @@ function toPascalCase(filename) {
4545 * Get TypeScript files from src/examples directory
4646 */
4747function getExampleFiles ( ) {
48- const examplesDir = path . join ( __dirname , "../src/examples" ) ;
48+ const catalogPath = path . join (
49+ __dirname ,
50+ "../src/utils/examples-catalog.json" ,
51+ ) ;
4952
50- if ( ! fs . existsSync ( examplesDir ) ) {
51- throw new Error ( `Examples directory not found: ${ examplesDir } ` ) ;
53+ if ( ! fs . existsSync ( catalogPath ) ) {
54+ throw new Error ( `Examples directory not found: ${ catalogPath } ` ) ;
5255 }
5356
54- const exampleFiles = [ ] ;
57+ const catalog = JSON . parse ( fs . readFileSync ( catalogPath , "utf8" ) ) ;
58+
59+ const exampleFiles = catalog . map ( ( example ) => example . name ) ;
5560
5661 // Read all directories in examples
5762 const entries = fs . readdirSync ( examplesDir , { withFileTypes : true } ) ;
@@ -105,25 +110,25 @@ function getExampleFiles() {
105110/**
106111 * Create a Lambda function resource configuration
107112 */
108- function createFunctionResource ( filename , skipVerboseLogging = false ) {
109- const resourceName = toPascalCase ( filename ) ;
110- const config = EXAMPLE_CONFIGS [ filename ] || DEFAULT_CONFIG ;
113+ function createFunctionResource (
114+ resourceName ,
115+ catalog ,
116+ skipVerboseLogging = false ,
117+ ) {
118+ const config = EXAMPLE_CONFIGS [ resourceName ] || DEFAULT_CONFIG ;
111119
112120 const functionResource = {
113121 Type : "AWS::Serverless::Function" ,
114122 Properties : {
115- FunctionName : ` ${ resourceName } -TypeScript` ,
123+ FunctionName : resourceName ,
116124 CodeUri : "./dist" ,
117- Handler : ` ${ filename } .handler` ,
125+ Handler : catalog . handler ,
118126 Runtime : "nodejs22.x" ,
119127 Architectures : [ "x86_64" ] ,
120128 MemorySize : config . memorySize ,
121129 Timeout : config . timeout ,
122130 Role : { "Fn::GetAtt" : [ "DurableFunctionRole" , "Arn" ] } ,
123- DurableConfig : {
124- ExecutionTimeout : 3600 ,
125- RetentionPeriodInDays : 7 ,
126- } ,
131+ DurableConfig : catalog . durableConfig ,
127132 Environment : {
128133 Variables : {
129134 AWS_ENDPOINT_URL_LAMBDA : "http://host.docker.internal:5000" ,
@@ -149,9 +154,20 @@ function createFunctionResource(filename, skipVerboseLogging = false) {
149154 * Generate the complete CloudFormation template
150155 */
151156function generateTemplate ( skipVerboseLogging = false ) {
152- const exampleFiles = getExampleFiles ( ) ;
157+ const examplesCatalogPath = path . join (
158+ __dirname ,
159+ "../src/utils/examples-catalog.json" ,
160+ ) ;
161+
162+ if ( ! fs . existsSync ( examplesCatalogPath ) ) {
163+ throw new Error ( `Examples directory not found: ${ examplesCatalogPath } ` ) ;
164+ }
165+
166+ const examplesCatalog = JSON . parse (
167+ fs . readFileSync ( examplesCatalogPath , "utf8" ) ,
168+ ) ;
153169
154- if ( exampleFiles . length === 0 ) {
170+ if ( examplesCatalog . length === 0 ) {
155171 throw new Error ( "No TypeScript example files found in src/examples" ) ;
156172 }
157173
@@ -202,12 +218,11 @@ function generateTemplate(skipVerboseLogging = false) {
202218 } ;
203219
204220 // Generate resources for each example file
205- exampleFiles . forEach ( ( filename ) => {
206- const resourceName = toPascalCase ( filename ) ;
207- template . Resources [ resourceName ] = createFunctionResource (
208- filename ,
209- skipVerboseLogging ,
210- ) ;
221+ examplesCatalog . forEach ( ( catalog ) => {
222+ const resourceName = catalog . name . replace ( / \s / g, "" ) + `-22x-NodeJS-Local` ;
223+ template . Resources [
224+ toPascalCase ( catalog . handler . slice ( 0 , - ".handler" . length ) )
225+ ] = createFunctionResource ( resourceName , catalog , skipVerboseLogging ) ;
211226 } ) ;
212227
213228 return template ;
0 commit comments