@@ -4,10 +4,11 @@ import { existsSync, promises as fs } from 'fs';
4
4
import path from 'path' ;
5
5
import { COMPONENTS } from '../src/items/components' ;
6
6
import { TEMPLATES } from '../src/items/templates' ;
7
+ import { copyFolder } from '../src/utils/copy-folder' ;
7
8
8
9
async function main ( ) {
9
10
for ( const template of TEMPLATES ) {
10
- await copyFolder ( template . path ) ;
11
+ await copyFolder ( template . path , template . name ) ;
11
12
}
12
13
for ( const comp of COMPONENTS ) {
13
14
if ( Array . isArray ( comp . paths ) ) {
@@ -34,33 +35,3 @@ async function writeFiles(paths: Array<{ from: string; to: { folder: string; fil
34
35
}
35
36
}
36
37
}
37
-
38
- async function copyFolder ( src : string , destPath ?: string ) {
39
- if ( ! existsSync ( src ) ) {
40
- throw new Error ( `Source folder does not exist: ${ src } ` ) ;
41
- }
42
-
43
- const paths = src . split ( '/' ) ;
44
- const folderName = paths [ paths . length - 1 ] ;
45
-
46
- const dest = destPath ?? path . join ( '__generated' , folderName ) ;
47
-
48
- if ( ! existsSync ( dest ) ) {
49
- await fs . mkdir ( dest , { recursive : true } ) ;
50
- }
51
-
52
- const entries = await fs . readdir ( src , { withFileTypes : true } ) ;
53
-
54
- for ( const entry of entries ) {
55
- const srcPath = path . join ( src , entry . name ) ;
56
- const destPath = path . join ( dest , entry . name ) ;
57
-
58
- if ( entry . isDirectory ( ) ) {
59
- // Recursively copy subdirectories
60
- await copyFolder ( srcPath , destPath ) ;
61
- } else if ( entry . isFile ( ) ) {
62
- // Copy files
63
- await fs . copyFile ( srcPath , destPath ) ;
64
- }
65
- }
66
- }
0 commit comments