2015-10-15 17:19:21 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
|
2015-10-26 19:59:54 +00:00
|
|
|
const parseCommandLine = require('../util/parseCommandLine');
|
2015-10-15 17:19:21 +00:00
|
|
|
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();
|
2015-10-26 14:55:29 +00:00
|
|
|
env.register(path.join(__dirname, '../generator'), 'react:app');
|
2015-10-15 17:19:21 +00:00
|
|
|
env.run(
|
|
|
|
['react:app', args['project-name']],
|
|
|
|
{
|
|
|
|
'skip-ios': args.platform !== 'ios',
|
|
|
|
'skip-android': args.platform !== 'android'
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
process.chdir(oldCwd);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = generate;
|