diff --git a/local-cli/cli.js b/local-cli/cli.js index 4f75e83db36d44..e21619cec5f649 100644 --- a/local-cli/cli.js +++ b/local-cli/cli.js @@ -4,9 +4,10 @@ 'use strict'; +var fs = require('fs'); var spawn = require('child_process').spawn; var path = require('path'); - +var generateAndroid = require('./generate-android.js'); var init = require('./init.js'); var install = require('./install.js'); var bundle = require('./bundle.js'); @@ -20,7 +21,8 @@ function printUsage() { ' start: starts the webserver', ' install: installs npm react components', ' bundle: builds the javascript bundle for offline use', - ' new-library: generates a native library bridge' + ' new-library: generates a native library bridge', + ' android: generates an Android project for your app' ].join('\n')); process.exit(1); } @@ -59,6 +61,12 @@ function run() { case 'init': printInitWarning(); break; + case 'android': + generateAndroid( + process.cwd(), + JSON.parse(fs.readFileSync('package.json', 'utf8')).name + ); + break; default: console.error('Command `%s` unrecognized', args[0]); printUsage(); diff --git a/local-cli/generate-android.js b/local-cli/generate-android.js new file mode 100644 index 00000000000000..cdfab974b1abe8 --- /dev/null +++ b/local-cli/generate-android.js @@ -0,0 +1,24 @@ +'use strict'; + +var fs = require('fs'); +var path = require('path'); +var yeoman = require('yeoman-environment'); + +module.exports = function(projectDir, name) { + fs.mkdirSync(path.join(projectDir, 'android')); + var oldCwd = process.cwd(); + process.chdir(path.join(projectDir, 'android')); + + var env = yeoman.createEnv(); + var generatorPath = path.join( + __dirname, + 'generator-react-native-android', + 'generators', + 'app', + 'index.js' + ); + env.register(generatorPath, 'android:app'); + env.run(['android:app', name], function() { + process.chdir(oldCwd); + }); +}; diff --git a/local-cli/init.js b/local-cli/init.js index 743eb4b001fcbe..2c86fca6c32f3e 100755 --- a/local-cli/init.js +++ b/local-cli/init.js @@ -1,6 +1,7 @@ 'use strict'; var fs = require('fs'); +var generateAndroid = require('./generate-android'); var path = require('path'); var utils = require('./generator-utils'); @@ -31,24 +32,7 @@ function init(projectDir, appName) { }); // generate Android source - fs.mkdirSync(path.join(projectDir, 'android')); - var oldCwd = process.cwd(); - process.chdir(path.join(projectDir, 'android')); - - var yeoman = require('yeoman-environment'); - var env = yeoman.createEnv(); - var generatorPath = path.join( - __dirname, - 'generator-react-native-android', - 'generators', - 'app', - 'index.js' - ); - env.register(generatorPath, 'android:app'); - env.run(['android:app', appName], function() { - process.chdir(oldCwd); - }); - + generateAndroid(projectDir, appName); console.log('Next Steps:'); console.log(' Open ' + path.resolve(projectDir, appName) + '.xcodeproj in Xcode');