Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Options parsing, add support for --version #651

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,37 @@

var spawn = require('child_process').spawn;
var path = require('path');

function printUsage() {
console.log([
'Usage: react-native <command>',
'',
'Commands:',
' start: starts the webserver',
].join('\n'));
process.exit(1);
}
var program = require('commander');
var spec = require('./package.json');

function run() {
var args = process.argv.slice(2);
if (args.length === 0) {
printUsage();
}
program.version(spec.version);

program
.command('start')
.description('starts the webserver')
.action(startServer);

switch (args[0]) {
case 'start':
spawn('sh', [
path.resolve(__dirname, 'packager', 'packager.sh'),
'--projectRoots',
process.cwd(),
], {stdio: 'inherit'});
break;
default:
console.error('Command `%s` unrecognized', args[0]);
printUsage();
program.on('*', function(command) {
console.error('Command `%s` unrecognized', command);
program.outputHelp();
process.exit(1);
});

program.parse(process.argv);

if (!program.args.length) {
program.outputHelp();
process.exit(1);
}
// Here goes any cli commands we need to
}

function startServer() {
spawn('sh', [
path.resolve(__dirname, 'packager', 'packager.sh'),
'--projectRoots',
process.cwd(),
], {stdio: 'inherit'});
}

function init(root, projectName) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"react-native-start": "packager/packager.sh"
},
"dependencies": {
"commander": "^2.7.x",
"connect": "2.8.3",
"jstransform": "10.1.0",
"react-timer-mixin": "^0.13.1",
Expand Down
3 changes: 3 additions & 0 deletions react-native-cli/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env node

/**
* This is the react-native binary installed globally. It shouldn't change
* much as it just delegates calls to cli.js, which can be updated idependently
*
* Copyright 2004-present Facebook. All Rights Reserved.
*/

Expand Down