1
- import fs from 'fs' ;
2
- import path from ' path' ;
1
+ import fs from "fs" ;
2
+ import path from " path" ;
3
3
4
4
interface TemplateFilesObject {
5
5
path : string ;
@@ -11,27 +11,45 @@ interface TemplateFilesObject {
11
11
}
12
12
export type Template = TemplateFilesObject [ ] ;
13
13
14
- export const templateGenerator = ( template : Template , templateDir : string , destinationDir : string ) => {
14
+ export const templateGenerator = (
15
+ template : Template ,
16
+ templateDir : string ,
17
+ destinationDir : string ,
18
+ ) => {
15
19
template . forEach ( ( templateFilesObject ) => {
16
20
templateFilesObject . files . forEach ( ( file ) => {
17
21
// Construct source and destination paths
18
22
const source = path . join ( templateDir , file ) ;
19
23
// console.log(source);
20
- const destination = path . join ( destinationDir , templateFilesObject . path , file ) ;
24
+ const destination = path . join (
25
+ destinationDir ,
26
+ templateFilesObject . path ,
27
+ file ,
28
+ ) ;
21
29
// check if the directory exists, if not create it
22
30
if ( ! fs . existsSync ( path . join ( destinationDir , templateFilesObject . path ) ) ) {
23
- fs . mkdirSync ( path . join ( destinationDir , templateFilesObject . path ) , { recursive : true } ) ;
31
+ fs . mkdirSync ( path . join ( destinationDir , templateFilesObject . path ) , {
32
+ recursive : true ,
33
+ } ) ;
24
34
}
25
35
fs . copyFileSync ( source , destination ) ;
26
36
27
37
// Handle file renaming if needed
28
38
if ( templateFilesObject . rename ) {
29
39
templateFilesObject . rename . forEach ( ( rename ) => {
30
- const oldPath = path . join ( process . cwd ( ) , templateFilesObject . path , rename . from ) ;
31
- const newPath = path . join ( process . cwd ( ) , templateFilesObject . path , rename . to ) ;
40
+ const oldPath = path . join (
41
+ process . cwd ( ) ,
42
+ templateFilesObject . path ,
43
+ rename . from ,
44
+ ) ;
45
+ const newPath = path . join (
46
+ process . cwd ( ) ,
47
+ templateFilesObject . path ,
48
+ rename . to ,
49
+ ) ;
32
50
fs . renameSync ( oldPath , newPath ) ;
33
51
} ) ;
34
52
}
35
53
} ) ;
36
54
} ) ;
37
- } ;
55
+ } ;
0 commit comments