Prettier files with shebang

Reviewed By: yungsters

Differential Revision: D7974564

fbshipit-source-id: 00db563ce24868c0fde117e981936b83cec30e48
This commit is contained in:
Eli White 2018-05-11 13:32:39 -07:00 committed by Facebook Github Bot
parent 36fcbaa56d
commit 0e5c2633ee
7 changed files with 155 additions and 109 deletions

View File

@ -7,6 +7,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @flow * @flow
* @format
*/ */
'use strict'; 'use strict';
@ -26,8 +27,8 @@ An incoming message of 'exit' will shut down the server.
`); `);
const server = new WebSocket.Server({port: 5555}); const server = new WebSocket.Server({port: 5555});
server.on('connection', (ws) => { server.on('connection', ws => {
ws.on('message', (message) => { ws.on('message', message => {
console.log('Received message:', message); console.log('Received message:', message);
if (message === 'exit') { if (message === 'exit') {
console.log('WebSocket integration test server exit'); console.log('WebSocket integration test server exit');

View File

@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @flow * @flow
* @format
*/ */
'use strict'; 'use strict';

View File

@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @flow * @flow
* @format
*/ */
'use strict'; 'use strict';
@ -29,8 +30,8 @@ ArrayBuffer instead of a string.
const respondWithBinary = process.argv.indexOf('--binary') !== -1; const respondWithBinary = process.argv.indexOf('--binary') !== -1;
const server = new WebSocket.Server({port: 5555}); const server = new WebSocket.Server({port: 5555});
server.on('connection', (ws) => { server.on('connection', ws => {
ws.on('message', (message) => { ws.on('message', message => {
console.log('Received message:', message); console.log('Received message:', message);
console.log('Cookie:', ws.upgradeReq.headers.cookie); console.log('Cookie:', ws.upgradeReq.headers.cookie);
if (respondWithBinary) { if (respondWithBinary) {

View File

@ -5,6 +5,8 @@
* *
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
* @format
*/ */
const isWindows = process.platform === 'win32'; const isWindows = process.platform === 'win32';
@ -14,23 +16,28 @@ if (isWindows) {
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
// On Windows, assume we are installed globally if we can't find a package.json above node_modules. // 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 { } else {
// On non-windows, assume we are installed globally if we are called from outside of the node_mobules/.bin/react-native executable. // 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]; var script = process.argv[1];
installedGlobally = script.indexOf('node_modules/.bin/react-native') === -1; installedGlobally = script.indexOf('node_modules/.bin/react-native') === -1;
} }
if (installedGlobally) { if (installedGlobally) {
const chalk = require('chalk'); const chalk = require('chalk');
console.error([ console.error(
chalk.red('Looks like you installed react-native globally, maybe you meant react-native-cli?'), [
chalk.red(
'Looks like you installed react-native globally, maybe you meant react-native-cli?',
),
chalk.red('To fix the issue, run:'), chalk.red('To fix the issue, run:'),
'npm uninstall -g react-native', 'npm uninstall -g react-native',
'npm install -g react-native-cli' 'npm install -g react-native-cli',
].join('\n')); ].join('\n'),
);
process.exit(1); process.exit(1);
} else { } else {
require('./cli').run(); require('./cli').run();

View File

@ -5,6 +5,8 @@
* *
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * 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 options = require('minimist')(process.argv.slice(2));
var CLI_MODULE_PATH = function() { var CLI_MODULE_PATH = function() {
return path.resolve( return path.resolve(process.cwd(), 'node_modules', 'react-native', 'cli.js');
process.cwd(),
'node_modules',
'react-native',
'cli.js'
);
}; };
var REACT_NATIVE_PACKAGE_JSON_PATH = function() { var REACT_NATIVE_PACKAGE_JSON_PATH = function() {
@ -73,7 +70,7 @@ var REACT_NATIVE_PACKAGE_JSON_PATH = function() {
process.cwd(), process.cwd(),
'node_modules', 'node_modules',
'react-native', 'react-native',
'package.json' 'package.json',
); );
}; };
@ -90,7 +87,9 @@ function getYarnVersionIfAvailable() {
if (process.platform.startsWith('win')) { if (process.platform.startsWith('win')) {
yarnVersion = (execSync('yarn --version 2> NUL').toString() || '').trim(); yarnVersion = (execSync('yarn --version 2> NUL').toString() || '').trim();
} else { } else {
yarnVersion = (execSync('yarn --version 2>/dev/null').toString() || '').trim(); yarnVersion = (
execSync('yarn --version 2>/dev/null').toString() || ''
).trim();
} }
} catch (error) { } catch (error) {
return null; return null;
@ -119,7 +118,8 @@ if (cli) {
cli.run(); cli.run();
} else { } else {
if (options._.length === 0 && (options.h || options.help)) { if (options._.length === 0 && (options.h || options.help)) {
console.log([ console.log(
[
'', '',
' Usage: react-native [command] [options]', ' Usage: react-native [command] [options]',
'', '',
@ -134,13 +134,14 @@ if (cli) {
' -v, --version use a specific version of React Native', ' -v, --version use a specific version of React Native',
' --template use an app template. Use --template to see available templates.', ' --template use an app template. Use --template to see available templates.',
'', '',
].join('\n')); ].join('\n'),
);
process.exit(0); process.exit(0);
} }
if (commands.length === 0) { if (commands.length === 0) {
console.error( 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); process.exit(1);
} }
@ -148,9 +149,7 @@ if (cli) {
switch (commands[0]) { switch (commands[0]) {
case 'init': case 'init':
if (!commands[1]) { if (!commands[1]) {
console.error( console.error('Usage: react-native init <ProjectName> [--verbose]');
'Usage: react-native init <ProjectName> [--verbose]'
);
process.exit(1); process.exit(1);
} else { } else {
init(commands[1], options); init(commands[1], options);
@ -160,7 +159,7 @@ if (cli) {
console.error( console.error(
'Command `%s` unrecognized. ' + 'Command `%s` unrecognized. ' +
'Make sure that you have run `npm install` and that you are inside a react-native project.', 'Make sure that you have run `npm install` and that you are inside a react-native project.',
commands[0] commands[0],
); );
process.exit(1); process.exit(1);
break; break;
@ -172,7 +171,7 @@ function validateProjectName(name) {
console.error( console.error(
'"%s" is not a valid name for a project. Please use a valid identifier ' + '"%s" is not a valid name for a project. Please use a valid identifier ' +
'name (alphanumeric).', 'name (alphanumeric).',
name name,
); );
process.exit(1); process.exit(1);
} }
@ -181,7 +180,7 @@ function validateProjectName(name) {
console.error( console.error(
'"%s" is not a valid name for a project. Please do not use the ' + '"%s" is not a valid name for a project. Please do not use the ' +
'reserved word "React".', 'reserved word "React".',
name name,
); );
process.exit(1); process.exit(1);
} }
@ -212,10 +211,10 @@ function createAfterConfirmation(name, options) {
message: 'Directory ' + name + ' already exists. Continue?', message: 'Directory ' + name + ' already exists. Continue?',
validator: /y[es]*|n[o]?/, validator: /y[es]*|n[o]?/,
warning: 'Must respond yes or no', 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') { if (result.yesno[0] === 'y') {
createProject(name, options); createProject(name, options);
} else { } else {
@ -231,7 +230,7 @@ function createProject(name, options) {
console.log( console.log(
'This will walk you through creating a new React Native project in', 'This will walk you through creating a new React Native project in',
root root,
); );
if (!fs.existsSync(root)) { if (!fs.existsSync(root)) {
@ -246,9 +245,12 @@ function createProject(name, options) {
start: 'node node_modules/react-native/local-cli/cli.js start', start: 'node node_modules/react-native/local-cli/cli.js start',
ios: 'react-native run-ios', ios: 'react-native run-ios',
android: 'react-native run-android', 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); process.chdir(root);
run(root, projectName, options); run(root, projectName, options);
@ -269,7 +271,7 @@ function getInstallPackage(rnPackage) {
function run(root, projectName, options) { function run(root, projectName, options) {
var rnPackage = options.version; // e.g. '0.38' or '/path/to/archive.tgz' var rnPackage = options.version; // e.g. '0.38' or '/path/to/archive.tgz'
var forceNpmClient = options.npm; var forceNpmClient = options.npm;
var yarnVersion = (!forceNpmClient) && getYarnVersionIfAvailable(); var yarnVersion = !forceNpmClient && getYarnVersionIfAvailable();
var installCommand; var installCommand;
if (options.installCommand) { if (options.installCommand) {
// In CI environments it can be useful to provide a custom command, // In CI environments it can be useful to provide a custom command,
@ -286,9 +288,12 @@ function run(root, projectName, options) {
} else { } else {
console.log('Installing ' + getInstallPackage(rnPackage) + '...'); console.log('Installing ' + getInstallPackage(rnPackage) + '...');
if (!forceNpmClient) { 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) { if (options.verbose) {
installCommand += ' --verbose'; installCommand += ' --verbose';
} }
@ -312,13 +317,15 @@ function checkNodeVersion() {
return; return;
} }
if (!semver.satisfies(process.version, packageJson.engines.node)) { 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. ' + 'You are currently running Node %s but React Native requires %s. ' +
'Please use a supported version of Node.\n' + 'Please use a supported version of Node.\n' +
'See https://facebook.github.io/react-native/docs/getting-started.html' 'See https://facebook.github.io/react-native/docs/getting-started.html',
), ),
process.version, process.version,
packageJson.engines.node); packageJson.engines.node,
);
} }
} }
@ -327,7 +334,9 @@ function printVersionsAndExit(reactNativePackageJsonPath) {
try { try {
console.log('react-native: ' + require(reactNativePackageJsonPath).version); console.log('react-native: ' + require(reactNativePackageJsonPath).version);
} catch (e) { } 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(); process.exit();
} }

View File

@ -5,13 +5,16 @@
* *
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
* @format
*/ */
var argv = require('minimist')(process.argv.slice(2)); var argv = require('minimist')(process.argv.slice(2));
var cli = require('./cli'); var cli = require('./cli');
if (argv._.length === 0 && (argv.h || argv.help)) { if (argv._.length === 0 && (argv.h || argv.help)) {
console.log([ console.log(
[
'', '',
' Usage: react-native-git-upgrade [version] [options]', ' Usage: react-native-git-upgrade [version] [options]',
'', '',
@ -28,7 +31,8 @@ if (argv._.length === 0 && (argv.h || argv.help)) {
' --verbose output debugging info', ' --verbose output debugging info',
' --npm force using the npm client even if your project uses yarn', ' --npm force using the npm client even if your project uses yarn',
'', '',
].join('\n')); ].join('\n'),
);
process.exit(0); process.exit(0);
} }
@ -37,5 +41,4 @@ if (argv._.length === 0 && (argv.v || argv.version)) {
process.exit(0); process.exit(0);
} }
cli.run(argv._[0], argv) cli.run(argv._[0], argv).catch(console.error);
.catch(console.error);

View File

@ -4,6 +4,8 @@
* *
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
* @format
*/ */
'use strict'; 'use strict';
@ -14,13 +16,7 @@
* All you have to do is push changes to remote and CI will make a new build. * All you have to do is push changes to remote and CI will make a new build.
*/ */
const fs = require('fs'); const fs = require('fs');
const { const {cat, echo, exec, exit, sed} = require('shelljs');
cat,
echo,
exec,
exit,
sed,
} = require('shelljs');
const minimist = require('minimist'); const minimist = require('minimist');
@ -30,7 +26,9 @@ let argv = minimist(process.argv.slice(2), {
}); });
// - check we are in release branch, e.g. 0.33-stable // - check we are in release branch, e.g. 0.33-stable
let branch = exec('git symbolic-ref --short HEAD', {silent: true}).stdout.trim(); let branch = exec('git symbolic-ref --short HEAD', {
silent: true,
}).stdout.trim();
if (branch.indexOf('-stable') === -1) { if (branch.indexOf('-stable') === -1) {
echo('You must be in 0.XX-stable branch to bump a version'); echo('You must be in 0.XX-stable branch to bump a version');
@ -44,14 +42,18 @@ let versionMajor = branch.slice(0, branch.indexOf('-stable'));
// e.g. 0.33.1 or 0.33.0-rc4 // e.g. 0.33.1 or 0.33.0-rc4
let version = argv._[0]; let version = argv._[0];
if (!version || version.indexOf(versionMajor) !== 0) { if (!version || version.indexOf(versionMajor) !== 0) {
echo(`You must pass a tag like 0.${versionMajor}.[X]-rc[Y] to bump a version`); echo(
`You must pass a tag like 0.${versionMajor}.[X]-rc[Y] to bump a version`,
);
exit(1); exit(1);
} }
// Generate version files to detect mismatches between JS and native. // Generate version files to detect mismatches between JS and native.
let match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/); let match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
if (!match) { if (!match) {
echo(`You must pass a correctly formatted version; couldn't parse ${version}`); echo(
`You must pass a correctly formatted version; couldn't parse ${version}`,
);
exit(1); exit(1);
} }
let [, major, minor, patch, prerelease] = match; let [, major, minor, patch, prerelease] = match;
@ -62,8 +64,11 @@ fs.writeFileSync(
.replace('${major}', major) .replace('${major}', major)
.replace('${minor}', minor) .replace('${minor}', minor)
.replace('${patch}', patch) .replace('${patch}', patch)
.replace('${prerelease}', prerelease !== undefined ? `"${prerelease}"` : 'null'), .replace(
'utf-8' '${prerelease}',
prerelease !== undefined ? `"${prerelease}"` : 'null',
),
'utf-8',
); );
fs.writeFileSync( fs.writeFileSync(
@ -72,8 +77,11 @@ fs.writeFileSync(
.replace('${major}', `@(${major})`) .replace('${major}', `@(${major})`)
.replace('${minor}', `@(${minor})`) .replace('${minor}', `@(${minor})`)
.replace('${patch}', `@(${patch})`) .replace('${patch}', `@(${patch})`)
.replace('${prerelease}', prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]'), .replace(
'utf-8' '${prerelease}',
prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]',
),
'utf-8',
); );
fs.writeFileSync( fs.writeFileSync(
@ -82,8 +90,11 @@ fs.writeFileSync(
.replace('${major}', major) .replace('${major}', major)
.replace('${minor}', minor) .replace('${minor}', minor)
.replace('${patch}', patch) .replace('${patch}', patch)
.replace('${prerelease}', prerelease !== undefined ? `'${prerelease}'` : 'null'), .replace(
'utf-8' '${prerelease}',
prerelease !== undefined ? `'${prerelease}'` : 'null',
),
'utf-8',
); );
let packageJson = JSON.parse(cat('package.json')); let packageJson = JSON.parse(cat('package.json'));
@ -91,16 +102,27 @@ packageJson.version = version;
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8'); fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8');
// - change ReactAndroid/gradle.properties // - change ReactAndroid/gradle.properties
if (sed('-i', /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, 'ReactAndroid/gradle.properties').code) { if (
echo('Couldn\'t update version for Gradle'); sed(
'-i',
/^VERSION_NAME=.*/,
`VERSION_NAME=${version}`,
'ReactAndroid/gradle.properties',
).code
) {
echo("Couldn't update version for Gradle");
exit(1); exit(1);
} }
// verify that files changed, we just do a git diff and check how many times version is added across files // verify that files changed, we just do a git diff and check how many times version is added across files
let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true}) let numberOfChangedLinesWithNewVersion = exec(
.stdout.trim(); `git diff -U0 | grep '^[+]' | grep -c ${version} `,
{silent: true},
).stdout.trim();
if (+numberOfChangedLinesWithNewVersion !== 2) { if (+numberOfChangedLinesWithNewVersion !== 2) {
echo('Failed to update all the files. package.json and gradle.properties must have versions in them'); echo(
'Failed to update all the files. package.json and gradle.properties must have versions in them',
);
echo('Fix the issue, revert and try again'); echo('Fix the issue, revert and try again');
exec('git diff'); exec('git diff');
exit(1); exit(1);
@ -114,7 +136,9 @@ if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) {
// - add tag v0.21.0-rc // - add tag v0.21.0-rc
if (exec(`git tag v${version}`).code) { if (exec(`git tag v${version}`).code) {
echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`); echo(
`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`,
);
echo('You may want to rollback the last commit'); echo('You may want to rollback the last commit');
echo('git reset --hard HEAD~1'); echo('git reset --hard HEAD~1');
exit(1); exit(1);