|
38 | 38 |
|
39 | 39 | 'use strict';
|
40 | 40 |
|
| 41 | +var chalk = require('chalk'); |
| 42 | + |
| 43 | +var currentNodeVersion = process.versions.node |
| 44 | +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')); |
| 47 | + process.exit(1); |
| 48 | +} |
| 49 | + |
41 | 50 | var fs = require('fs');
|
42 | 51 | var path = require('path');
|
43 | 52 | var execSync = require('child_process').execSync;
|
44 | 53 | var spawn = require('cross-spawn');
|
45 |
| -var chalk = require('chalk'); |
46 | 54 | var semver = require('semver');
|
47 |
| -var argv = require('minimist')(process.argv.slice(2)); |
48 | 55 | var pathExists = require('path-exists');
|
49 | 56 |
|
50 |
| -/** |
51 |
| - * Arguments: |
52 |
| - * --version - to print current version |
53 |
| - * --verbose - to print logs while init |
54 |
| - * --scripts-version <alternative package> |
55 |
| - * Example of valid values: |
56 |
| - * - a specific npm version: "0.22.0-rc1" |
57 |
| - * - a .tgz archive from any npm repo: "https://registry.npmjs.org/react-scripts/-/react-scripts-0.20.0.tgz" |
58 |
| - * - a package prepared with `tasks/clean_pack.sh`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz" |
59 |
| - */ |
60 |
| -var commands = argv._; |
61 |
| -if (commands.length === 0) { |
62 |
| - if (argv.version) { |
63 |
| - console.log('create-react-app version: ' + require('./package.json').version); |
64 |
| - process.exit(); |
65 |
| - } |
66 |
| - console.error( |
67 |
| - 'Usage: create-react-app <project-directory> [--verbose]' |
68 |
| - ); |
| 57 | +var projectName; |
| 58 | + |
| 59 | +var program = require('commander') |
| 60 | + .version(require('./package.json').version) |
| 61 | + .arguments('<name>') |
| 62 | + .action(function (name) { |
| 63 | + projectName = name; |
| 64 | + }) |
| 65 | + .option('-v, --verbose', 'print logs while init') |
| 66 | + .option('-s, --scripts-version <alternative package>', 'select a react script variant') |
| 67 | + .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"') |
| 72 | + }) |
| 73 | + .parse(process.argv) |
| 74 | + |
| 75 | +if (typeof projectName === 'undefined') { |
| 76 | + console.error('Error: no name given!'); |
| 77 | + console.log('Usage: ' + program.name() + ' ' + program.usage()); |
69 | 78 | process.exit(1);
|
70 | 79 | }
|
71 | 80 |
|
72 |
| -createApp(commands[0], argv.verbose, argv['scripts-version']); |
| 81 | +createApp(projectName, program.verbose, program.scriptsVersion); |
73 | 82 |
|
74 | 83 | function createApp(name, verbose, version) {
|
75 | 84 | var root = path.resolve(name);
|
|
0 commit comments