changed stuff to define config via cli argument

This commit is contained in:
Daniel Sommer 2022-02-18 01:33:57 +01:00
parent 1a994010f5
commit fd26fbe75d
3 changed files with 18 additions and 14 deletions

View file

@ -30,13 +30,6 @@ function resolvePath(file) {
}); });
} }
function executeCommand(command) {
if (command == undefined) {
return;
}
command = command.trim();
}
module.exports = { module.exports = {
fileExists, fileExists,
resolvePath resolvePath

View file

@ -1,17 +1,20 @@
const configJSON = require('../config.json');
const logger = require('./logger.js'); const logger = require('./logger.js');
const Watcher = require('./watcher.js'); const Watcher = require('./watcher.js');
const watchers = []; const watchers = [];
function initialize() { function initialize(config) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
if (configJSON == undefined || configJSON.watchers == undefined || configJSON.watchers.length == 0) { if (config == undefined || config.path == undefined) {
reject('no watchers in \'config.json\' defined'); reject('no config defined');
}
config = require(config.path);
if (config.watchers == undefined || config.watchers.length == 0) {
reject('no watchers in config defined');
} }
var tmp = [] var tmp = []
for (var index = 0; index < configJSON.watchers.length; index++) { for (var index = 0; index < config.watchers.length; index++) {
tmp.push(new Watcher(configJSON.watchers[index], watcherCallback)); tmp.push(new Watcher(config.watchers[index], watcherCallback));
} }
Promise.all(tmp.map(check)) Promise.all(tmp.map(check))
.then(resolve) .then(resolve)

View file

@ -1,4 +1,5 @@
const watchers = require('./libs/watchers.js'); const watchers = require('./libs/watchers.js');
const util = require('./libs/util.js');
const logger = require('./libs/logger.js'); const logger = require('./libs/logger.js');
const packageJSON = require('./package.json'); const packageJSON = require('./package.json');
@ -8,7 +9,14 @@ logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...');
handleInterrupts(); handleInterrupts();
watchers.initialize() const config = process.argv[2] || './config.json';
util.fileExists(config)
.catch((err) => {
logger.error(err);
exit(1);
})
.then(watchers.initialize)
.then(watchers.start) .then(watchers.start)
.catch((err) => { .catch((err) => {
logger.error(err); logger.error(err);