Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Meta
create-react-app
Commits
c51a6119
Commit
c51a6119
authored
8 years ago
by
Johann Hubert Sonntagbauer
Committed by
Dan Abramov
8 years ago
Browse files
Options
Download
Email Patches
Plain Diff
add project name validation (#1662)
* add project name validation * Tweak console output
parent
715968ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/create-react-app/index.js
+17
-1
packages/create-react-app/index.js
packages/create-react-app/package.json
+2
-1
packages/create-react-app/package.json
with
19 additions
and
2 deletions
+19
-2
packages/create-react-app/index.js
+
17
-
1
View file @
c51a6119
...
...
@@ -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
(
...
...
This diff is collapsed.
Click to expand it.
packages/create-react-app/package.json
+
2
-
1
View file @
c51a6119
...
...
@@ -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"
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets