Skip to content

Commit 9f3f97d

Browse files
chitchuSpaceK33z
authored andcommitted
Gracefully handle initial installation error (facebook#1512)
* Gracefully handle initial installation error * Print out message when problem occurs * Delete project folder on errors * Fix directory deleting message Resolves facebook#1505 # Conflicts: # tasks/e2e-installs.sh
1 parent 084f4b2 commit 9f3f97d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/create-react-cy-app/index.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,30 @@ function run(root, appName, version, verbose, originalDirectory, template) {
182182

183183
install(allDependencies, verbose, function(code, command, args) {
184184
if (code !== 0) {
185-
console.error(chalk.cyan(command + ' ' + args.join(' ')) + ' failed');
185+
console.log();
186+
console.error('Aborting installation.', chalk.cyan(command + ' ' + args.join(' ')), 'has failed.');
187+
// On 'exit' we will delete these files from target directory.
188+
var knownGeneratedFiles = [
189+
'package.json', 'npm-debug.log', 'yarn-error.log', 'yarn-debug.log', 'node_modules'
190+
];
191+
var currentFiles = fs.readdirSync(path.join(root));
192+
currentFiles.forEach(function (file) {
193+
knownGeneratedFiles.forEach(function (fileToMatch) {
194+
// This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
195+
// and the rest of knownGeneratedFiles.
196+
if ((fileToMatch.match(/.log/g) && file.indexOf(fileToMatch) === 0) || file === fileToMatch) {
197+
console.log('Deleting generated file...', chalk.cyan(file));
198+
fs.removeSync(path.join(root, file));
199+
}
200+
});
201+
});
202+
var remainingFiles = fs.readdirSync(path.join(root));
203+
if (!remainingFiles.length) {
204+
// Delete target folder if empty
205+
console.log('Deleting', chalk.cyan(appName + '/'), 'from', chalk.cyan(path.resolve(root, '..')));
206+
fs.removeSync(path.join(root));
207+
}
208+
console.log('Done.');
186209
process.exit(1);
187210
}
188211

0 commit comments

Comments
 (0)