Skip to content

Commit

Permalink
Merge pull request #4 from foghina/addandroid
Browse files Browse the repository at this point in the history
Add command to add android to existing project
  • Loading branch information
Felix Oghină committed Jul 22, 2015
2 parents a917b01 + 495772b commit 689bf3b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
12 changes: 10 additions & 2 deletions local-cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
24 changes: 24 additions & 0 deletions local-cli/generate-android.js
Original file line number Diff line number Diff line change
@@ -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);
});
};
20 changes: 2 additions & 18 deletions local-cli/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var fs = require('fs');
var generateAndroid = require('./generate-android');
var path = require('path');
var utils = require('./generator-utils');

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 689bf3b

Please sign in to comment.