local-cli/init/init.js
/**
 * Generates a new React Native project based on the template.
 * @param Absolute path at which the project folder should be created.
 * @param options Command line arguments parsed by minimist.
 */
Generates a new React Native project based on the template.
@param Absolute path at which the project folder should be created.
@param options Command line arguments parsed by minimist.
Generates a new React Native project based on the template . @param Absolute path at which the project folder should be created . @param options Command line arguments parsed by minimist .
function generateProject(destinationRoot, newProjectName, options) {
  var reactNativePackageJson = require('../../package.json');
  var { peerDependencies } = reactNativePackageJson;
  if (!peerDependencies) {
    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.');
    return;
  }
  const yarnVersion =
    (!options.npm) &&
    yarn.getYarnVersionIfAvailable() &&
    yarn.isGlobalCliUsingYarn(destinationRoot);
  createProjectFromTemplate(destinationRoot, newProjectName, options.template, yarnVersion);
  if (yarnVersion) {
    console.log('Adding React...');
    execSync(`yarn add react@${reactVersion}`, {stdio: 'inherit'});
    execSync(`yarn add babel-plugin-module-resolver`, {stdio: 'inherit'});
  } else {
    console.log('Installing React...');
    execSync(`npm install react@${reactVersion} --save --save-exact`, {stdio: 'inherit'});
    execSync(`npm install babel-plugin-module-resolver --save-dev`);
  }
  if (!options['skip-jest']) {
    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'});
    }
    addJestToPackageJson(destinationRoot);
  }
  printRunInstructions(destinationRoot, newProjectName);
}
function generateProject ( destinationRoot , newProjectName , options ) { var reactNativePackageJson = require ( '../../package.json' ) ; var { peerDependencies } = reactNativePackageJson ; if ( ! peerDependencies ) { 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.' ) ; return ; } const yarnVersion = ( ! options . npm ) && yarn . getYarnVersionIfAvailable ( ) && yarn . isGlobalCliUsingYarn ( destinationRoot ) ; createProjectFromTemplate ( destinationRoot , newProjectName , options . template , yarnVersion ) ; if ( yarnVersion ) { console . log ( 'Adding React...' ) ; execSync ( ` ${ reactVersion } ` , { stdio : 'inherit' } ) ; execSync ( ` ` , { stdio : 'inherit' } ) ; } else { console . log ( 'Installing React...' ) ; execSync ( ` ${ reactVersion } ` , { stdio : 'inherit' } ) ; execSync ( ` ` ) ; } if ( ! options [ 'skip-jest' ] ) { const jestDeps = ( ` ${ reactVersion } ` ) ; if ( yarnVersion ) { console . log ( 'Adding Jest...' ) ; execSync ( ` ${ jestDeps } ` , { stdio : 'inherit' } ) ; } else { console . log ( 'Installing Jest...' ) ; execSync ( ` ${ jestDeps } ` , { stdio : 'inherit' } ) ; } addJestToPackageJson ( destinationRoot ) ; } printRunInstructions ( destinationRoot , newProjectName ) ; }
Generates a new React Native project based on the template.
Generates a new React Native project based on the template .