Skip to content

Commit 36697ae

Browse files
martinbigiofacebook-github-bot-7
authored andcommitted
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
1 parent ca1bc35 commit 36697ae

2 files changed

Lines changed: 85 additions & 7 deletions

File tree

local-cli/cli.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
'use strict';
66

77
var bundle = require('../private-cli/src/bundle/bundle');
8-
var bundle_DEPRECATED = require('./bundle.js');
98
var Config = require('../private-cli/src/util/Config');
109
var fs = require('fs');
11-
var generateAndroid = require('./generate-android.js');
10+
var generate = require('../private-cli/src/generate/generate');
1211
var init = require('./init.js');
1312
var newLibrary = require('./new-library.js');
1413
var runAndroid = require('./run-android.js');
1514
var runPackager = require('./run-packager.js');
1615

16+
// TODO: remove once we fully roll out the `private-cli` based cli
17+
// var bundle_DEPRECATED = require('./bundle.js');
18+
// var generateAndroid_DEPRECATED = require('./generate-android.js');
19+
1720
function printUsage() {
1821
console.log([
1922
'Usage: react-native <command>',
@@ -41,12 +44,14 @@ function run() {
4144
printUsage();
4245
}
4346

47+
var config = Config.get(__dirname);
48+
4449
switch (args[0]) {
4550
case 'start':
4651
runPackager();
4752
break;
4853
case 'bundle':
49-
bundle(args, Config.get(__dirname)).done();
54+
bundle(args, config).done();
5055
// bundle_DEPRECATED.init(args);
5156
break;
5257
case 'new-library':
@@ -56,10 +61,20 @@ function run() {
5661
printInitWarning();
5762
break;
5863
case 'android':
59-
generateAndroid(
60-
process.cwd(),
61-
JSON.parse(fs.readFileSync('package.json', 'utf8')).name
62-
);
64+
generate(
65+
[
66+
'--platform', 'android',
67+
'--project-path', process.cwd(),
68+
'--project-name', JSON.parse(
69+
fs.readFileSync('package.json', 'utf8')
70+
).name
71+
],
72+
config
73+
).done();
74+
// generateAndroid(
75+
// process.cwd(),
76+
// JSON.parse(fs.readFileSync('package.json', 'utf8')).name
77+
// );
6378
break;
6479
case 'run-android':
6580
runAndroid();
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
'use strict';
10+
11+
const parseCommandLine = require('../../../packager/parseCommandLine');
12+
const path = require('path');
13+
const Promise = require('promise');
14+
const yeoman = require('yeoman-environment');
15+
16+
/**
17+
* Generates the template for the given platform.
18+
*/
19+
function generate(argv, config) {
20+
return new Promise((resolve, reject) => {
21+
_generate(argv, config, resolve, reject);
22+
});
23+
}
24+
25+
function _generate(argv, config, resolve, reject) {
26+
const args = parseCommandLine([{
27+
command: 'platform',
28+
description: 'Platform (ios|android)',
29+
type: 'string',
30+
required: true,
31+
},
32+
{
33+
command: 'project-path',
34+
description: 'Path to the project directory',
35+
type: 'string',
36+
required: true,
37+
},
38+
{
39+
command: 'project-name',
40+
description: 'Name of the project',
41+
type: 'string',
42+
required: true,
43+
}], argv);
44+
45+
const oldCwd = process.cwd();
46+
process.chdir(args['project-path']);
47+
48+
const env = yeoman.createEnv();
49+
env.register(path.join(__dirname, '../../../local-cli/generator'), 'react:app');
50+
env.run(
51+
['react:app', args['project-name']],
52+
{
53+
'skip-ios': args.platform !== 'ios',
54+
'skip-android': args.platform !== 'android'
55+
},
56+
() => {
57+
process.chdir(oldCwd);
58+
resolve();
59+
}
60+
);
61+
}
62+
63+
module.exports = generate;

0 commit comments

Comments
 (0)