@@ -30,6 +30,25 @@ prompt(
3030
3131 var ownPath = path . join ( __dirname , '..' ) ;
3232 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+
3352 var files = [
3453 path . join ( 'config' , 'env.js' ) ,
3554 path . join ( 'config' , 'paths.js' ) ,
@@ -44,22 +63,13 @@ prompt(
4463 ] ;
4564
4665 // 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 ) ;
5868
5969 // 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+ } ) ;
6373
6474 console . log ( ) ;
6575 console . log ( cyan ( 'Copying files into ' + appPath ) ) ;
0 commit comments