mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 03:50:11 +08:00
Prettier RN local-cli
Reviewed By: yungsters Differential Revision: D7962462 fbshipit-source-id: 0afe2092af8703895de91a6d1400315c3173aa6d
This commit is contained in:
committed by
Facebook Github Bot
parent
680fb50040
commit
aba4ec0c09
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user