@@ -15,9 +15,6 @@ const TEMPLATES_DIR: string = path.resolve(ROOT, 'templates');
1515
1616const DEFAULT_TEMPLATE = 'node-graphql' ;
1717
18- // Files from the template that get copied into generated/<name>/
19- const WORKSPACE_FILES = [ 'package.json' , 'tsconfig.json' , 'index.ts' ] ;
20-
2118interface FunctionManifest {
2219 name : string ;
2320 version : string ;
@@ -70,6 +67,24 @@ function resolveTemplateDir(manifest: FunctionManifest): string {
7067 return templateDir ;
7168}
7269
70+ // --- Template file discovery ---
71+
72+ function walkTemplateFiles ( dir : string , base : string = '' ) : string [ ] {
73+ const results : string [ ] = [ ] ;
74+ const entries = fs . readdirSync ( dir ) as string [ ] ;
75+ for ( const entry of entries ) {
76+ const fullPath = path . join ( dir , entry ) ;
77+ const relPath = base ? path . join ( base , entry ) : entry ;
78+ const stat = fs . statSync ( fullPath ) ;
79+ if ( stat . isDirectory ( ) ) {
80+ results . push ( ...walkTemplateFiles ( fullPath , relPath ) ) ;
81+ } else {
82+ results . push ( relPath ) ;
83+ }
84+ }
85+ return results ;
86+ }
87+
7388// --- Placeholder replacement ---
7489
7590function replacePlaceholders ( content : string , manifest : FunctionManifest ) : string {
@@ -183,18 +198,23 @@ function main(): void {
183198
184199 console . log ( ` Generating ${ fnName } (template: ${ manifest . type || DEFAULT_TEMPLATE } )...` ) ;
185200
186- // Copy and process template files
187- for ( const fileName of WORKSPACE_FILES ) {
188- const templateFile = path . join ( templateDir , fileName ) ;
189- if ( ! fs . existsSync ( templateFile ) ) {
190- console . warn ( ` ! Template file missing: ${ fileName } ` ) ;
191- continue ;
201+ // Walk all template files and copy/process them
202+ const templateFiles = walkTemplateFiles ( templateDir ) ;
203+ for ( const relPath of templateFiles ) {
204+ const templateFile = path . join ( templateDir , relPath ) ;
205+ const outputFile = path . join ( genDir , relPath ) ;
206+
207+ // Ensure subdirectories exist (e.g., k8s/)
208+ const outputDir = path . dirname ( outputFile ) ;
209+ if ( ! fs . existsSync ( outputDir ) ) {
210+ fs . mkdirSync ( outputDir , { recursive : true } ) ;
192211 }
193212
194213 const templateContent = fs . readFileSync ( templateFile , 'utf-8' ) ;
195- const processed = processTemplateFile ( fileName , templateContent , manifest , fnDir ) ;
196- const changed = writeIfChanged ( path . join ( genDir , fileName ) , processed ) ;
197- if ( changed ) console . log ( ` - ${ fileName } ` ) ;
214+ const baseName = path . basename ( relPath ) ;
215+ const processed = processTemplateFile ( baseName , templateContent , manifest , fnDir ) ;
216+ const changed = writeIfChanged ( outputFile , processed ) ;
217+ if ( changed ) console . log ( ` - ${ relPath } ` ) ;
198218 }
199219
200220 // Symlink handler.ts
0 commit comments