mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-19 19:05:45 +08:00
Prettier files with shebang
Reviewed By: yungsters Differential Revision: D7974564 fbshipit-source-id: 00db563ce24868c0fde117e981936b83cec30e48
This commit is contained in:
committed by
Facebook Github Bot
parent
36fcbaa56d
commit
0e5c2633ee
119
react-native-cli/index.js
vendored
119
react-native-cli/index.js
vendored
@@ -5,6 +5,8 @@
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -60,12 +62,7 @@ var semver = require('semver');
|
||||
var options = require('minimist')(process.argv.slice(2));
|
||||
|
||||
var CLI_MODULE_PATH = function() {
|
||||
return path.resolve(
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'react-native',
|
||||
'cli.js'
|
||||
);
|
||||
return path.resolve(process.cwd(), 'node_modules', 'react-native', 'cli.js');
|
||||
};
|
||||
|
||||
var REACT_NATIVE_PACKAGE_JSON_PATH = function() {
|
||||
@@ -73,7 +70,7 @@ var REACT_NATIVE_PACKAGE_JSON_PATH = function() {
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'react-native',
|
||||
'package.json'
|
||||
'package.json',
|
||||
);
|
||||
};
|
||||
|
||||
@@ -90,7 +87,9 @@ function getYarnVersionIfAvailable() {
|
||||
if (process.platform.startsWith('win')) {
|
||||
yarnVersion = (execSync('yarn --version 2> NUL').toString() || '').trim();
|
||||
} else {
|
||||
yarnVersion = (execSync('yarn --version 2>/dev/null').toString() || '').trim();
|
||||
yarnVersion = (
|
||||
execSync('yarn --version 2>/dev/null').toString() || ''
|
||||
).trim();
|
||||
}
|
||||
} catch (error) {
|
||||
return null;
|
||||
@@ -119,51 +118,51 @@ if (cli) {
|
||||
cli.run();
|
||||
} else {
|
||||
if (options._.length === 0 && (options.h || options.help)) {
|
||||
console.log([
|
||||
'',
|
||||
' Usage: react-native [command] [options]',
|
||||
'',
|
||||
'',
|
||||
' Commands:',
|
||||
'',
|
||||
' init <ProjectName> [options] generates a new project and installs its dependencies',
|
||||
'',
|
||||
' Options:',
|
||||
'',
|
||||
' -h, --help output usage information',
|
||||
' -v, --version use a specific version of React Native',
|
||||
' --template use an app template. Use --template to see available templates.',
|
||||
'',
|
||||
].join('\n'));
|
||||
console.log(
|
||||
[
|
||||
'',
|
||||
' Usage: react-native [command] [options]',
|
||||
'',
|
||||
'',
|
||||
' Commands:',
|
||||
'',
|
||||
' init <ProjectName> [options] generates a new project and installs its dependencies',
|
||||
'',
|
||||
' Options:',
|
||||
'',
|
||||
' -h, --help output usage information',
|
||||
' -v, --version use a specific version of React Native',
|
||||
' --template use an app template. Use --template to see available templates.',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (commands.length === 0) {
|
||||
console.error(
|
||||
'You did not pass any commands, run `react-native --help` to see a list of all available commands.'
|
||||
'You did not pass any commands, run `react-native --help` to see a list of all available commands.',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
switch (commands[0]) {
|
||||
case 'init':
|
||||
if (!commands[1]) {
|
||||
case 'init':
|
||||
if (!commands[1]) {
|
||||
console.error('Usage: react-native init <ProjectName> [--verbose]');
|
||||
process.exit(1);
|
||||
} else {
|
||||
init(commands[1], options);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.error(
|
||||
'Usage: react-native init <ProjectName> [--verbose]'
|
||||
'Command `%s` unrecognized. ' +
|
||||
'Make sure that you have run `npm install` and that you are inside a react-native project.',
|
||||
commands[0],
|
||||
);
|
||||
process.exit(1);
|
||||
} else {
|
||||
init(commands[1], options);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.error(
|
||||
'Command `%s` unrecognized. ' +
|
||||
'Make sure that you have run `npm install` and that you are inside a react-native project.',
|
||||
commands[0]
|
||||
);
|
||||
process.exit(1);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +171,7 @@ function validateProjectName(name) {
|
||||
console.error(
|
||||
'"%s" is not a valid name for a project. Please use a valid identifier ' +
|
||||
'name (alphanumeric).',
|
||||
name
|
||||
name,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -181,7 +180,7 @@ function validateProjectName(name) {
|
||||
console.error(
|
||||
'"%s" is not a valid name for a project. Please do not use the ' +
|
||||
'reserved word "React".',
|
||||
name
|
||||
name,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -212,10 +211,10 @@ function createAfterConfirmation(name, options) {
|
||||
message: 'Directory ' + name + ' already exists. Continue?',
|
||||
validator: /y[es]*|n[o]?/,
|
||||
warning: 'Must respond yes or no',
|
||||
default: 'no'
|
||||
default: 'no',
|
||||
};
|
||||
|
||||
prompt.get(property, function (err, result) {
|
||||
prompt.get(property, function(err, result) {
|
||||
if (result.yesno[0] === 'y') {
|
||||
createProject(name, options);
|
||||
} else {
|
||||
@@ -231,7 +230,7 @@ function createProject(name, options) {
|
||||
|
||||
console.log(
|
||||
'This will walk you through creating a new React Native project in',
|
||||
root
|
||||
root,
|
||||
);
|
||||
|
||||
if (!fs.existsSync(root)) {
|
||||
@@ -246,9 +245,12 @@ function createProject(name, options) {
|
||||
start: 'node node_modules/react-native/local-cli/cli.js start',
|
||||
ios: 'react-native run-ios',
|
||||
android: 'react-native run-android',
|
||||
}
|
||||
},
|
||||
};
|
||||
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(packageJson));
|
||||
fs.writeFileSync(
|
||||
path.join(root, 'package.json'),
|
||||
JSON.stringify(packageJson),
|
||||
);
|
||||
process.chdir(root);
|
||||
|
||||
run(root, projectName, options);
|
||||
@@ -269,7 +271,7 @@ function getInstallPackage(rnPackage) {
|
||||
function run(root, projectName, options) {
|
||||
var rnPackage = options.version; // e.g. '0.38' or '/path/to/archive.tgz'
|
||||
var forceNpmClient = options.npm;
|
||||
var yarnVersion = (!forceNpmClient) && getYarnVersionIfAvailable();
|
||||
var yarnVersion = !forceNpmClient && getYarnVersionIfAvailable();
|
||||
var installCommand;
|
||||
if (options.installCommand) {
|
||||
// In CI environments it can be useful to provide a custom command,
|
||||
@@ -286,9 +288,12 @@ function run(root, projectName, options) {
|
||||
} else {
|
||||
console.log('Installing ' + getInstallPackage(rnPackage) + '...');
|
||||
if (!forceNpmClient) {
|
||||
console.log('Consider installing yarn to make this faster: https://yarnpkg.com');
|
||||
console.log(
|
||||
'Consider installing yarn to make this faster: https://yarnpkg.com',
|
||||
);
|
||||
}
|
||||
installCommand = 'npm install --save --save-exact ' + getInstallPackage(rnPackage);
|
||||
installCommand =
|
||||
'npm install --save --save-exact ' + getInstallPackage(rnPackage);
|
||||
if (options.verbose) {
|
||||
installCommand += ' --verbose';
|
||||
}
|
||||
@@ -312,13 +317,15 @@ function checkNodeVersion() {
|
||||
return;
|
||||
}
|
||||
if (!semver.satisfies(process.version, packageJson.engines.node)) {
|
||||
console.error(chalk.red(
|
||||
console.error(
|
||||
chalk.red(
|
||||
'You are currently running Node %s but React Native requires %s. ' +
|
||||
'Please use a supported version of Node.\n' +
|
||||
'See https://facebook.github.io/react-native/docs/getting-started.html'
|
||||
'Please use a supported version of Node.\n' +
|
||||
'See https://facebook.github.io/react-native/docs/getting-started.html',
|
||||
),
|
||||
process.version,
|
||||
packageJson.engines.node);
|
||||
packageJson.engines.node,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +334,9 @@ function printVersionsAndExit(reactNativePackageJsonPath) {
|
||||
try {
|
||||
console.log('react-native: ' + require(reactNativePackageJsonPath).version);
|
||||
} catch (e) {
|
||||
console.log('react-native: n/a - not inside a React Native project directory');
|
||||
console.log(
|
||||
'react-native: n/a - not inside a React Native project directory',
|
||||
);
|
||||
}
|
||||
process.exit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user