|
39 | 39 | 'use strict';
|
40 | 40 |
|
41 | 41 | var chalk = require('chalk');
|
| 42 | +var validateProjectName = require("validate-npm-package-name"); |
42 | 43 |
|
43 | 44 | var currentNodeVersion = process.versions.node;
|
44 | 45 | if (currentNodeVersion.split('.')[0] < 4) {
|
@@ -97,6 +98,14 @@ if (typeof projectName === 'undefined') {
|
97 | 98 | process.exit(1);
|
98 | 99 | }
|
99 | 100 |
|
| 101 | +function printValidationResults(results) { |
| 102 | + if (typeof results !== 'undefined') { |
| 103 | + results.forEach(function (error) { |
| 104 | + console.error(chalk.red(' * ' + error)); |
| 105 | + }); |
| 106 | + } |
| 107 | +} |
| 108 | + |
100 | 109 | var hiddenProgram = new commander.Command()
|
101 | 110 | .option('--internal-testing-template <path-to-template>', '(internal usage only, DO NOT RELY ON THIS) ' +
|
102 | 111 | 'use a non-standard application template')
|
@@ -304,11 +313,18 @@ function checkNodeVersion(packageName) {
|
304 | 313 | }
|
305 | 314 |
|
306 | 315 | function checkAppName(appName) {
|
| 316 | + var validationResult = validateProjectName(appName); |
| 317 | + if (!validationResult.validForNewPackages) { |
| 318 | + console.error('Could not create a project called ' + chalk.red('"' + appName + '"') + ' because of npm naming restrictions:'); |
| 319 | + printValidationResults(validationResult.errors); |
| 320 | + printValidationResults(validationResult.warnings); |
| 321 | + process.exit(1); |
| 322 | + } |
| 323 | + |
307 | 324 | // TODO: there should be a single place that holds the dependencies
|
308 | 325 | var dependencies = ['react', 'react-dom'];
|
309 | 326 | var devDependencies = ['react-scripts'];
|
310 | 327 | var allDependencies = dependencies.concat(devDependencies).sort();
|
311 |
| - |
312 | 328 | if (allDependencies.indexOf(appName) >= 0) {
|
313 | 329 | console.error(
|
314 | 330 | chalk.red(
|
|
0 commit comments