2022-11-08 05:43:24 -05:00
|
|
|
const fs = require('fs');
|
|
|
|
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-08 05:43:24 -05:00
|
|
|
function loadPlugins(directory) {
|
|
|
|
const plugins = [];
|
2022-08-14 05:51:45 -04:00
|
|
|
|
|
|
|
for (const filename of fs.readdirSync(directory)) {
|
2022-11-08 05:43:24 -05:00
|
|
|
if (!filename.endsWith('.js')) continue;
|
2022-08-14 05:51:45 -04:00
|
|
|
|
2022-11-08 05:43:24 -05:00
|
|
|
const filepath = path.join(directory, filename);
|
2022-08-14 05:51:45 -04:00
|
|
|
|
2022-11-08 05:43:24 -05:00
|
|
|
const plugin = require(filepath);
|
2022-08-14 05:51:45 -04:00
|
|
|
|
2022-11-08 05:43:24 -05:00
|
|
|
plugins.push(plugin);
|
2022-08-14 05:51:45 -04:00
|
|
|
}
|
|
|
|
|
2022-11-08 05:43:24 -05:00
|
|
|
return plugins;
|
2022-08-14 05:51:45 -04:00
|
|
|
}
|
|
|
|
|
2022-11-08 05:43:24 -05:00
|
|
|
module.exports = loadPlugins;
|