-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
executable file
·40 lines (38 loc) · 1.33 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
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const consola = require('consola');
const chalk = require('chalk');
const nodemon = require('nodemon');
const boxen = require('boxen');
const jsonGui = require('./server/json-gui');
const config = require('./server/config');
const log = {
info: (message) => consola.info(chalk.bold('JSON GUI'), message),
success: (message) => consola.success(chalk.bold('JSON GUI'), message),
warn: (message) => consola.warn(chalk.bold('JSON GUI'), message),
error: (message) => consola.error(chalk.bold('JSON GUI:'), message)
};
Promise.all([jsonGui(), nodemon({
script: require.resolve('./server/json-server.js'),
watch: !config.watch ? false : `${config.baseDir}/db.json`
})]).then(() => {
const greeting = chalk.white(chalk.yellow.bold('Firing up JSON GUI 🔥🔥') + '\n\nRunning at ' + chalk.blue.underline(`http://localhost:${config.port}`));
const boxenOptions = {
borderColor: 'yellow',
padding: 1,
margin: {
top: 1,
bottom: 1
}
};
const msgBox = boxen(greeting, boxenOptions);
console.log(msgBox);
log.info('Type s + enter at any time to create a snapshot of the database');
if (config.watch) {
log.info('Watching for changes...');
}
}).catch((error) => {
console.log(error);
log.error(chalk.red(error));
process.exit();
});