Skip to content

Commit a8dedf3

Browse files
authored
Tweak console messages (#1236)
* Tweak minimal Node error message * Tweak console messages * It doesn't need to be from npm * Try to fix e2e test
1 parent 5c551f8 commit a8dedf3

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

packages/create-react-app/index.js

+39-19
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ var chalk = require('chalk');
4242

4343
var currentNodeVersion = process.versions.node
4444
if (currentNodeVersion.split('.')[0] < 4) {
45-
console.error(chalk.red('You are currently running Node v' + currentNodeVersion +
46-
' but create-react-app requires >=4. Please use a supported version of Node.\n'));
45+
console.error(
46+
chalk.red(
47+
'You are running Node ' + currentNodeVersion + '.\n' +
48+
'Create React App requires Node 4 or higher. \n' +
49+
'Please update your version of Node.'
50+
)
51+
);
4752
process.exit(1);
4853
}
4954

@@ -58,23 +63,36 @@ var projectName;
5863

5964
var program = require('commander')
6065
.version(require('./package.json').version)
61-
.arguments('<name>')
66+
.arguments('<project-directory>')
67+
.usage(chalk.green('<project-directory>') + ' [options]')
6268
.action(function (name) {
6369
projectName = name;
6470
})
65-
.option('-v, --verbose', 'print logs while init')
66-
.option('-s, --scripts-version <alternative package>', 'select a react script variant')
71+
.option('--verbose', 'print additional logs')
72+
.option('--scripts-version <alternative-package>', 'use a non-standard version of react-scripts')
6773
.on('--help', function () {
68-
console.log('Example of valid script version values:')
69-
console.log(' - a specific npm version: "0.22.0-rc1"')
70-
console.log(' - a .tgz archive from any npm repo: "https://registry.npmjs.org/react-scripts/-/react-scripts-0.20.0.tgz"')
71-
console.log(' - a package prepared with `tasks/clean_pack.sh`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz"')
74+
console.log(' Only ' + chalk.green('<project-directory>') + ' is required.');
75+
console.log();
76+
console.log(' A custom ' + chalk.cyan('--scripts-version') + ' can be one of:');
77+
console.log(' - a specific npm version: ' + chalk.green('0.8.2'));
78+
console.log(' - a custom fork published on npm: ' + chalk.green('my-react-scripts'));
79+
console.log(' - a .tgz archive: ' + chalk.green('https://mysite.com/my-react-scripts-0.8.2.tgz'));
80+
console.log(' It is not needed unless you specifically want to use a fork.');
81+
console.log();
82+
console.log(' If you have any problems, do not hesitate to file an issue:');
83+
console.log(' ' + chalk.cyan('https://github.com/facebookincubator/create-react-app/issues/new'));
84+
console.log();
7285
})
7386
.parse(process.argv)
7487

7588
if (typeof projectName === 'undefined') {
76-
console.error('Error: no name given!');
77-
console.log('Usage: ' + program.name() + ' ' + program.usage());
89+
console.error('Please specify the project directory:');
90+
console.log(' ' + chalk.cyan(program.name()) + chalk.green(' <project-directory>'));
91+
console.log();
92+
console.log('For example:');
93+
console.log(' ' + chalk.cyan(program.name()) + chalk.green(' my-react-app'));
94+
console.log();
95+
console.log('Run ' + chalk.cyan(program.name() + ' --help') + ' to see all options.');
7896
process.exit(1);
7997
}
8098

@@ -89,12 +107,13 @@ function createApp(name, verbose, version) {
89107
if (!pathExists.sync(name)) {
90108
fs.mkdirSync(root);
91109
} else if (!isSafeToCreateProjectIn(root)) {
92-
console.log('The directory `' + name + '` contains file(s) that could conflict. Aborting.');
110+
console.log('The directory ' + chalk.green(name) + ' contains files that could conflict.');
111+
console.log('Try using a new directory name.');
93112
process.exit(1);
94113
}
95114

96115
console.log(
97-
'Creating a new React app in ' + root + '.'
116+
'Creating a new React app in ' + chalk.green(root) + '.'
98117
);
99118
console.log();
100119

@@ -111,7 +130,7 @@ function createApp(name, verbose, version) {
111130
process.chdir(root);
112131

113132
console.log('Installing packages. This might take a couple minutes.');
114-
console.log('Installing react-scripts...');
133+
console.log('Installing ' + chalk.cyan('react-scripts') + '...');
115134
console.log();
116135

117136
run(root, appName, version, verbose, originalDirectory);
@@ -153,7 +172,7 @@ function run(root, appName, version, verbose, originalDirectory) {
153172

154173
install(packageToInstall, verbose, function(code, command, args) {
155174
if (code !== 0) {
156-
console.error('`' + command + ' ' + args.join(' ') + '` failed');
175+
console.error(chalk.cyan(command + ' ' + args.join(' ')) + ' failed');
157176
process.exit(1);
158177
}
159178

@@ -187,7 +206,7 @@ function getInstallPackage(version) {
187206
function getPackageName(installPackage) {
188207
if (installPackage.indexOf('.tgz') > -1) {
189208
// The package name could be with or without semver version, e.g. react-scripts-0.2.0-alpha.1.tgz
190-
// However, this function returns package name only wihout semver version.
209+
// However, this function returns package name only without semver version.
191210
return installPackage.match(/^.+\/(.+?)(?:-\d+.+)?\.tgz$/)[1];
192211
} else if (installPackage.indexOf('@') > 0) {
193212
// Do not match @scope/ when stripping off @version or @tag
@@ -211,8 +230,9 @@ function checkNodeVersion(packageName) {
211230
if (!semver.satisfies(process.version, packageJson.engines.node)) {
212231
console.error(
213232
chalk.red(
214-
'You are currently running Node %s but create-react-app requires %s.' +
215-
' Please use a supported version of Node.\n'
233+
'You are running Node %s.\n' +
234+
'Create React App requires Node %s or higher. \n' +
235+
'Please update your version of Node.'
216236
),
217237
process.version,
218238
packageJson.engines.node
@@ -230,7 +250,7 @@ function checkAppName(appName) {
230250
if (allDependencies.indexOf(appName) >= 0) {
231251
console.error(
232252
chalk.red(
233-
'We cannot create a project called `' + appName + '` because a dependency with the same name exists.\n' +
253+
'We cannot create a project called ' + chalk.green(appName) + ' because a dependency with the same name exists.\n' +
234254
'Due to the way npm works, the following names are not allowed:\n\n'
235255
) +
236256
chalk.cyan(

tasks/e2e.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if [ `node --version | sed -e 's/^v//' -e 's/\..\+//g'` -lt 4 ]
6565
then
6666
cd $temp_app_path
6767
err_output=`node "$root_path"/packages/create-react-app/index.js test-node-version 2>&1 > /dev/null || echo ''`
68-
[[ $err_output =~ You\ are\ currently\ running\ Node\ v.+\ but\ create-react-app\ requires\ \>=4\. ]] && exit 0 || exit 1
68+
[[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1
6969
fi
7070

7171
if [ "$USE_YARN" = "yes" ]

0 commit comments

Comments
 (0)