@@ -12,11 +12,12 @@ if (!projectName) {
12
12
13
13
// create project directory
14
14
const projectDir = path . resolve ( process . cwd ( ) , projectName )
15
- if ( fs . existsSync ( projectDir ) ) {
16
- console . error ( `Error: Directory '${ projectName } ' already exists.` )
17
- process . exit ( 1 )
15
+ const isProjectDirExists = fs . existsSync ( projectDir )
16
+ if ( isProjectDirExists ) {
17
+ console . warn ( `Warning: Directory '${ projectName } ' already exists.` )
18
+ } else {
19
+ fs . mkdirSync ( projectDir , { recursive : true } )
18
20
}
19
- fs . mkdirSync ( projectDir , { recursive : true } )
20
21
21
22
// copy files
22
23
const files = [
@@ -31,16 +32,18 @@ const files = [
31
32
'commitlint.config.ts' ,
32
33
'eslint.config.ts' ,
33
34
'jest.config.ts' ,
35
+ 'tsconfig.json' ,
34
36
]
35
37
for ( const file of files ) {
36
38
const src = path . resolve ( __dirname , '..' , file )
37
39
const dest = path . resolve ( projectDir , file )
38
40
fs . mkdirSync ( path . dirname ( dest ) , { recursive : true } )
39
- if ( fs . existsSync ( dest ) ) {
40
- console . error ( `Error: File '${ file } ' already exists in the destination.` )
41
- process . exit ( 1 )
41
+ const isDestFileExists = fs . existsSync ( dest )
42
+ if ( isDestFileExists ) {
43
+ console . warn ( `Warning: File '${ file } ' already exists in the destination.` )
44
+ } else {
45
+ fs . copyFileSync ( src , dest )
42
46
}
43
- fs . copyFileSync ( src , dest )
44
47
}
45
48
46
49
// create package.json
@@ -63,7 +66,19 @@ const packageJsonFile = JSON.stringify(packageJson, null, 2)
63
66
fs . writeFileSync ( packageJsonPath , packageJsonFile )
64
67
65
68
// create empty src/index.ts
66
- fs . mkdirSync ( path . resolve ( projectDir , 'src' ) )
67
- fs . writeFileSync ( path . resolve ( projectDir , 'src/index.ts' ) , '' )
69
+ const srcDir = path . resolve ( projectDir , 'src' )
70
+ const isSrcDirExists = fs . existsSync ( srcDir )
71
+ if ( isSrcDirExists ) {
72
+ console . warn ( `Warning: Directory 'src' already exists in the destination.` )
73
+ } else {
74
+ fs . mkdirSync ( srcDir )
75
+ }
76
+ const srcIndexPath = path . resolve ( srcDir , 'index.ts' )
77
+ const isSrcIndexExists = fs . existsSync ( srcIndexPath )
78
+ if ( isSrcIndexExists ) {
79
+ console . warn ( `Warning: File 'index.ts' already exists in the destination.` )
80
+ } else {
81
+ fs . writeFileSync ( srcIndexPath , '' )
82
+ }
68
83
69
84
console . log ( `Success! Created '${ projectName } ' at ${ projectDir } ` )
0 commit comments