Prettier RN local-cli

Reviewed By: yungsters

Differential Revision: D7962462

fbshipit-source-id: 0afe2092af8703895de91a6d1400315c3173aa6d
This commit is contained in:
Eli White
2018-05-11 12:43:49 -07:00
committed by Facebook Github Bot
parent 680fb50040
commit aba4ec0c09
209 changed files with 3167 additions and 2071 deletions

View File

@@ -3,7 +3,10 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const {
@@ -58,42 +61,53 @@ function init(projectDir, argsOrName) {
*/
function generateProject(destinationRoot, newProjectName, options) {
var reactNativePackageJson = require('../../package.json');
var { peerDependencies } = reactNativePackageJson;
var {peerDependencies} = reactNativePackageJson;
if (!peerDependencies) {
console.error('Missing React peer dependency in React Native\'s package.json. Aborting.');
console.error(
"Missing React peer dependency in React Native's package.json. Aborting.",
);
return;
}
var reactVersion = peerDependencies.react;
if (!reactVersion) {
console.error('Missing React peer dependency in React Native\'s package.json. Aborting.');
console.error(
"Missing React peer dependency in React Native's package.json. Aborting.",
);
return;
}
const yarnVersion =
(!options.npm) &&
!options.npm &&
yarn.getYarnVersionIfAvailable() &&
yarn.isGlobalCliUsingYarn(destinationRoot);
createProjectFromTemplate(destinationRoot, newProjectName, options.template, yarnVersion);
createProjectFromTemplate(
destinationRoot,
newProjectName,
options.template,
yarnVersion,
);
if (yarnVersion) {
console.log('Adding React...');
execSync(`yarn add react@${reactVersion}`, {stdio: 'inherit'});
} else {
console.log('Installing React...');
execSync(`npm install react@${reactVersion} --save --save-exact`, {stdio: 'inherit'});
execSync(`npm install react@${reactVersion} --save --save-exact`, {
stdio: 'inherit',
});
}
if (!options['skip-jest']) {
const jestDeps = (
`jest babel-jest babel-preset-react-native react-test-renderer@${reactVersion}`
);
const jestDeps = `jest babel-jest babel-preset-react-native react-test-renderer@${reactVersion}`;
if (yarnVersion) {
console.log('Adding Jest...');
execSync(`yarn add ${jestDeps} --dev --exact`, {stdio: 'inherit'});
} else {
console.log('Installing Jest...');
execSync(`npm install ${jestDeps} --save-dev --save-exact`, {stdio: 'inherit'});
execSync(`npm install ${jestDeps} --save-dev --save-exact`, {
stdio: 'inherit',
});
}
addJestToPackageJson(destinationRoot);
}
@@ -109,7 +123,7 @@ function addJestToPackageJson(destinationRoot) {
packageJSON.scripts.test = 'jest';
packageJSON.jest = {
preset: 'react-native'
preset: 'react-native',
};
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2));
}