From fd26fbe75df9f98ad68bea95abc91276141f9b01 Mon Sep 17 00:00:00 2001 From: velvettear Date: Fri, 18 Feb 2022 01:33:57 +0100 Subject: [PATCH] changed stuff to define config via cli argument --- libs/util.js | 7 ------- libs/watchers.js | 15 +++++++++------ ninwa.js | 10 +++++++++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/libs/util.js b/libs/util.js index 3977a06..01788f4 100644 --- a/libs/util.js +++ b/libs/util.js @@ -30,13 +30,6 @@ function resolvePath(file) { }); } -function executeCommand(command) { - if (command == undefined) { - return; - } - command = command.trim(); -} - module.exports = { fileExists, resolvePath diff --git a/libs/watchers.js b/libs/watchers.js index 5b3f2e8..0ffd5c6 100644 --- a/libs/watchers.js +++ b/libs/watchers.js @@ -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) diff --git a/ninwa.js b/ninwa.js index 7602e58..020d346 100644 --- a/ninwa.js +++ b/ninwa.js @@ -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);