Martin Konicek 6bee16a63d Use Yarn if available
Summary:
**Motivation**

If the project is using yarn to manage its dependencies, we should be running 'yarn add' to upgrade the React Native dependency, rather than 'npm install'.

**Test plan (required)**

Running in a project that's in a bad state:

    Error: react-native version in "package.json" (0.29.2) doesn't match the installed version in "node_modules" (0.38.0).
    Try running "yarn" to fix this.

Removed yarn.lock file, ran again:

    Error: react-native version in "package.json" (0.29.2) doesn't match the installed version in "node_modules" (0.38.0).
    Try running "npm install" to fix this.

Running inside a folder that doesn't contain a `package.json` file:

    Error: Unable to find "/Users/mkonicek/Zero29App/package.json" or "/Users/mkonicek/Zero29App/node_modules/react-native/package.json". Make sure you ran "yarn" and that you are inside a React Native project.

Removed yarn.lock file, ran again:

    Error: Unable to find "/Users/mkonicek/Zero29App/package.json" or "/Users/
Closes https://github.com/facebook/react-native/pull/11225

Differential Revision: D4261102

Pulled By: mkonicek

fbshipit-source-id: b44ae91fe46f2c81b14616ca2868cc171692c895
2016-12-02 00:13:32 -08:00

44 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
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'));
process.exit(0);
}
if (argv._.length === 0 && (argv.v || argv.version)) {
console.log(require('./package.json').version);
process.exit(0);
}
cli.run(argv._[0], argv)
.catch(console.error);