-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
78 lines (70 loc) · 1.83 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
77
const pkgJson = require('./package')
const utils = require('./utils')
const logger = require('./utils/logger')
const options = require('minimist')(process.argv.slice(2));
// Options
const commands = options._;
if(commands.length === 0) {
// Print Version
if (options.i || options.info) {
utils.printSystemInfoAndExit();
} else if(options.v || options.version) {
utils.printVersionsAndExit(pkgJson.version);
} else if(options.h || options.help) {
utils.printHelpAndExit()
} else if(options.g || options.graffiti) {
utils.printGraffitiAndExit();
} else {
utils.printInvalidAndExit();
}
} else {
switch (commands[0]) {
case 'init':
if (!commands[1]) {
logger.error('Usage: react-native-hooks init <ProjectName> [--verbose]');
process.exit(1);
} else {
init(commands[1], options);
}
break;
default:
logger.error(
'Command `%s` unrecognized. '
);
process.exit(1);
break;
}
}
/**
* @param name Project name, e.g. 'AwesomeReactNativeHook'.
* @param options
* @param options.verbose If true, will run 'npm install' in verbose mode (for debugging).
*/
function init(name, options) {
utils.validateProjectName(name);
if (fs.existsSync(name)) {
initAfterConfirm(name, options);
} else {
initProject(name, options);
}
}
function initAfterConfirm (name, options) {
prompt.start();
const property = {
name: 'yesno',
message: `Directory ${name} already exists. Continue?`,
validator: /y[es]*|n[o]?/,
warning: 'Must respond yes or no',
default: 'no',
};
prompt.get(property, (err, result) => {
if (result.yesno[0] === 'y') {
initProject(name, options);
} else {
console.log('Project initialization canceled');
process.exit();
}
});
}
function initProject(name, options) {
}