This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·143 lines (97 loc) · 3.1 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env node
const program = require('commander');
const {version} = require('./package.json');
const setup = require('./setup');
const style = require('./styles');
const shell = require('./shell');
const plugins = require('./plugins');
const lifecycle = require('./lifecycle');
const serverConfig = require('./config-server');
const cliConfig = require('./config-cli');
// wrapper for cli actions. Provides more useful error info.
function helpful (fn) {
return async function (...args) {
try {
await fn(...args);
} catch (e) {
console.error(`
${style.bad('Something Went Wrong!')}
${style.info('If you ask for help, be sure to provide the following details:')}
CLI version: ${version}
Command run: ${program.rawArgs}
Error:
${e}
`);
}
}
}
program.version(version);
program.command('setup')
.description('setup a Corsica server')
.action(helpful(async function () {
console.log(style.info('\nSetting up Corsica...\n'));
await setup();
console.log(style.good('Done!'));
}));
program.command('start')
.description('start the Corsica server')
.option('-b, --background', 'run Corsica in the background')
.action(helpful(async function (options) {
if (options.background) {
await lifecycle.startInBackground();
} else {
await lifecycle.start();
console.log(style.info('Press Ctrl+C to exit.'));
}
}));
program.command('restart')
.description('restart the Corsica server')
.option('-b, --background', 'run Corsica in the background')
.action(helpful(async function (options) {
await lifecycle.stop();
if (options.background) {
await lifecycle.startInBackground();
} else {
await lifecycle.start();
console.log(style.info('Press Ctrl+C to exit.'));
}
}));
program.command('stop')
.description('stop a running Corsica server')
.action(helpful(async function () {
await lifecycle.stop();
console.log(style.good('Done!'));
}));
program.command('add-plugin [name]')
.description('install a plugin')
.action(helpful(async function (name) {
console.log(style.info(`Installing ${name}...\n`));
await plugins.install(name);
console.log(style.good('Done!'));
}));
program.command('remove-plugin [name]')
.description('remove an installed plugin')
.action(helpful(async function (name) {
await plugins.remove(name);
console.log(style.good('Done!'));
}));
program.command('list-plugins')
.description('list installed plugins')
.action(helpful(async function () {
await plugins.list();
}));
program.command('update')
.description('update Corsica and its plugins')
.action(helpful(async function () {
let { installPath } = await cliConfig.get();
console.log(style.info('Updating Corsica and plugins...'));
await shell('npm', ['update'], { cwd: installPath });
console.log(style.info('Updating corsica-cli...'));
await shell('npm', ['install', '-g', 'corsica-cli']);
console.log(style.good('Done!'));
}));
program.parse(process.argv);
if (program.args.length === 0) {
program.outputHelp();
process.stdout.write('\n');
}