Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI Project Generator: Explicitly include a default .babelrc #7822

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions local-cli/__tests__/generators-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ xdescribe('React Yeoman Generators', function() {
'.flowconfig',
'.gitignore',
'.watchmanconfig',
'.babelrc',
'index.ios.js',
'index.android.js'
]);
Expand Down
4 changes: 4 additions & 0 deletions local-cli/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ module.exports = yeoman.generators.NamedBase.extend({
this.templatePath('_buckconfig'),
this.destinationPath('.buckconfig')
);
this.fs.copy(
this.templatePath('_babelrc'),
this.destinationPath('.babelrc')
);
},

writing: function() {
Expand Down
3 changes: 3 additions & 0 deletions local-cli/generator/templates/_babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
23 changes: 14 additions & 9 deletions react-native-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,28 @@ function createProject(name, verbose, rnPackage) {
}
}

function getInstallPackage(rnPackage) {
var packageToInstall = 'react-native';
function getInstallPackages(rnPackage) {
var reactNativePackageToInstall = 'react-native';
var valideSemver = semver.valid(rnPackage);
if (valideSemver) {
packageToInstall += '@' + valideSemver;
reactNativePackageToInstall += '@' + valideSemver;
} else if (rnPackage) {
// for tar.gz or alternative paths
packageToInstall = rnPackage;
reactNativePackageToInstall = rnPackage;
}
return packageToInstall;
return [
reactNativePackageToInstall,
'babel-preset-react-native'
].join(' ');
}

function run(root, projectName, rnPackage) {
exec('npm install --save ' + getInstallPackage(rnPackage), function(e, stdout, stderr) {
var installPackages = getInstallPackages(rnPackage);
exec('npm install --save ' + installPackages, function(e, stdout, stderr) {
if (e) {
console.log(stdout);
console.error(stderr);
console.error('`npm install --save react-native` failed');
console.error('`npm install --save ' + installPackages + '` failed');
process.exit(1);
}

Expand All @@ -229,10 +233,11 @@ function run(root, projectName, rnPackage) {
}

function runVerbose(root, projectName, rnPackage) {
var proc = spawn('npm', ['install', '--verbose', '--save', getInstallPackage(rnPackage)], {stdio: 'inherit'});
var installPackages = getInstallPackages(rnPackage);
var proc = spawn('npm', ['install', '--verbose', '--save', installPackages], {stdio: 'inherit'});
proc.on('close', function (code) {
if (code !== 0) {
console.error('`npm install --save react-native` failed');
console.error('`npm install --save ' + installPackages + '` failed');
return;
}

Expand Down