mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-24 05:05:53 +08:00
fix: proactively append to .gitignore during init (#8028)
This commit is contained in:
committed by
Brody McKee
parent
30eaab4ef2
commit
18e56da3b7
21
packages/react-scripts/scripts/init.js
vendored
21
packages/react-scripts/scripts/init.js
vendored
@@ -190,23 +190,20 @@ module.exports = function(
|
||||
}
|
||||
}
|
||||
|
||||
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
|
||||
// See: https://github.com/npm/npm/issues/1862
|
||||
try {
|
||||
const gitignoreExists = fs.existsSync(path.join(appPath, '.gitignore'));
|
||||
if (gitignoreExists) {
|
||||
// Append if there's already a `.gitignore` file there
|
||||
const data = fs.readFileSync(path.join(appPath, 'gitignore'));
|
||||
fs.appendFileSync(path.join(appPath, '.gitignore'), data);
|
||||
fs.unlinkSync(path.join(appPath, 'gitignore'));
|
||||
} else {
|
||||
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
|
||||
// See: https://github.com/npm/npm/issues/1862
|
||||
fs.moveSync(
|
||||
path.join(appPath, 'gitignore'),
|
||||
path.join(appPath, '.gitignore'),
|
||||
[]
|
||||
);
|
||||
} catch (err) {
|
||||
// Append if there's already a `.gitignore` file there
|
||||
if (err.code === 'EEXIST') {
|
||||
const data = fs.readFileSync(path.join(appPath, 'gitignore'));
|
||||
fs.appendFileSync(path.join(appPath, '.gitignore'), data);
|
||||
fs.unlinkSync(path.join(appPath, 'gitignore'));
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
let command;
|
||||
|
||||
Reference in New Issue
Block a user