Konstantin Raev f22e9353a7 Made react installed via reac-native init strict to unbreak 15.1.0
Summary:
React@15.1.0 is incompatible with React-Native@0.26.
This PR was cherry-picked to 0.26-stable branch now.

What this change does:
- react-native-cli (major release bump) saves exact versions of react-native and react (only in npm2) dependencies into package.json
- local-cli saves exact version of react (only npm3) dependency into package.json
Closes https://github.com/facebook/react-native/pull/7879

Differential Revision: D3384705

Pulled By: davidaurelio

fbshipit-source-id: d4dff418f9659bd083ae8826433a4e7c0355d03b
2016-06-03 03:43:31 -07:00

113 lines
3.0 KiB
JavaScript

/**
* 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.
*/
'use strict';
var path = require('path');
var yeoman = require('yeoman-generator');
var utils = require('../generator-utils');
module.exports = yeoman.generators.NamedBase.extend({
constructor: function() {
yeoman.generators.NamedBase.apply(this, arguments);
this.option('skip-ios', {
desc: 'Skip generating iOS files',
type: Boolean,
defaults: false
});
this.option('skip-android', {
desc: 'Skip generating Android files',
type: Boolean,
defaults: false
});
this.option('upgrade', {
desc: 'Specify an upgrade',
type: Boolean,
defaults: false
});
// this passes command line arguments down to the composed generators
var args = {args: arguments[0], options: this.options};
if (!this.options['skip-ios']) {
this.composeWith('react:ios', args, {
local: require.resolve(path.resolve(__dirname, '..', 'generator-ios'))
});
}
if (!this.options['skip-android']) {
this.composeWith('react:android', args, {
local: require.resolve(path.resolve(__dirname, '..', 'generator-android'))
});
}
},
configuring: function() {
utils.copyAndReplace(
this.templatePath('../../../.flowconfig'),
this.destinationPath('.flowconfig'),
{
'Libraries\/react-native\/react-native-interface.js' : 'node_modules/react-native/Libraries/react-native/react-native-interface.js',
'^flow/$' : 'node_modules/react-native/flow\nflow/'
}
);
this.fs.copy(
this.templatePath('_gitignore'),
this.destinationPath('.gitignore')
);
this.fs.copy(
this.templatePath('_watchmanconfig'),
this.destinationPath('.watchmanconfig')
);
this.fs.copy(
this.templatePath('_buckconfig'),
this.destinationPath('.buckconfig')
);
},
writing: function() {
if (this.options.upgrade) {
// never upgrade index.*.js files
return;
}
if (!this.options['skip-ios']) {
this.fs.copyTpl(
this.templatePath('index.ios.js'),
this.destinationPath('index.ios.js'),
{name: this.name}
);
}
if (!this.options['skip-android']) {
this.fs.copyTpl(
this.templatePath('index.android.js'),
this.destinationPath('index.android.js'),
{name: this.name}
);
}
},
install: function() {
if (this.options.upgrade) {
return;
}
var reactNativePackageJson = require('../../package.json');
var { peerDependencies } = reactNativePackageJson;
if (!peerDependencies) {
return;
}
var reactVersion = peerDependencies.react;
if (!reactVersion) {
return;
}
this.npmInstall(`react@${reactVersion}`, { '--save': true, '--save-exact': true });
}
});