Move android generator to private-cli
Summary: @public Lets also make this more generic to allow to generate the template for any platform code. Reviewed By: @vjeux Differential Revision: D2536821 fb-gh-sync-id: 6fb99c6dc546b8e1f9839c96a473dc08b0f5285c
This commit is contained in:
parent
ca1bc35940
commit
36697ae6a1
|
@ -5,15 +5,18 @@
|
|||
'use strict';
|
||||
|
||||
var bundle = require('../private-cli/src/bundle/bundle');
|
||||
var bundle_DEPRECATED = require('./bundle.js');
|
||||
var Config = require('../private-cli/src/util/Config');
|
||||
var fs = require('fs');
|
||||
var generateAndroid = require('./generate-android.js');
|
||||
var generate = require('../private-cli/src/generate/generate');
|
||||
var init = require('./init.js');
|
||||
var newLibrary = require('./new-library.js');
|
||||
var runAndroid = require('./run-android.js');
|
||||
var runPackager = require('./run-packager.js');
|
||||
|
||||
// TODO: remove once we fully roll out the `private-cli` based cli
|
||||
// var bundle_DEPRECATED = require('./bundle.js');
|
||||
// var generateAndroid_DEPRECATED = require('./generate-android.js');
|
||||
|
||||
function printUsage() {
|
||||
console.log([
|
||||
'Usage: react-native <command>',
|
||||
|
@ -41,12 +44,14 @@ function run() {
|
|||
printUsage();
|
||||
}
|
||||
|
||||
var config = Config.get(__dirname);
|
||||
|
||||
switch (args[0]) {
|
||||
case 'start':
|
||||
runPackager();
|
||||
break;
|
||||
case 'bundle':
|
||||
bundle(args, Config.get(__dirname)).done();
|
||||
bundle(args, config).done();
|
||||
// bundle_DEPRECATED.init(args);
|
||||
break;
|
||||
case 'new-library':
|
||||
|
@ -56,10 +61,20 @@ function run() {
|
|||
printInitWarning();
|
||||
break;
|
||||
case 'android':
|
||||
generateAndroid(
|
||||
process.cwd(),
|
||||
JSON.parse(fs.readFileSync('package.json', 'utf8')).name
|
||||
);
|
||||
generate(
|
||||
[
|
||||
'--platform', 'android',
|
||||
'--project-path', process.cwd(),
|
||||
'--project-name', JSON.parse(
|
||||
fs.readFileSync('package.json', 'utf8')
|
||||
).name
|
||||
],
|
||||
config
|
||||
).done();
|
||||
// generateAndroid(
|
||||
// process.cwd(),
|
||||
// JSON.parse(fs.readFileSync('package.json', 'utf8')).name
|
||||
// );
|
||||
break;
|
||||
case 'run-android':
|
||||
runAndroid();
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const parseCommandLine = require('../../../packager/parseCommandLine');
|
||||
const path = require('path');
|
||||
const Promise = require('promise');
|
||||
const yeoman = require('yeoman-environment');
|
||||
|
||||
/**
|
||||
* Generates the template for the given platform.
|
||||
*/
|
||||
function generate(argv, config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
_generate(argv, config, resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
function _generate(argv, config, resolve, reject) {
|
||||
const args = parseCommandLine([{
|
||||
command: 'platform',
|
||||
description: 'Platform (ios|android)',
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
command: 'project-path',
|
||||
description: 'Path to the project directory',
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
command: 'project-name',
|
||||
description: 'Name of the project',
|
||||
type: 'string',
|
||||
required: true,
|
||||
}], argv);
|
||||
|
||||
const oldCwd = process.cwd();
|
||||
process.chdir(args['project-path']);
|
||||
|
||||
const env = yeoman.createEnv();
|
||||
env.register(path.join(__dirname, '../../../local-cli/generator'), 'react:app');
|
||||
env.run(
|
||||
['react:app', args['project-name']],
|
||||
{
|
||||
'skip-ios': args.platform !== 'ios',
|
||||
'skip-android': args.platform !== 'android'
|
||||
},
|
||||
() => {
|
||||
process.chdir(oldCwd);
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = generate;
|
Loading…
Reference in New Issue