2022-02-15 04:33:19 +01:00
|
|
|
const watchers = require('./libs/watchers.js');
|
2022-02-18 01:33:57 +01:00
|
|
|
const util = require('./libs/util.js');
|
2022-02-15 04:33:19 +01:00
|
|
|
const logger = require('./libs/logger.js');
|
|
|
|
const packageJSON = require('./package.json');
|
|
|
|
|
2022-02-16 03:28:17 +01:00
|
|
|
const INTERRUPTS = ['SIGINT', 'SIGTERM'];
|
|
|
|
|
|
|
|
logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...');
|
|
|
|
|
|
|
|
handleInterrupts();
|
2022-02-15 04:33:19 +01:00
|
|
|
|
2022-02-19 02:28:37 +01:00
|
|
|
const config = process.argv[2] || __dirname + '/config.json';
|
2022-02-18 01:33:57 +01:00
|
|
|
|
|
|
|
util.fileExists(config)
|
|
|
|
.then(watchers.initialize)
|
2022-02-15 04:33:19 +01:00
|
|
|
.then(watchers.start)
|
|
|
|
.catch((err) => {
|
|
|
|
logger.error(err);
|
2022-02-16 03:28:17 +01:00
|
|
|
exit(1);
|
2022-02-15 04:33:19 +01:00
|
|
|
});
|
2022-02-16 03:28:17 +01:00
|
|
|
|
|
|
|
function exit(code) {
|
|
|
|
code = code || 0;
|
|
|
|
logger.info(packageJSON.name + ' ' + packageJSON.version + ' exiting with code \'' + code + '\'...');
|
|
|
|
process.exit(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleInterrupts() {
|
|
|
|
for (var index = 0; index < INTERRUPTS.length; index++) {
|
|
|
|
process.once(INTERRUPTS[index], (code) => {
|
|
|
|
watchers.stop()
|
|
|
|
.then(exit(code))
|
|
|
|
.catch(exit(code));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|