This repository has been archived by the owner on Mar 22, 2021. It is now read-only.
forked from huggingface/Mongoku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.ts
62 lines (52 loc) · 1.73 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
#!/usr/bin/env node
import * as child_process from 'child_process';
import * as path from 'path';
import * as program from 'commander';
import * as figlet from 'figlet';
import chalk from 'chalk';
import * as server from './server';
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.hsl(216, 25, 75)(figlet.textSync('Mongoku')));
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
return 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/");
}
});
}
if (forever) {
// Start for forever
return 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/");
}
});
}
await server.start();
}