Skip to content

Commit

Permalink
Prettier files with shebang
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D7974564

fbshipit-source-id: 00db563ce24868c0fde117e981936b83cec30e48
  • Loading branch information
elicwhite authored and facebook-github-bot committed May 11, 2018
1 parent 36fcbaa commit 0e5c263
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 109 deletions.
5 changes: 3 additions & 2 deletions IntegrationTests/websocket_integration_test_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';

Expand All @@ -26,8 +27,8 @@ An incoming message of 'exit' will shut down the server.
`);

const server = new WebSocket.Server({port: 5555});
server.on('connection', (ws) => {
ws.on('message', (message) => {
server.on('connection', ws => {
ws.on('message', message => {
console.log('Received message:', message);
if (message === 'exit') {
console.log('WebSocket integration test server exit');
Expand Down
1 change: 1 addition & 0 deletions RNTester/js/http_test_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';

Expand Down
5 changes: 3 additions & 2 deletions RNTester/js/websocket_test_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';

Expand All @@ -29,8 +30,8 @@ ArrayBuffer instead of a string.

const respondWithBinary = process.argv.indexOf('--binary') !== -1;
const server = new WebSocket.Server({port: 5555});
server.on('connection', (ws) => {
ws.on('message', (message) => {
server.on('connection', ws => {
ws.on('message', message => {
console.log('Received message:', message);
console.log('Cookie:', ws.upgradeReq.headers.cookie);
if (respondWithBinary) {
Expand Down
23 changes: 15 additions & 8 deletions local-cli/wrong-react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

const isWindows = process.platform === 'win32';
Expand All @@ -14,23 +16,28 @@ if (isWindows) {
const fs = require('fs');
const path = require('path');
// On Windows, assume we are installed globally if we can't find a package.json above node_modules.
installedGlobally = !(fs.existsSync(path.join(__dirname, '../../../package.json')));
installedGlobally = !fs.existsSync(
path.join(__dirname, '../../../package.json'),
);
} else {
// On non-windows, assume we are installed globally if we are called from outside of the node_mobules/.bin/react-native executable.
var script = process.argv[1];
installedGlobally = script.indexOf('node_modules/.bin/react-native') === -1;
}


if (installedGlobally) {
const chalk = require('chalk');

console.error([
chalk.red('Looks like you installed react-native globally, maybe you meant react-native-cli?'),
chalk.red('To fix the issue, run:'),
'npm uninstall -g react-native',
'npm install -g react-native-cli'
].join('\n'));
console.error(
[
chalk.red(
'Looks like you installed react-native globally, maybe you meant react-native-cli?',
),
chalk.red('To fix the issue, run:'),
'npm uninstall -g react-native',
'npm install -g react-native-cli',
].join('\n'),
);
process.exit(1);
} else {
require('./cli').run();
Expand Down
119 changes: 64 additions & 55 deletions react-native-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -60,20 +62,15 @@ 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() {
return path.resolve(
process.cwd(),
'node_modules',
'react-native',
'package.json'
'package.json',
);
};

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)) {
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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';
}
Expand All @@ -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,
);
}
}

Expand All @@ -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();
}
43 changes: 23 additions & 20 deletions react-native-git-upgrade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

var argv = require('minimist')(process.argv.slice(2));
var cli = require('./cli');

if (argv._.length === 0 && (argv.h || argv.help)) {
console.log([
'',
' Usage: react-native-git-upgrade [version] [options]',
'',
'',
' Commands:',
'',
' [Version] upgrades React Native and app templates to the desired version',
' (latest, if not specified)',
'',
' Options:',
'',
' -h, --help output usage information',
' -v, --version output the version number',
' --verbose output debugging info',
' --npm force using the npm client even if your project uses yarn',
'',
].join('\n'));
console.log(
[
'',
' Usage: react-native-git-upgrade [version] [options]',
'',
'',
' Commands:',
'',
' [Version] upgrades React Native and app templates to the desired version',
' (latest, if not specified)',
'',
' Options:',
'',
' -h, --help output usage information',
' -v, --version output the version number',
' --verbose output debugging info',
' --npm force using the npm client even if your project uses yarn',
'',
].join('\n'),
);
process.exit(0);
}

Expand All @@ -37,5 +41,4 @@ if (argv._.length === 0 && (argv.v || argv.version)) {
process.exit(0);
}

cli.run(argv._[0], argv)
.catch(console.error);
cli.run(argv._[0], argv).catch(console.error);
Loading

0 comments on commit 0e5c263

Please sign in to comment.