1
0
Fork 0
mirror of https://github.com/ChomeNS/chomens-bot-mc.git synced 2025-07-24 12:48:53 -04:00
chomens-bot-js/util/load_files.js

26 lines
546 B
JavaScript
Raw Normal View History

2022-11-27 14:35:28 +07:00
const fs = require('fs/promises')
const path = require('path')
2022-08-14 16:51:45 +07:00
2022-11-16 09:33:16 +07:00
/**
* loads js files
* @param {string} directory the directory that contains the js files
* @return {Array} an array of require()ed js files
*/
2022-11-27 14:35:28 +07:00
async function loadPlugins (directory) {
const plugins = []
2022-08-14 16:51:45 +07:00
2022-11-27 08:40:10 +07:00
for (const filename of await fs.readdir(directory)) {
2022-11-27 14:35:28 +07:00
if (!filename.endsWith('.js')) continue
2022-08-14 16:51:45 +07:00
2022-11-27 14:35:28 +07:00
const filepath = path.join(directory, filename)
2022-08-14 16:51:45 +07:00
2022-11-27 14:35:28 +07:00
const plugin = require(filepath)
2022-08-14 16:51:45 +07:00
2022-11-27 14:35:28 +07:00
plugins.push(plugin)
2022-08-14 16:51:45 +07:00
}
2022-11-27 14:35:28 +07:00
return plugins
2022-08-14 16:51:45 +07:00
}
2022-11-27 14:35:28 +07:00
module.exports = loadPlugins