mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
react-native-cli initial commit
A cli package that is responsible for: * starting a new react-native project * forwarding all other commands to a cli module in react-native * currently cli.js knows how to start the webserver, in the future it may do things like build the app etc.
This commit is contained in:
48
cli.js
Normal file
48
cli.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function run() {
|
||||
var args = process.argv.slice(2);
|
||||
if (args.length === 0) {
|
||||
printUsage();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
// Here goes any cli commands we need to
|
||||
}
|
||||
|
||||
function init() {
|
||||
spawn('sh', [path.resolve(__dirname, 'init.sh')], {stdio:'inherit'});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run: run,
|
||||
init: init,
|
||||
};
|
||||
Reference in New Issue
Block a user