Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for presence of folders before continuing eject. #951

Merged
merged 1 commit into from
Oct 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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));
Expand Down