-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·71 lines (61 loc) · 1.59 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
#!/usr/bin/env node
(require('dotenv')).config();
const yargs = require('yargs/yargs')
const {
hideBin
} = require('yargs/helpers')
const {
version
} = require('./package.json');
const prompts = require('prompts');
const path = require('path');
const kleur = require('kleur');
const argv = yargs(hideBin(process.argv)).argv
if (argv.debug) {
console.log(kleur.yellow().underline('Debugging is ON'));
}
process.env.SERVER_ROOT = (argv.debug) ? path.join(__dirname, 'fakeServer') : '/';
const helpers = require('./helpers');
const actions = require('./actions');
const chooseAction = (choices) => {
return new Promise((resolve, reject) => {
prompts({
type: 'select',
name: 'action',
message: 'Which action do you want to perform',
choices,
initial: 1,
}, {
onSubmit: (prompt, answer) => {
resolve(prompt.choices.find(({
value
}) => value == answer));
},
onCancel: process.exit
});
})
}
(async () => {
console.clear();
console.log(`================================`);
console.log(kleur.italic().bold('Ezyo Server Manager'));
console.log(kleur.italic().dim(`v${version}`));
console.log(`================================`);
if (argv.action) {
const action = actions.find(({
value
}) => value == argv.action);
if (action) {
prompts.override(argv);
await action.execute();
prompts.override({}) // Clear prefilled answers
}
}
while (true) {
console.log('\n');
const action = await chooseAction(actions);
if (action) {
await action.execute();
}
}
})();