2015-05-14 14:18:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var path = require('path');
|
2015-08-04 11:50:22 +00:00
|
|
|
var yeoman = require('yeoman-environment');
|
2015-05-14 14:18:44 +00:00
|
|
|
|
2015-10-08 16:49:05 +00:00
|
|
|
// 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.
|
2015-10-02 13:44:20 +00:00
|
|
|
function init(projectDir, argsOrName) {
|
2015-05-14 14:18:44 +00:00
|
|
|
console.log('Setting up new React Native app in ' + projectDir);
|
2015-08-04 11:50:22 +00:00
|
|
|
var env = yeoman.createEnv();
|
|
|
|
env.register(require.resolve(path.join(__dirname, 'generator')), 'react:app');
|
2015-10-08 16:49:05 +00:00
|
|
|
// argv is e.g.
|
|
|
|
// ['node', 'react-native', 'init', 'AwesomeApp', '--verbose']
|
|
|
|
// args is ['AwesomeApp', '--verbose']
|
2015-10-07 21:39:22 +00:00
|
|
|
var args = Array.isArray(argsOrName) ? argsOrName : [argsOrName].concat(process.argv.slice(4));
|
2015-09-14 14:35:58 +00:00
|
|
|
var generator = env.create('react:app', {args: args});
|
2015-08-04 11:50:22 +00:00
|
|
|
generator.destinationRoot(projectDir);
|
|
|
|
generator.run();
|
2015-05-14 14:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = init;
|