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 = {
fileExists,
resolvePath

View file

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

View file

@ -1,4 +1,5 @@
const watchers = require('./libs/watchers.js');
const util = require('./libs/util.js');
const logger = require('./libs/logger.js');
const packageJSON = require('./package.json');
@ -8,7 +9,14 @@ logger.info(packageJSON.name + ' ' + packageJSON.version + ' starting...');
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)
.catch((err) => {
logger.error(err);