@@ -30,6 +30,25 @@ prompt(
30
30
31
31
var ownPath = path . join ( __dirname , '..' ) ;
32
32
var appPath = path . join ( ownPath , '..' , '..' ) ;
33
+
34
+ function verifyAbsent ( file ) {
35
+ if ( fs . existsSync ( path . join ( appPath , file ) ) ) {
36
+ console . error (
37
+ '`' + file + '` already exists in your app folder. We cannot ' +
38
+ 'continue as you would lose all the changes in that file or directory. ' +
39
+ 'Please move or delete it (maybe make a copy for backup) and run this ' +
40
+ 'command again.'
41
+ ) ;
42
+ process . exit ( 1 ) ;
43
+ }
44
+ }
45
+
46
+ var folders = [
47
+ 'config' ,
48
+ path . join ( 'config' , 'jest' ) ,
49
+ 'scripts'
50
+ ] ;
51
+
33
52
var files = [
34
53
path . join ( 'config' , 'env.js' ) ,
35
54
path . join ( 'config' , 'paths.js' ) ,
@@ -44,22 +63,13 @@ prompt(
44
63
] ;
45
64
46
65
// Ensure that the app folder is clean and we won't override any files
47
- files . forEach ( function ( file ) {
48
- if ( fs . existsSync ( path . join ( appPath , file ) ) ) {
49
- console . error (
50
- '`' + file + '` already exists in your app folder. We cannot ' +
51
- 'continue as you would lose all the changes in that file or directory. ' +
52
- 'Please delete it (maybe make a copy for backup) and run this ' +
53
- 'command again.'
54
- ) ;
55
- process . exit ( 1 ) ;
56
- }
57
- } ) ;
66
+ folders . forEach ( verifyAbsent ) ;
67
+ files . forEach ( verifyAbsent ) ;
58
68
59
69
// Copy the files over
60
- fs . mkdirSync ( path . join ( appPath , 'config' ) ) ;
61
- fs . mkdirSync ( path . join ( appPath , 'config' , 'jest' ) ) ;
62
- fs . mkdirSync ( path . join ( appPath , 'scripts' ) ) ;
70
+ folders . forEach ( function ( folder ) {
71
+ fs . mkdirSync ( path . join ( appPath , folder ) )
72
+ } ) ;
63
73
64
74
console . log ( ) ;
65
75
console . log ( cyan ( 'Copying files into ' + appPath ) ) ;
0 commit comments