mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Release React Native for Android
This is an early release and there are several things that are known not to work if you're porting your iOS app to Android. See the Known Issues guide on the website. We will work with the community to reach platform parity with iOS.
This commit is contained in:
64
local-cli/generator-android/index.js
Normal file
64
local-cli/generator-android/index.js
Normal file
@@ -0,0 +1,64 @@
|
||||
'use strict';
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var yeoman = require('yeoman-generator');
|
||||
|
||||
function validatePackageName(name) {
|
||||
if (!name.match(/^([a-zA-Z_$][a-zA-Z\d_$]*\.)+([a-zA-Z_$][a-zA-Z\d_$]*)$/)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = yeoman.generators.NamedBase.extend({
|
||||
constructor: function() {
|
||||
yeoman.generators.NamedBase.apply(this, arguments);
|
||||
|
||||
this.option('package', {
|
||||
desc: 'Package name for the application (com.example.app)',
|
||||
type: String,
|
||||
defaults: 'com.' + this.name.toLowerCase()
|
||||
});
|
||||
},
|
||||
|
||||
initializing: function() {
|
||||
if (!validatePackageName(this.options.package)) {
|
||||
throw new Error('Package name ' + this.options.package + ' is invalid');
|
||||
}
|
||||
},
|
||||
|
||||
writing: function() {
|
||||
var templateParams = {
|
||||
package: this.options.package,
|
||||
name: this.name
|
||||
};
|
||||
this.fs.copyTpl(
|
||||
this.templatePath(path.join('src', '**')),
|
||||
this.destinationPath('android'),
|
||||
templateParams
|
||||
);
|
||||
this.fs.copy(
|
||||
this.templatePath(path.join('bin', '**')),
|
||||
this.destinationPath('android')
|
||||
);
|
||||
var javaPath = path.join.apply(
|
||||
null,
|
||||
['android', 'app', 'src', 'main', 'java'].concat(this.options.package.split('.'))
|
||||
);
|
||||
this.fs.copyTpl(
|
||||
this.templatePath(path.join('package', '**')),
|
||||
this.destinationPath(javaPath),
|
||||
templateParams
|
||||
);
|
||||
},
|
||||
|
||||
end: function() {
|
||||
var projectPath = this.destinationRoot();
|
||||
this.log(chalk.white.bold('To run your app on Android:'));
|
||||
this.log(chalk.white(' Have an Android emulator running, or a device connected'));
|
||||
this.log(chalk.white(' cd ' + projectPath));
|
||||
this.log(chalk.white(' react-native run-android'));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user