From 6b8fa00e09f7c1af879a29d7ff941f0e8653450f Mon Sep 17 00:00:00 2001 From: Ashrith Reddy Date: Wed, 2 Oct 2019 13:53:22 +0530 Subject: [PATCH] Use installing package manager in README (#7687) --- packages/react-scripts/scripts/init.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 9b473ab3d95..b0460036635 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -135,6 +135,24 @@ module.exports = function( return; } + // modifies README.md commands based on user used package manager. + if (useYarn) { + try { + const readme = fs.readFileSync(path.join(appPath, 'README.md'), 'utf8'); + fs.writeFileSync( + path.join(appPath, 'README.md'), + readme + .replace(/npm start/g, 'yarn start') + .replace(/npm test/g, 'yarn test') + .replace(/npm run build/g, 'yarn build') + .replace(/npm run eject/g, 'yarn eject'), + 'utf8' + ); + } catch (err) { + // Silencing the error. As it fall backs to using default npm commands. + } + } + // Rename gitignore after the fact to prevent npm from renaming it to .npmignore // See: https://github.com/npm/npm/issues/1862 try {