@@ -3,28 +3,28 @@ const path = require("path");
3
3
4
4
function createQuestion ( newPath ) {
5
5
return new Promise ( ( resolve , reject ) => {
6
+ const newDir = path . normalize ( `./src/${ newPath } ` ) ;
7
+ const sourceFilePath = path . normalize ( "./common/template/template.js" )
8
+ const newFilePath = path . join ( newDir , "index.js" )
6
9
// 判断是否存在
7
- fs . exists ( newPath , ( exists ) => {
10
+ fs . exists ( newFilePath , ( exists ) => {
8
11
if ( exists ) {
9
12
reject ( `./src/${ newPath } 已存在,请检查目录!` ) ;
10
- return ;
11
- }
12
- try {
13
- const newDir = path . normalize ( `./src/${ newPath } ` ) ;
14
- const sourceFilePath = path . normalize ( "./common/template/template.js" )
15
- const newFilePath = path . join ( newDir , "index.js" )
16
- // 创建目录
17
- fs . mkdir ( newDir , { recursive : true } , ( ) => {
18
- // 复制文件
19
- fs . copyFile ( sourceFilePath , newFilePath , 0 , ( ) => {
20
- resolve ( newFilePath ) ;
21
- console . log ( `File '${ sourceFilePath } ' copied to '${ newFilePath } '` ) ;
13
+ } else {
14
+ try {
15
+
16
+ // 创建目录
17
+ fs . mkdir ( newDir , { recursive : true } , ( ) => {
18
+ // 复制文件
19
+ fs . copyFile ( sourceFilePath , newFilePath , 0 , ( ) => {
20
+ resolve ( newFilePath ) ;
21
+ console . log ( `File '${ sourceFilePath } ' copied to '${ newFilePath } '` ) ;
22
+ } ) ;
22
23
} ) ;
23
- } ) ;
24
- } catch ( error ) {
25
- reject ( 'Error:' , error . message ) ;
24
+ } catch ( error ) {
25
+ reject ( 'Error:' , error . message ) ;
26
+ }
26
27
}
27
-
28
28
} )
29
29
} )
30
30
}
0 commit comments