ext/ExtensionManager.js

"use strict";
// ExtensionManager.ts - Extension manager (noud02)
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const rreaddirSync = require("recursive-readdir-sync");
/**
 * Extension manager class
 *
 * @export
 * @class ExtensionManager
 */
class ExtensionManager {
    constructor(options) {
        this.options = options;
        /**
         * Map of commands
         *
         * @type {Map<string, Command>}
         */
        this.commands = new Map();
    }
    /**
     * Initializes the extension manager
     *
     * @returns {Promise<void>}
     */
    init() {
        let files = [];
        try {
            files = rreaddirSync(path.resolve(this.options.extensionDir));
        }
        catch (e) {
            return Promise.reject(e);
        }
        for (const file of files) {
            if (!file.endsWith(".js")) {
                continue;
            }
            const Ext = require(file);
            this.commands.set(Ext.prototype.name, new Ext());
            delete require.cache[require.resolve(file)];
        }
        return Promise.resolve();
    }
}
exports.ExtensionManager = ExtensionManager;