UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

39 lines (38 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.magicImport = exports.loadFiles = void 0; const promises_1 = require("fs/promises"); const path_1 = require("path"); /** * Load all files from a directory. * @param dirPath The path of the directory to load the files from. * @returns The loaded files. * @internal */ async function loadFiles(dirPath) { const files = []; const dir = await (0, promises_1.readdir)(dirPath); for (const content of dir) { const path = (0, path_1.join)(dirPath, content); const data = await (0, promises_1.stat)(path); if (data.isDirectory()) { const loadedFiles = await loadFiles(path); files.push(...loadedFiles); } else { const fileData = await magicImport(path); files.push(fileData); } } return files; } exports.loadFiles = loadFiles; async function magicImport(path) { try { return require(path); } catch { return eval('((path) => import(`file:///${path}?update=${Date.now()}`))')(path.split('\\').join('\\\\')); } } exports.magicImport = magicImport;