|
10 | 10 | var fs = require('fs-extra');
|
11 | 11 | var path = require('path');
|
12 | 12 | var spawn = require('cross-spawn');
|
| 13 | +var pathExists = require('path-exists'); |
| 14 | +var chalk = require('chalk'); |
13 | 15 |
|
14 | 16 | module.exports = function(appPath, appName, verbose, originalDirectory) {
|
15 | 17 | var ownPath = path.join(appPath, 'node_modules', 'react-scripts');
|
@@ -43,12 +45,28 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
|
43 | 45 | JSON.stringify(appPackage, null, 2)
|
44 | 46 | );
|
45 | 47 |
|
| 48 | + var readmeExists = pathExists.sync(path.join(appPath, 'README.md')); |
| 49 | + if (readmeExists) { |
| 50 | + fs.renameSync(path.join(appPath, 'README.md'), path.join(appPath, 'README.old.md')); |
| 51 | + } |
| 52 | + |
46 | 53 | // Copy the files for the user
|
47 | 54 | fs.copySync(path.join(ownPath, 'template'), appPath);
|
48 | 55 |
|
49 | 56 | // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
|
50 | 57 | // See: https://github.com/npm/npm/issues/1862
|
51 |
| - fs.move(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), []); |
| 58 | + fs.move(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), [], function (err) { |
| 59 | + if (err) { |
| 60 | + // Append if there's already a `.gitignore` file there |
| 61 | + if (err.code === 'EEXIST') { |
| 62 | + var data = fs.readFileSync(path.join(appPath, 'gitignore')); |
| 63 | + fs.appendFileSync(path.join(appPath, '.gitignore'), data); |
| 64 | + fs.unlinkSync(path.join(appPath, 'gitignore')); |
| 65 | + } else { |
| 66 | + throw err; |
| 67 | + } |
| 68 | + } |
| 69 | + }); |
52 | 70 |
|
53 | 71 | // Run another npm install for react and react-dom
|
54 | 72 | console.log('Installing react and react-dom from npm...');
|
@@ -88,6 +106,10 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
|
88 | 106 | console.log();
|
89 | 107 | console.log(' cd', cdpath);
|
90 | 108 | console.log(' npm start');
|
| 109 | + if (readmeExists) { |
| 110 | + console.log(); |
| 111 | + console.log(chalk.yellow('You had a `README.md` file, we renamed it to `README.old.md`')); |
| 112 | + } |
91 | 113 | console.log();
|
92 | 114 | console.log('Happy hacking!');
|
93 | 115 | });
|
|
0 commit comments