const watchers = require('./libs/watchers.js'); const util = require('./libs/util.js'); const logger = require('./libs/logger.js'); const packageJSON = require('./package.json'); const INTERRUPTS = ['SIGINT', 'SIGTERM']; main(); async function main() { handleInterrupts(); try { let configFile = await util.getFileInfo(process.argv[2] || __dirname + '/config.json'); global.config = require(configFile.path); global.config.path = configFile.path; } catch (err) { console.error(err); process.exit(1); } try { logger.initialize(global.config.log.level, global.config.log.timestamp); logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...'); await watchers.initialize(global.config.watchers); await watchers.start(); } catch (err) { logger.error(err); exit(1); } } function handleInterrupts() { for (var index = 0; index < INTERRUPTS.length; index++) { process.on(INTERRUPTS[index], (code) => { exit(code); watchers.stop() .then(exit(code)) .catch(exit(code)); }); } } function exit(code) { code = code || 0; logger.info(packageJSON.name + ' ' + packageJSON.version + ' exiting with code \'' + code + '\'...'); process.exit(code); }