1+ #!/usr/bin/env node
2+
3+ import fs from 'fs' ;
4+ import path from 'path' ;
5+ import { fileURLToPath } from 'url' ;
6+
7+ const __filename = fileURLToPath ( import . meta. url ) ;
8+ const __dirname = path . dirname ( __filename ) ;
9+ const projectRoot = path . resolve ( __dirname , '..' ) ;
10+
11+ console . log ( '📁 Copying Handlebars templates to dist folder...' ) ;
12+
13+ const srcTemplatesDir = path . join ( projectRoot , 'src' , 'features' , 'schema' , 'templates' ) ;
14+ const distTemplatesDir = path . join ( projectRoot , 'dist' , 'features' , 'schema' , 'templates' ) ;
15+
16+ try {
17+ // Ensure destination directory exists
18+ fs . mkdirSync ( distTemplatesDir , { recursive : true } ) ;
19+
20+ // Read all files in the templates directory
21+ const templateFiles = fs . readdirSync ( srcTemplatesDir ) . filter ( file => file . endsWith ( '.hbs' ) ) ;
22+
23+ if ( templateFiles . length === 0 ) {
24+ console . log ( '⚠️ No .hbs template files found in source directory' ) ;
25+ process . exit ( 0 ) ;
26+ }
27+
28+ // Copy each template file
29+ let copiedCount = 0 ;
30+ for ( const file of templateFiles ) {
31+ const srcPath = path . join ( srcTemplatesDir , file ) ;
32+ const distPath = path . join ( distTemplatesDir , file ) ;
33+
34+ fs . copyFileSync ( srcPath , distPath ) ;
35+ console . log ( ` ✅ Copied ${ file } ` ) ;
36+ copiedCount ++ ;
37+ }
38+
39+ console . log ( `📋 Successfully copied ${ copiedCount } Handlebars template(s) to dist folder` ) ;
40+ } catch ( error ) {
41+ console . error ( '❌ Error copying templates:' , error . message ) ;
42+ process . exit ( 1 ) ;
43+ }
0 commit comments