-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.js
69 lines (64 loc) · 2.12 KB
/
events.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
import 'colors';
import nodemon from 'nodemon';
import fs from 'fs';
import dotEnv from 'dotEnv';
dotEnv.config();
import childProcess from 'child_process';
const { exec } = childProcess;
import input from 'input';
//files
const props = JSON.parse(fs.readFileSync('./props/default.json'));
//props
const consoleTxtColor =
props.consoleTxtColor == null || props.consoleTxtColor === ''
? 'cyan'
: props.consoleTxtColor;
const consoleVarColor =
props.consoleVarColor == null || props.consoleVarColor === ''
? 'green'
: props.consoleVarColor;
const consoleAlertColor =
props.consoleAlertColor == null || props.consoleAlertColor === ''
? 'white'
: props.consoleAlertColor;
const consoleErrorColor =
props.consoleErrorColor == null || props.consoleErrorColor === ''
? 'red'
: props.consoleErrorColor;
const logEvents = props.logEvents == null ? true : props.logEvents;
const logRestartCause =
props.logRestartCause == null ? true : props.logRestartCause;
const openTabOnStart =
props.openTabOnStart == null ? true : props.openTabOnStart;
const isDev = process.env.ISDEV === 'true' ? true : false;
const port = isDev ? props.port : process.env.PORT;
nodemon({ script: './app.js' })
.on('crash', () => {
if (logEvents)
console.log(`Better Express server has crashed`[consoleErrorColor]);
})
.on('quit', () => {
nodemon.emit('quit');
if (logEvents) console.log(`App has quit`[consoleErrorColor]);
})
.on('restart', (files) => {
if (logEvents === true)
console.log(`Restarting Better Express Server`[consoleTxtColor]);
if (logRestartCause)
console.log(`Server restarted due to: ${files}`[consoleAlertColor]);
});
if (openTabOnStart) {
if (process.platform === 'win32') {
exec(`explorer \"http://localhost:${port}\"`, (err) => {
if (err) {
console.error(err);
}
});
} else {
exec(`open \"http://localhost:${port}\"`, (err) => {
if (err) {
console.error(err);
}
});
}
}