forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
76 lines (67 loc) · 1.6 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*/
'use strict';
var spawn = require('child_process').spawn;
var path = require('path');
var init = require('./init.js');
var install = require('./install.js');
var bundle = require('./bundle.js');
var newLibrary = require('./new-library.js');
function printUsage() {
console.log([
'Usage: react-native <command>',
'',
'Commands:',
' start: starts the webserver',
' install: installs npm react components',
' bundle: builds the javascript bundle for offline use',
' new-library: generates a native library bridge'
].join('\n'));
process.exit(1);
}
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);
}
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;
case 'install':
install.init();
break;
case 'bundle':
bundle.init(args);
break;
case 'new-library':
newLibrary.init(args);
break;
case 'init':
printInitWarning();
break;
default:
console.error('Command `%s` unrecognized', args[0]);
printUsage();
}
// Here goes any cli commands we need to
}
if (require.main === module) {
run();
}
module.exports = {
run: run,
init: init,
};