@@ -11,12 +11,14 @@ async function processAndCopyFiles(
11
11
destDir : string ,
12
12
context : ProjectConfig ,
13
13
overwrite = true ,
14
+ ignorePatterns ?: string [ ] ,
14
15
) {
15
16
const sourceFiles = await globby ( sourcePattern , {
16
17
cwd : baseSourceDir ,
17
18
dot : true ,
18
19
onlyFiles : true ,
19
20
absolute : false ,
21
+ ignore : ignorePatterns ,
20
22
} ) ;
21
23
22
24
for ( const relativeSrcPath of sourceFiles ) {
@@ -26,28 +28,30 @@ async function processAndCopyFiles(
26
28
if ( relativeSrcPath . endsWith ( ".hbs" ) ) {
27
29
relativeDestPath = relativeSrcPath . slice ( 0 , - 4 ) ;
28
30
}
29
- const basename = path . basename ( relativeSrcPath ) ;
31
+
32
+ const basename = path . basename ( relativeDestPath ) ;
30
33
if ( basename === "_gitignore" ) {
31
- relativeDestPath = path . join ( path . dirname ( relativeSrcPath ) , ".gitignore" ) ;
34
+ relativeDestPath = path . join (
35
+ path . dirname ( relativeDestPath ) ,
36
+ ".gitignore" ,
37
+ ) ;
32
38
} else if ( basename === "_npmrc" ) {
33
- relativeDestPath = path . join ( path . dirname ( relativeSrcPath ) , ".npmrc" ) ;
39
+ relativeDestPath = path . join ( path . dirname ( relativeDestPath ) , ".npmrc" ) ;
34
40
}
35
41
36
42
const destPath = path . join ( destDir , relativeDestPath ) ;
37
43
38
- try {
39
- await fs . ensureDir ( path . dirname ( destPath ) ) ;
44
+ await fs . ensureDir ( path . dirname ( destPath ) ) ;
40
45
41
- if ( ! overwrite && ( await fs . pathExists ( destPath ) ) ) {
42
- continue ;
43
- }
46
+ if ( ! overwrite && ( await fs . pathExists ( destPath ) ) ) {
47
+ continue ;
48
+ }
44
49
45
- if ( srcPath . endsWith ( ".hbs" ) ) {
46
- await processTemplate ( srcPath , destPath , context ) ;
47
- } else {
48
- await fs . copy ( srcPath , destPath , { overwrite : true } ) ;
49
- }
50
- } catch ( _error ) { }
50
+ if ( srcPath . endsWith ( ".hbs" ) ) {
51
+ await processTemplate ( srcPath , destPath , context ) ;
52
+ } else {
53
+ await fs . copy ( srcPath , destPath , { overwrite : true } ) ;
54
+ }
51
55
}
52
56
}
53
57
@@ -655,26 +659,14 @@ export async function setupExamplesTemplate(
655
659
ignorePatterns . push ( "next/**" ) ;
656
660
}
657
661
658
- const generalServerFiles = await globby ( [ "**/*.ts" , "**/*.hbs" ] , {
659
- cwd : exampleServerSrc ,
660
- onlyFiles : true ,
661
- deep : 1 ,
662
- ignore : ignorePatterns ,
663
- } ) ;
664
-
665
- for ( const file of generalServerFiles ) {
666
- const srcPath = path . join ( exampleServerSrc , file ) ;
667
- const destPath = path . join ( serverAppDir , file . replace ( ".hbs" , "" ) ) ;
668
- try {
669
- if ( srcPath . endsWith ( ".hbs" ) ) {
670
- await processTemplate ( srcPath , destPath , context ) ;
671
- } else {
672
- if ( ! ( await fs . pathExists ( destPath ) ) ) {
673
- await fs . copy ( srcPath , destPath , { overwrite : false } ) ;
674
- }
675
- }
676
- } catch ( _error ) { }
677
- }
662
+ await processAndCopyFiles (
663
+ [ "**/*.ts" , "**/*.hbs" ] ,
664
+ exampleServerSrc ,
665
+ serverAppDir ,
666
+ context ,
667
+ false ,
668
+ ignorePatterns ,
669
+ ) ;
678
670
}
679
671
680
672
if ( webAppDirExists ) {
@@ -791,9 +783,13 @@ export async function handleExtras(projectDir: string, context: ProjectConfig) {
791
783
792
784
if ( context . packageManager === "bun" ) {
793
785
const bunfigSrc = path . join ( extrasDir , "bunfig.toml.hbs" ) ;
794
- const bunfigDest = path . join ( projectDir , "bunfig.toml" ) ;
795
786
if ( await fs . pathExists ( bunfigSrc ) ) {
796
- await processTemplate ( bunfigSrc , bunfigDest , context ) ;
787
+ await processAndCopyFiles (
788
+ "bunfig.toml.hbs" ,
789
+ extrasDir ,
790
+ projectDir ,
791
+ context ,
792
+ ) ;
797
793
}
798
794
}
799
795
@@ -802,9 +798,8 @@ export async function handleExtras(projectDir: string, context: ProjectConfig) {
802
798
( hasNative || context . frontend . includes ( "nuxt" ) )
803
799
) {
804
800
const npmrcTemplateSrc = path . join ( extrasDir , "_npmrc.hbs" ) ;
805
- const npmrcDest = path . join ( projectDir , ".npmrc" ) ;
806
801
if ( await fs . pathExists ( npmrcTemplateSrc ) ) {
807
- await processTemplate ( npmrcTemplateSrc , npmrcDest , context ) ;
802
+ await processAndCopyFiles ( "_npmrc.hbs" , extrasDir , projectDir , context ) ;
808
803
}
809
804
}
810
805
0 commit comments