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
|
|
|
let config;
|
2022-02-16 03:28:17 +01:00
|
|
|
|
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');
|
|
|
|
config = require(configFile.path);
|
|
|
|
config.path = config.path;
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
logger.initialize(config.log.level, config.log.timestamp);
|
|
|
|
logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...');
|
|
|
|
await watchers.initialize(config.watchers);
|
|
|
|
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);
|
|
|
|
}
|