-
Notifications
You must be signed in to change notification settings - Fork 87
/
cli.ts
65 lines (55 loc) · 1.79 KB
/
cli.ts
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
#!/usr/bin/env node
import * as child_process from 'child_process';
import * as path from 'path';
import { createCommand } from 'commander';
import * as figlet from 'figlet';
import chalk from 'chalk';
import * as server from './server';
const program = createCommand();
program
.version(require('../package.json').version)
.usage('start [--pm2] [--forever]')
.description('MongoDB client for the web')
.option('--pm2', 'Run using pm2')
.option('--forever', 'Run using forever')
.action(start)
.parse(process.argv);
async function start(cmd: 'start', options: any) {
console.log(chalk.rgb(175, 188, 207)(figlet.textSync('Mongoku')) + '\n');
if (cmd !== "start") {
return program.help();
}
const pm2 = options.pm2;
const forever = options.forever;
const entryPath = path.join(__dirname, 'server.js');
if (pm2 && forever) {
console.log("Cannot launch with both PM2 and Forever. You need to chose one.");
console.log("Use 'mongoku --help' for more info");
process.exit(1);
}
if (pm2) {
// Start for pm2
child_process.exec(`pm2 start --name mongoku ${entryPath}`, (err, stdout, stderr) => {
if (err) {
console.log("Error while launching with pm2: ", err);
} else {
console.log(stdout, stderr);
console.log("[Mongoku] Launched with PM2.\nAvailable at http://localhost:3100/");
}
});
return;
}
if (forever) {
// Start for forever
child_process.exec(`forever --uid mongoku start -a ${entryPath}`, (err, stdout, stderr) => {
if (err) {
console.log("Error while launching with forever: ", err);
} else {
console.log(stdout, stderr);
console.log("[Mongoku] Launched with forever.\nAvailable at http://localhost:3100/");
}
});
return;
}
await server.start();
}