Commit c51a6119 authored by Johann Hubert Sonntagbauer's avatar Johann Hubert Sonntagbauer Committed by Dan Abramov
Browse files

add project name validation (#1662)

* add project name validation

* Tweak console output
parent 715968ec
4 merge requests!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!5717Automatically extract project file structure from build bundle file,!1933Add note about installing watchman
Showing with 19 additions and 2 deletions
+19 -2
......@@ -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(chalk.red(' * ' + error));
});
}
}
var hiddenProgram = new commander.Command()
.option('--internal-testing-template <path-to-template>', '(internal usage only, DO NOT RELY ON THIS) ' +
'use a non-standard application template')
......@@ -304,11 +313,18 @@ function checkNodeVersion(packageName) {
}
function checkAppName(appName) {
var validationResult = validateProjectName(appName);
if (!validationResult.validForNewPackages) {
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(
......
......@@ -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"
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment