From e0558bc4c6276e00a3f6ca8e2203af2dba12611c Mon Sep 17 00:00:00 2001
From: Dan Abramov <dan.abramov@gmail.com>
Date: Thu, 21 Jul 2016 15:02:27 +0100
Subject: [PATCH] Use a single script (#57)

It is easier to add more scripts later this way.
---
 bin/build-react-app.js |  2 --
 bin/eject-react-app.js |  2 --
 bin/react-scripts.js   | 21 +++++++++++++++++++++
 bin/start-react-app.js |  2 --
 package.json           |  4 +---
 scripts/eject.js       |  4 +---
 scripts/init.js        |  5 ++---
 7 files changed, 25 insertions(+), 15 deletions(-)
 delete mode 100644 bin/build-react-app.js
 delete mode 100644 bin/eject-react-app.js
 create mode 100644 bin/react-scripts.js
 delete mode 100644 bin/start-react-app.js

diff --git a/bin/build-react-app.js b/bin/build-react-app.js
deleted file mode 100644
index 4e16fa983..000000000
--- a/bin/build-react-app.js
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env node
-require('../scripts/build');
diff --git a/bin/eject-react-app.js b/bin/eject-react-app.js
deleted file mode 100644
index 3a4141bb6..000000000
--- a/bin/eject-react-app.js
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env node
-require('../scripts/eject');
diff --git a/bin/react-scripts.js b/bin/react-scripts.js
new file mode 100644
index 000000000..3f924225a
--- /dev/null
+++ b/bin/react-scripts.js
@@ -0,0 +1,21 @@
+#!/usr/bin/env node
+var path = require('path');
+var spawn = require('cross-spawn');
+var script = process.argv[2];
+var args = process.argv.slice(3);
+
+switch (script) {
+case 'build':
+case 'start':
+case 'eject':
+  spawn(
+    'node',
+    [path.resolve(__dirname, '..', 'scripts', script)].concat(args),
+    {stdio: 'inherit'}
+  );
+  break;
+default:
+  console.log('Unknown script "' + script + '".');
+  console.log('Perhaps you need to update react-scripts?');
+  break;
+}
diff --git a/bin/start-react-app.js b/bin/start-react-app.js
deleted file mode 100644
index a287171b9..000000000
--- a/bin/start-react-app.js
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env node
-require('../scripts/start');
diff --git a/package.json b/package.json
index acf92fb96..33ba2bd5a 100644
--- a/package.json
+++ b/package.json
@@ -21,9 +21,7 @@
     "template"
   ],
   "bin": {
-    "start-react-app": "./bin/start-react-app.js",
-    "build-react-app": "./bin/build-react-app.js",
-    "eject-react-app": "./bin/eject-react-app.js"
+    "react-scripts": "./bin/react-scripts.js"
   },
   "dependencies": {
     "autoprefixer": "6.3.7",
diff --git a/scripts/eject.js b/scripts/eject.js
index bf4c42ff0..4237d699d 100644
--- a/scripts/eject.js
+++ b/scripts/eject.js
@@ -36,9 +36,9 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
 
   console.log('Ejecting...');
   console.log();
+
   var selfPath = path.join(__dirname, '..');
   var hostPath = path.join(selfPath, '..', '..');
-
   var files = [
     path.join('config', 'babel.dev.js'),
     path.join('config', 'babel.prod.js'),
@@ -73,7 +73,6 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
    content = content.replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '').trim() + '\n';
    fs.writeFileSync(path.join(hostPath, file), content);
   });
-
   console.log();
 
   var selfPackage = require(path.join(selfPath, 'package.json'));
@@ -109,5 +108,4 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
   console.log('Please consider sharing why you ejected in this survey:');
   console.log('  http://goo.gl/forms/Bi6CZjk1EqsdelXk1');
   console.log();
-
 });
diff --git a/scripts/init.js b/scripts/init.js
index 8c8366dc8..1b8c981cb 100644
--- a/scripts/init.js
+++ b/scripts/init.js
@@ -26,8 +26,7 @@ module.exports = function(hostPath, appName, verbose) {
   // Setup the script rules
   hostPackage.scripts = {};
   ['start', 'build', 'eject'].forEach(function(command) {
-    hostPackage.scripts[command] =
-      command + '-react-app';
+    hostPackage.scripts[command] = 'react-scripts ' + command;
   });
 
   fs.writeFileSync(
@@ -53,7 +52,7 @@ module.exports = function(hostPath, appName, verbose) {
     copySync(
       path.join(selfPath, 'template', filename),
       path.join(hostPath, filename)
-    );    
+    );
   });
 
   // Run another npm install for react and react-dom
-- 
GitLab