Skip to content

Commit

Permalink
[New] exported global findAndRequire function to loop through command…
Browse files Browse the repository at this point in the history
…s folders and require them
  • Loading branch information
naseif committed Sep 2, 2021
1 parent 8098f82 commit e4b6039
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/loopAndRequireCommands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require("fs");

module.exports.findAndRequire = (inputPath, extension, collection) => {
const files = fs
.readdirSync(inputPath)
.filter((command) => command.endsWith(extension));

for (const f of files) {
const command = require(`../${inputPath}/${f}`);
collection.set(command.data.name, command);
}
};

0 comments on commit e4b6039

Please sign in to comment.