X-Git-Url: https://git.r.bdr.sh/rbdr/corona-regeln/blobdiff_plain/07d8db2bb758686466d4643f575b4b5280cc4791..10129c006c73d9667a4eb2b45bf0aae7e6cdecdb:/lib/rule_generator.js?ds=inline diff --git a/lib/rule_generator.js b/lib/rule_generator.js index 5db5240..742c915 100644 --- a/lib/rule_generator.js +++ b/lib/rule_generator.js @@ -1,4 +1,4 @@ -const { readdir } = require('fs/promises'); +const { readdir } = require('fs'); const { join, resolve } = require('path'); const internals = { @@ -18,16 +18,30 @@ const internals = { rules: null, currentIndex: 0, - kRulesDirectory: resolve(process.cwd(), 'rules'), + kRulesDirectory: resolve(__dirname, './rules'), async readRules() { - const ruleFiles = await readdir(internals.kRulesDirectory); + const ruleFiles = await internals.readdir(internals.kRulesDirectory); const rules = ruleFiles .filter((file) => file.match(/.js$/)) .map((file) => require(join(internals.kRulesDirectory, file))); internals.rules = rules.sort(() => Math.random() - 0.5) + }, + + readdir(path) { + return new Promise((resolve, reject) => { + + readdir(path, (err, files) => { + + if (err) { + return reject(err); + } + + return resolve(files); + }) + }); } }