From f3a807c1464cc001b833da5d4a639a18e71865d1 Mon Sep 17 00:00:00 2001 From: Johann Hubert Sonntagbauer Date: Mon, 27 Feb 2017 12:49:49 +0100 Subject: [PATCH 1/2] add project name validation --- packages/create-react-app/index.js | 17 +++++++++++++++++ packages/create-react-app/package.json | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index d5afee43b8f..494b47e605b 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -39,6 +39,7 @@ 'use strict'; var chalk = require('chalk'); +var validateProjectName = require("validate-npm-package-name"); var currentNodeVersion = process.versions.node; if (currentNodeVersion.split('.')[0] < 4) { @@ -97,6 +98,14 @@ if (typeof projectName === 'undefined') { process.exit(1); } +function printValidationResults(results) { + if (typeof results !== 'undefined') { + results.forEach(function (error) { + console.error(' ' + error); + }); + } +} + var hiddenProgram = new commander.Command() .option('--internal-testing-template ', '(internal usage only, DO NOT RELY ON THIS) ' + 'use a non-standard application template') @@ -308,6 +317,14 @@ function checkAppName(appName) { var devDependencies = ['react-scripts']; var allDependencies = dependencies.concat(devDependencies).sort(); + var validationResult = validateProjectName(appName); + if (!validationResult.validForNewPackages) { + console.error('We cannot create a project called ' + chalk.green(appName) + ' because the name does not match npm naming restrictions:'); + printValidationResults(validationResult.errors); + printValidationResults(validationResult.warnings); + process.exit(1); + } + if (allDependencies.indexOf(appName) >= 0) { console.error( chalk.red( diff --git a/packages/create-react-app/package.json b/packages/create-react-app/package.json index e1eb1c45ef2..f26823f5b41 100644 --- a/packages/create-react-app/package.json +++ b/packages/create-react-app/package.json @@ -24,6 +24,7 @@ "commander": "^2.9.0", "cross-spawn": "^4.0.0", "fs-extra": "^1.0.0", - "semver": "^5.0.3" + "semver": "^5.0.3", + "validate-npm-package-name": "^3.0.0" } } From 1a5d86d3a7a8da5d3cce27c175051c04a1819414 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 28 Feb 2017 13:55:48 +0000 Subject: [PATCH 2/2] Tweak console output --- packages/create-react-app/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index 494b47e605b..02d30975907 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -101,7 +101,7 @@ if (typeof projectName === 'undefined') { function printValidationResults(results) { if (typeof results !== 'undefined') { results.forEach(function (error) { - console.error(' ' + error); + console.error(chalk.red(' * ' + error)); }); } } @@ -312,19 +312,18 @@ function checkNodeVersion(packageName) { } function checkAppName(appName) { - // TODO: there should be a single place that holds the dependencies - var dependencies = ['react', 'react-dom']; - var devDependencies = ['react-scripts']; - var allDependencies = dependencies.concat(devDependencies).sort(); - var validationResult = validateProjectName(appName); if (!validationResult.validForNewPackages) { - console.error('We cannot create a project called ' + chalk.green(appName) + ' because the name does not match npm naming restrictions:'); + console.error('Could not create a project called ' + chalk.red('"' + appName + '"') + ' because of npm naming restrictions:'); printValidationResults(validationResult.errors); printValidationResults(validationResult.warnings); process.exit(1); } - + + // TODO: there should be a single place that holds the dependencies + var dependencies = ['react', 'react-dom']; + var devDependencies = ['react-scripts']; + var allDependencies = dependencies.concat(devDependencies).sort(); if (allDependencies.indexOf(appName) >= 0) { console.error( chalk.red(