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'];
|
|
|
|
|
2022-03-10 12:29:41 +01:00
|
|
|
main();
|
2022-02-15 04:33:19 +01:00
|
|
|
|
2022-03-10 12:29:41 +01:00
|
|
|
async function main() {
|
|
|
|
handleInterrupts();
|
|
|
|
try {
|
|
|
|
let configFile = await util.getFileInfo(process.argv[2] || __dirname + '/config.json');
|
2022-03-28 16:08:33 +02:00
|
|
|
global.config = require(configFile.path);
|
|
|
|
global.config.path = configFile.path;
|
2022-03-10 12:29:41 +01:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
try {
|
2022-03-28 16:08:33 +02:00
|
|
|
logger.initialize(global.config.log.level, global.config.log.timestamp);
|
2022-03-10 12:29:41 +01:00
|
|
|
logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...');
|
2022-03-28 16:08:33 +02:00
|
|
|
await watchers.initialize(global.config.watchers);
|
2022-03-10 12:29:41 +01:00
|
|
|
await watchers.start();
|
|
|
|
} catch (err) {
|
2022-02-15 04:33:19 +01:00
|
|
|
logger.error(err);
|
2022-02-16 03:28:17 +01:00
|
|
|
exit(1);
|
2022-03-10 12:29:41 +01:00
|
|
|
}
|
2022-02-16 03:28:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleInterrupts() {
|
|
|
|
for (var index = 0; index < INTERRUPTS.length; index++) {
|
2022-03-10 12:29:41 +01:00
|
|
|
process.on(INTERRUPTS[index], (code) => {
|
|
|
|
exit(code);
|
2022-02-16 03:28:17 +01:00
|
|
|
watchers.stop()
|
|
|
|
.then(exit(code))
|
|
|
|
.catch(exit(code));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-03-10 12:29:41 +01:00
|
|
|
|
|
|
|
function exit(code) {
|
|
|
|
code = code || 0;
|
|
|
|
logger.info(packageJSON.name + ' ' + packageJSON.version + ' exiting with code \'' + code + '\'...');
|
|
|
|
process.exit(code);
|
|
|
|
}
|