From 39a5b4de6e97535ec8dbe0623e7d0f42345ea4f0 Mon Sep 17 00:00:00 2001
From: Jirat Ki <saakyz@gmail.com>
Date: Sat, 10 Dec 2016 03:42:52 +0700
Subject: [PATCH] Skip gh-page setup instruction if scripts.deploy has been
 added (#1222)

---
 packages/react-scripts/scripts/build.js | 36 ++++++++++++++-----------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js
index a53b2f01a..523b39f34 100644
--- a/packages/react-scripts/scripts/build.js
+++ b/packages/react-scripts/scripts/build.js
@@ -158,7 +158,8 @@ function build(previousSizeMap) {
     console.log();
 
     var openCommand = process.platform === 'win32' ? 'start' : 'open';
-    var homepagePath = require(paths.appPackageJson).homepage;
+    var appPackage  = require(paths.appPackageJson);
+    var homepagePath = appPackage.homepage;
     var publicPath = config.output.publicPath;
     if (homepagePath && homepagePath.indexOf('.github.io/') !== -1) {
       // "homepage": "http://user.github.io/project"
@@ -167,23 +168,26 @@ function build(previousSizeMap) {
       console.log();
       console.log('The ' + chalk.cyan('build') + ' folder is ready to be deployed.');
       console.log('To publish it at ' + chalk.green(homepagePath) + ', run:');
-      console.log();
-      if (useYarn) {
-        console.log('  ' + chalk.cyan('yarn') +  ' add --dev gh-pages');
-      } else {
-        console.log('  ' + chalk.cyan('npm') +  ' install --save-dev gh-pages');
+      // If script deploy has been added to package.json, skip the instructions
+      if (typeof appPackage.scripts.deploy === 'undefined') {
+        console.log();
+        if (useYarn) {
+          console.log('  ' + chalk.cyan('yarn') +  ' add --dev gh-pages');
+        } else {
+          console.log('  ' + chalk.cyan('npm') +  ' install --save-dev gh-pages');
+        }
+        console.log();
+        console.log('Add the following script in your ' + chalk.cyan('package.json') + '.');
+        console.log();
+        console.log('    ' + chalk.dim('// ...'));
+        console.log('    ' + chalk.yellow('"scripts"') + ': {');
+        console.log('      ' + chalk.dim('// ...'));
+        console.log('      ' + chalk.yellow('"deploy"') + ': ' + chalk.yellow('"npm run build&&gh-pages -d build"'));
+        console.log('    }');
+        console.log();
+        console.log('Then run:');
       }
       console.log();
-      console.log('Add the following script in your ' + chalk.cyan('package.json') + '.');
-      console.log();
-      console.log('    ' + chalk.dim('// ...'));
-      console.log('    ' + chalk.yellow('"scripts"') + ': {');
-      console.log('      ' + chalk.dim('// ...'));
-      console.log('      ' + chalk.yellow('"deploy"') + ': ' + chalk.yellow('"npm run build&&gh-pages -d build"'));
-      console.log('    }');
-      console.log();
-      console.log('Then run:');
-      console.log();
       console.log('  ' + chalk.cyan(useYarn ? 'yarn' : 'npm') +  ' run deploy');
       console.log();
     } else if (publicPath !== '/') {
-- 
GitLab