From 7ce4b6e0e436feff0a38cebb123eefdf6a6dc399 Mon Sep 17 00:00:00 2001 From: Alice Rose Date: Fri, 28 Oct 2016 14:54:56 +0200 Subject: [PATCH] Check for presence of folders before continuing eject. Closes #939. (#951) --- packages/react-scripts/scripts/eject.js | 38 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index d14aec6abef..dbd4d64e4d5 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -30,6 +30,25 @@ prompt( var ownPath = path.join(__dirname, '..'); var appPath = path.join(ownPath, '..', '..'); + + function verifyAbsent(file) { + if (fs.existsSync(path.join(appPath, file))) { + console.error( + '`' + file + '` already exists in your app folder. We cannot ' + + 'continue as you would lose all the changes in that file or directory. ' + + 'Please move or delete it (maybe make a copy for backup) and run this ' + + 'command again.' + ); + process.exit(1); + } + } + + var folders = [ + 'config', + path.join('config', 'jest'), + 'scripts' + ]; + var files = [ path.join('config', 'env.js'), path.join('config', 'paths.js'), @@ -44,22 +63,13 @@ prompt( ]; // Ensure that the app folder is clean and we won't override any files - files.forEach(function(file) { - if (fs.existsSync(path.join(appPath, file))) { - console.error( - '`' + file + '` already exists in your app folder. We cannot ' + - 'continue as you would lose all the changes in that file or directory. ' + - 'Please delete it (maybe make a copy for backup) and run this ' + - 'command again.' - ); - process.exit(1); - } - }); + folders.forEach(verifyAbsent); + files.forEach(verifyAbsent); // Copy the files over - fs.mkdirSync(path.join(appPath, 'config')); - fs.mkdirSync(path.join(appPath, 'config', 'jest')); - fs.mkdirSync(path.join(appPath, 'scripts')); + folders.forEach(function(folder) { + fs.mkdirSync(path.join(appPath, folder)) + }); console.log(); console.log(cyan('Copying files into ' + appPath));