2015-04-04 01:00:23 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-10-13 17:44:00 +00:00
|
|
|
var bundle = require('../private-cli/src/bundle/bundle');
|
|
|
|
var Config = require('../private-cli/src/util/Config');
|
2015-09-14 14:35:58 +00:00
|
|
|
var fs = require('fs');
|
2015-10-15 17:19:21 +00:00
|
|
|
var generate = require('../private-cli/src/generate/generate');
|
2015-05-14 17:08:56 +00:00
|
|
|
var init = require('./init.js');
|
2015-10-16 15:20:29 +00:00
|
|
|
var library = require('../private-cli/src/library/library');
|
2015-09-14 14:35:58 +00:00
|
|
|
var runAndroid = require('./run-android.js');
|
2015-10-16 22:00:04 +00:00
|
|
|
var server = require('../private-cli/src/server/server');
|
2015-04-04 01:00:23 +00:00
|
|
|
|
2015-10-15 17:19:21 +00:00
|
|
|
// TODO: remove once we fully roll out the `private-cli` based cli
|
|
|
|
// var bundle_DEPRECATED = require('./bundle.js');
|
|
|
|
// var generateAndroid_DEPRECATED = require('./generate-android.js');
|
2015-10-16 15:20:29 +00:00
|
|
|
// var newLibrary_DEPRECATED = require('./new-library.js');
|
2015-10-16 22:00:04 +00:00
|
|
|
// var runPackager_DEPRECATED = require('./run-packager.js');
|
2015-10-15 17:19:21 +00:00
|
|
|
|
2015-04-04 01:00:23 +00:00
|
|
|
function printUsage() {
|
|
|
|
console.log([
|
|
|
|
'Usage: react-native <command>',
|
|
|
|
'',
|
|
|
|
'Commands:',
|
|
|
|
' start: starts the webserver',
|
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();
|
|
|
|
}
|
|
|
|
|
2015-10-15 17:19:21 +00:00
|
|
|
var config = Config.get(__dirname);
|
2015-04-04 01:00:23 +00:00
|
|
|
switch (args[0]) {
|
|
|
|
case 'start':
|
2015-10-16 22:00:04 +00:00
|
|
|
server(args, config).done();
|
|
|
|
// runPackager_DEPRECATED();
|
2015-04-04 01:00:23 +00:00
|
|
|
break;
|
2015-04-15 00:19:58 +00:00
|
|
|
case 'bundle':
|
2015-10-15 17:19:21 +00:00
|
|
|
bundle(args, config).done();
|
2015-10-13 17:44:00 +00:00
|
|
|
// bundle_DEPRECATED.init(args);
|
2015-04-15 00:19:58 +00:00
|
|
|
break;
|
2015-03-28 15:50:31 +00:00
|
|
|
case 'new-library':
|
2015-10-16 15:20:29 +00:00
|
|
|
library(args, config).done();
|
|
|
|
// newLibrary_DEPRECATED.init(args);
|
2015-03-28 15:50:31 +00:00
|
|
|
break;
|
2015-05-04 19:17:47 +00:00
|
|
|
case 'init':
|
|
|
|
printInitWarning();
|
|
|
|
break;
|
2015-09-14 14:35:58 +00:00
|
|
|
case 'android':
|
2015-10-15 17:19:21 +00:00
|
|
|
generate(
|
|
|
|
[
|
|
|
|
'--platform', 'android',
|
|
|
|
'--project-path', process.cwd(),
|
|
|
|
'--project-name', JSON.parse(
|
|
|
|
fs.readFileSync('package.json', 'utf8')
|
|
|
|
).name
|
|
|
|
],
|
|
|
|
config
|
|
|
|
).done();
|
|
|
|
// generateAndroid(
|
|
|
|
// process.cwd(),
|
|
|
|
// JSON.parse(fs.readFileSync('package.json', 'utf8')).name
|
|
|
|
// );
|
2015-09-14 14:35:58 +00:00
|
|
|
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,
|
|
|
|
};
|