From 03435a2070139db0543f604ece6d6b2a2669b367 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Thu, 15 Dec 2016 15:37:57 +0200 Subject: [PATCH 01/10] Create git repo with initial commit --- packages/react-scripts/scripts/init.js | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index aa62265ccc5..eb08d6dd614 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -11,6 +11,34 @@ var fs = require('fs-extra'); var path = require('path'); var spawn = require('cross-spawn'); var chalk = require('chalk'); +var execSync = require('child_process').execSync; + +function insideGitRepository() { + try { + execSync('git rev-parse --is-inside-work-tree', {stdio: 'ignore'}); + return true; + } catch (e) { + return false; + } +} + +function gitInit() { + try { + execSync('git --version', {stdio: 'ignore'}); + + if (insideGitRepository()) { + return false; + } + + execSync('git init', {stdio: 'ignore'}); + execSync('git add .', {stdio: 'ignore'}); + execSync('git commit -m "chore: initial commit from react-create-app"', {stdio: 'ignore'}); + + return true; + } catch (e) { + return false; + } +} module.exports = function(appPath, appName, verbose, originalDirectory, template) { var ownPackageName = require(path.join(__dirname, '..', 'package.json')).name; @@ -64,6 +92,10 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template } }); + if (gitInit()) { + console.log('Initializing git repository'); + } + var command; var args; From ec1fe1887c9bc316e4d4f1521fe22d448092af0f Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Tue, 27 Dec 2016 13:50:20 +0100 Subject: [PATCH 02/10] Fixe commit message --- packages/react-scripts/scripts/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index eb08d6dd614..39c97f508e5 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -32,7 +32,7 @@ function gitInit() { execSync('git init', {stdio: 'ignore'}); execSync('git add .', {stdio: 'ignore'}); - execSync('git commit -m "chore: initial commit from react-create-app"', {stdio: 'ignore'}); + execSync('git commit -m "chore: initial commit from create-react-app"', {stdio: 'ignore'}); return true; } catch (e) { From a721762ad7a262a095ffcf304724db5e15cb278c Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Thu, 29 Dec 2016 11:08:10 +0100 Subject: [PATCH 03/10] Added the git repo to the docs --- README.md | 1 + packages/react-scripts/template/README.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 39baa1a5073..e658b84f73f 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ The [User Guide](https://github.com/facebookincubator/create-react-app/blob/mast - [Running Tests](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests) - [Developing Components in Isolation](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#developing-components-in-isolation) - [Making a Progressive Web App](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#making-a-progressive-web-app) +- [Git Repository](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#git-repository) - [Deployment](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment) - [Advanced Configuration](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration) - [Troubleshooting](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#troubleshooting) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index e290b935625..14aa23e1ba4 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -61,6 +61,7 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Editor Integration](#editor-integration) - [Developing Components in Isolation](#developing-components-in-isolation) - [Making a Progressive Web App](#making-a-progressive-web-app) +- [Git Repository](#git-repository) - [Deployment](#deployment) - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing) - [Building for Relative Paths](#building-for-relative-paths) @@ -1206,6 +1207,12 @@ Learn more about React Storybook: You can turn your React app into a [Progressive Web App](https://developers.google.com/web/progressive-web-apps/) by following the steps in [this repository](https://github.com/jeffposnick/create-react-pwa). +## Git Repository + +Create React App will create a new Git repository and commit the generated files to it as the initial commit. This step is skipped if the folder you are creating is already part of a larger Git repository. +The initial commit will be created with a message **chore: initial commit from create-react-app**. If you prefer another message it is easy to change before doing any other commits using the command ```git commit --amend -m "Some other message"```. +You can delete the Git repository using the command ```rm -rf .git```. + ## Deployment `npm run build` creates a `build` directory with a production build of your app. Set up your favourite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main..js` are served with the contents of the `/static/js/main..js` file. For example, Python contains a built-in HTTP server that can serve static files: From 66fdb9a04b8e70aa46b9f9d8b61daad44f6e72e4 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Thu, 9 Feb 2017 11:11:24 +0100 Subject: [PATCH 04/10] Bail if we are in a mercurial repository --- packages/react-scripts/scripts/init.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 39c97f508e5..f312826adae 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -22,11 +22,20 @@ function insideGitRepository() { } } +function insideMercurialRepository() { + try { + execSync('hg --cwd . root', {stdio: 'ignore'}); + return true; + } catch (e) { + return false; + } +} + function gitInit() { try { execSync('git --version', {stdio: 'ignore'}); - if (insideGitRepository()) { + if (insideGitRepository() || insideMercurialRepository()) { return false; } From f7259347e2750fad6707459672a7c3ce584bcebc Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Thu, 9 Feb 2017 11:12:21 +0100 Subject: [PATCH 05/10] Removed Chore from commit mesage --- packages/react-scripts/scripts/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index f312826adae..ff3ca58b21f 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -41,7 +41,7 @@ function gitInit() { execSync('git init', {stdio: 'ignore'}); execSync('git add .', {stdio: 'ignore'}); - execSync('git commit -m "chore: initial commit from create-react-app"', {stdio: 'ignore'}); + execSync('git commit -m "initial commit from create-react-app"', {stdio: 'ignore'}); return true; } catch (e) { From e61343f485e619dacba177e0ae109b2dafffec29 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Sun, 12 Feb 2017 16:42:26 +0100 Subject: [PATCH 06/10] Create repo after installing react and react-dom --- packages/react-scripts/scripts/init.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index ff3ca58b21f..5bae5047f20 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -41,7 +41,7 @@ function gitInit() { execSync('git init', {stdio: 'ignore'}); execSync('git add .', {stdio: 'ignore'}); - execSync('git commit -m "initial commit from create-react-app"', {stdio: 'ignore'}); + execSync('git commit -m "Initial commit from create-react-app"', {stdio: 'ignore'}); return true; } catch (e) { @@ -101,10 +101,6 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template } }); - if (gitInit()) { - console.log('Initializing git repository'); - } - var command; var args; @@ -145,6 +141,10 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template } } + if (gitInit()) { + console.log('Initializing git repository'); + } + // Display the most elegant way to cd. // This needs to handle an undefined originalDirectory for // backward compatibility with old global-cli's. From 05367bc07deb8b8b1a8248cc205142638d37366c Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Sun, 12 Feb 2017 16:57:26 +0100 Subject: [PATCH 07/10] Removed docs --- README.md | 1 - packages/react-scripts/template/README.md | 7 ------- 2 files changed, 8 deletions(-) diff --git a/README.md b/README.md index e658b84f73f..39baa1a5073 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,6 @@ The [User Guide](https://github.com/facebookincubator/create-react-app/blob/mast - [Running Tests](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests) - [Developing Components in Isolation](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#developing-components-in-isolation) - [Making a Progressive Web App](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#making-a-progressive-web-app) -- [Git Repository](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#git-repository) - [Deployment](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment) - [Advanced Configuration](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration) - [Troubleshooting](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#troubleshooting) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 14aa23e1ba4..e290b935625 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -61,7 +61,6 @@ You can find the most recent version of this guide [here](https://github.com/fac - [Editor Integration](#editor-integration) - [Developing Components in Isolation](#developing-components-in-isolation) - [Making a Progressive Web App](#making-a-progressive-web-app) -- [Git Repository](#git-repository) - [Deployment](#deployment) - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing) - [Building for Relative Paths](#building-for-relative-paths) @@ -1207,12 +1206,6 @@ Learn more about React Storybook: You can turn your React app into a [Progressive Web App](https://developers.google.com/web/progressive-web-apps/) by following the steps in [this repository](https://github.com/jeffposnick/create-react-pwa). -## Git Repository - -Create React App will create a new Git repository and commit the generated files to it as the initial commit. This step is skipped if the folder you are creating is already part of a larger Git repository. -The initial commit will be created with a message **chore: initial commit from create-react-app**. If you prefer another message it is easy to change before doing any other commits using the command ```git commit --amend -m "Some other message"```. -You can delete the Git repository using the command ```rm -rf .git```. - ## Deployment `npm run build` creates a `build` directory with a production build of your app. Set up your favourite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main..js` are served with the contents of the `/static/js/main..js` file. For example, Python contains a built-in HTTP server that can serve static files: From ff65875d71462b74a9e83c5af0b1e90742485c6d Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Tue, 16 Jan 2018 10:29:28 +0100 Subject: [PATCH 08/10] Commit changes when ejecting --- tasks/e2e-kitchensink.sh | 6 ++++++ tasks/e2e-simple.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index a1e1ccc9d42..b849c367944 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -174,6 +174,12 @@ rm .babelrc # Finally, let's check that everything still works after ejecting. # ****************************************************************************** +# Commiting changes +git config user.email "you@example.com" +git config user.name "Your Name" +git add . +git commit -m "Before npm run eject" + # Eject... echo yes | npm run eject diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 8ea08b55611..7c158b3704e 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -261,6 +261,12 @@ verify_module_scope # Finally, let's check that everything still works after ejecting. # ****************************************************************************** +# Commiting changes +git config user.email "you@example.com" +git config user.name "Your Name" +git add . +git commit -m "Before npm run eject" + # Eject... echo yes | npm run eject From 7f15e128677002ba9dc63e9b8dd7948ef53a61c1 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Fri, 19 Jan 2018 08:40:53 +0100 Subject: [PATCH 09/10] Update after review --- packages/react-scripts/scripts/init.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index b7d7083eea4..4795a0695dc 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -24,7 +24,7 @@ const os = require('os'); function insideGitRepository() { try { - execSync('git rev-parse --is-inside-work-tree', {stdio: 'ignore'}); + execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }); return true; } catch (e) { return false; @@ -33,7 +33,7 @@ function insideGitRepository() { function insideMercurialRepository() { try { - execSync('hg --cwd . root', {stdio: 'ignore'}); + execSync('hg --cwd . root', { stdio: 'ignore' }); return true; } catch (e) { return false; @@ -42,15 +42,17 @@ function insideMercurialRepository() { function gitInit() { try { - execSync('git --version', {stdio: 'ignore'}); + execSync('git --version', { stdio: 'ignore' }); if (insideGitRepository() || insideMercurialRepository()) { return false; } - execSync('git init', {stdio: 'ignore'}); - execSync('git add .', {stdio: 'ignore'}); - execSync('git commit -m "Initial commit from Create React App"', {stdio: 'ignore'}); + execSync('git init', { stdio: 'ignore' }); + execSync('git add .', { stdio: 'ignore' }); + execSync('git commit -m "Initial commit from Create React App"', { + stdio: 'ignore', + }); return true; } catch (e) { @@ -141,7 +143,7 @@ module.exports = function( args = ['install', '--save', verbose && '--verbose'].filter(e => e); } args.push('react', 'react-dom'); - + // Install additional template dependencies, if present const templateDependenciesPath = path.join( appPath, @@ -172,7 +174,7 @@ module.exports = function( } if (gitInit()) { - console.log('Initializing git repository'); + console.log('Initialized git repository'); } // Display the most elegant way to cd. From bbd5c9a3a3aee8bef2eb595d8356514ec4ea7d58 Mon Sep 17 00:00:00 2001 From: Maurice de Beijer Date: Fri, 19 Jan 2018 08:45:32 +0100 Subject: [PATCH 10/10] git add -A instead of git add . after code review --- packages/react-scripts/scripts/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 4795a0695dc..8837c28ea64 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -49,7 +49,7 @@ function gitInit() { } execSync('git init', { stdio: 'ignore' }); - execSync('git add .', { stdio: 'ignore' }); + execSync('git add -A', { stdio: 'ignore' }); execSync('git commit -m "Initial commit from Create React App"', { stdio: 'ignore', });