2015-04-04 01:00:23 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
var fs = require('fs');
|
2015-04-04 01:00:23 +00:00
|
|
|
var spawn = require('child_process').spawn;
|
|
|
|
var path = require('path');
|
2015-09-14 14:35:58 +00:00
|
|
|
var generateAndroid = require('./generate-android.js');
|
2015-05-14 17:08:56 +00:00
|
|
|
var init = require('./init.js');
|
2015-04-04 01:00:23 +00:00
|
|
|
var install = require('./install.js');
|
2015-04-15 00:19:58 +00:00
|
|
|
var bundle = require('./bundle.js');
|
2015-03-28 15:50:31 +00:00
|
|
|
var newLibrary = require('./new-library.js');
|
2015-09-14 14:35:58 +00:00
|
|
|
var runAndroid = require('./run-android.js');
|
|
|
|
var runPackager = require('./run-packager.js');
|
2015-04-04 01:00:23 +00:00
|
|
|
|
|
|
|
function printUsage() {
|
|
|
|
console.log([
|
|
|
|
'Usage: react-native <command>',
|
|
|
|
'',
|
|
|
|
'Commands:',
|
|
|
|
' start: starts the webserver',
|
2015-04-15 00:19:58 +00:00
|
|
|
' install: installs npm react components',
|
2015-03-28 15:50:31 +00:00
|
|
|
' bundle: builds the javascript bundle for offline use',
|
2015-09-14 14:35:58 +00:00
|
|
|
' new-library: generates a native library bridge',
|
|
|
|
' android: generates an Android project for your app'
|
2015-04-04 01:00:23 +00:00
|
|
|
].join('\n'));
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2015-05-04 19:17:47 +00:00
|
|
|
function printInitWarning() {
|
|
|
|
console.log([
|
|
|
|
'Looks like React Native project already exists in the current',
|
|
|
|
'folder. Run this command from a different folder or remove node_modules/react-native'
|
|
|
|
].join('\n'));
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2015-04-04 01:00:23 +00:00
|
|
|
function run() {
|
|
|
|
var args = process.argv.slice(2);
|
|
|
|
if (args.length === 0) {
|
|
|
|
printUsage();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args[0]) {
|
|
|
|
case 'start':
|
2015-09-14 14:35:58 +00:00
|
|
|
runPackager();
|
2015-04-04 01:00:23 +00:00
|
|
|
break;
|
|
|
|
case 'install':
|
|
|
|
install.init();
|
|
|
|
break;
|
2015-04-15 00:19:58 +00:00
|
|
|
case 'bundle':
|
|
|
|
bundle.init(args);
|
|
|
|
break;
|
2015-03-28 15:50:31 +00:00
|
|
|
case 'new-library':
|
|
|
|
newLibrary.init(args);
|
|
|
|
break;
|
2015-05-04 19:17:47 +00:00
|
|
|
case 'init':
|
|
|
|
printInitWarning();
|
|
|
|
break;
|
2015-09-14 14:35:58 +00:00
|
|
|
case 'android':
|
|
|
|
generateAndroid(
|
|
|
|
process.cwd(),
|
|
|
|
JSON.parse(fs.readFileSync('package.json', 'utf8')).name
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'run-android':
|
|
|
|
runAndroid();
|
|
|
|
break;
|
2015-04-04 01:00:23 +00:00
|
|
|
default:
|
|
|
|
console.error('Command `%s` unrecognized', args[0]);
|
|
|
|
printUsage();
|
|
|
|
}
|
|
|
|
// Here goes any cli commands we need to
|
|
|
|
}
|
|
|
|
|
2015-04-07 19:33:41 +00:00
|
|
|
if (require.main === module) {
|
|
|
|
run();
|
|
|
|
}
|
|
|
|
|
2015-04-04 01:00:23 +00:00
|
|
|
module.exports = {
|
|
|
|
run: run,
|
|
|
|
init: init,
|
|
|
|
};
|