Martin Konicek e612690413 Add license headers to local-cli
Reviewed By: martinbigio

Differential Revision: D2559969

fb-gh-sync-id: d8cd52435213729ff73a1f039eb0378b28f8d10e
2015-10-20 09:55:21 -07:00

42 lines
1.5 KiB
JavaScript
Executable File

/**
* 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';
var path = require('path');
var yeoman = require('yeoman-environment');
var TerminalAdapter = require('yeoman-environment/lib/adapter.js');
class CreateSuppressingTerminalAdapter extends TerminalAdapter {
constructor() {
super();
// suppres 'create' output generated by yeoman
this.log.create = function() {};
}
};
// argsOrName can be:
// - A string (e.g. 'AwesomeApp'). This is the common case when
// you run 'react-native init AwesomeApp' from the command line.
// - An array with all the arguments. This can be useful when you
// need to pass custom arguments to the generator.
function init(projectDir, argsOrName) {
console.log('Setting up new React Native app in ' + projectDir);
var env = yeoman.createEnv(undefined, undefined, new CreateSuppressingTerminalAdapter());
env.register(require.resolve(path.join(__dirname, 'generator')), 'react:app');
// argv is e.g.
// ['node', 'react-native', 'init', 'AwesomeApp', '--verbose']
// args is ['AwesomeApp', '--verbose']
var args = Array.isArray(argsOrName) ? argsOrName : [argsOrName].concat(process.argv.slice(4));
var generator = env.create('react:app', {args: args});
generator.destinationRoot(projectDir);
generator.run();
}
module.exports = init;