2015-04-04 01:00:23 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var spawn = require('child_process').spawn;
|
|
|
|
var path = require('path');
|
|
|
|
var install = require('./install.js');
|
2015-04-15 00:19:58 +00:00
|
|
|
var bundle = require('./bundle.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',
|
|
|
|
' bundle: builds the javascript bundle for offline use'
|
2015-04-04 01:00:23 +00:00
|
|
|
].join('\n'));
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run() {
|
|
|
|
var args = process.argv.slice(2);
|
|
|
|
if (args.length === 0) {
|
|
|
|
printUsage();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args[0]) {
|
|
|
|
case 'start':
|
|
|
|
spawn('sh', [
|
2015-04-08 08:21:30 +00:00
|
|
|
path.resolve(__dirname, '../packager', 'packager.sh'),
|
2015-04-04 01:00:23 +00:00
|
|
|
'--projectRoots',
|
|
|
|
process.cwd(),
|
|
|
|
], {stdio: 'inherit'});
|
|
|
|
break;
|
|
|
|
case 'install':
|
|
|
|
install.init();
|
|
|
|
break;
|
2015-04-15 00:19:58 +00:00
|
|
|
case 'bundle':
|
|
|
|
bundle.init(args);
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
function init(root, projectName) {
|
2015-04-08 04:30:46 +00:00
|
|
|
spawn(path.resolve(__dirname, '../init.sh'), [projectName], {stdio:'inherit'});
|
2015-04-04 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
};
|