chomens-bot-js/util/load_files.js

26 lines
546 B
JavaScript
Raw Permalink Normal View History

2022-11-27 02:35:28 -05:00
const fs = require('fs/promises')
const path = require('path')
2022-08-14 05:51:45 -04:00
2022-11-15 21:33:16 -05: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 02:35:28 -05:00
async function loadPlugins (directory) {
const plugins = []
2022-08-14 05:51:45 -04:00
2022-11-26 20:40:10 -05:00
for (const filename of await fs.readdir(directory)) {
2022-11-27 02:35:28 -05:00
if (!filename.endsWith('.js')) continue
2022-08-14 05:51:45 -04:00
2022-11-27 02:35:28 -05:00
const filepath = path.join(directory, filename)
2022-08-14 05:51:45 -04:00
2022-11-27 02:35:28 -05:00
const plugin = require(filepath)
2022-08-14 05:51:45 -04:00
2022-11-27 02:35:28 -05:00
plugins.push(plugin)
2022-08-14 05:51:45 -04:00
}
2022-11-27 02:35:28 -05:00
return plugins
2022-08-14 05:51:45 -04:00
}
2022-11-27 02:35:28 -05:00
module.exports = loadPlugins