UNPKG

typedoc-plugin-merge-modules

Version:
56 lines (55 loc) 1.89 kB
import { getModulesFrom } from "../utils.js"; import { ModuleBundle } from "./module_bundle.js"; /** * Merger that merges the content of modules based on their JSDoc module annotation. */ export class ModuleMerger { /** The project whose modules are merged. */ project; /** The plugin which is using this merger. */ plugin; /** * Creates a new merger instance. * @param project The project whose modules are merged. * @param plugin The plugin which is using this merger. */ constructor(project, plugin) { this.project = project; this.plugin = plugin; } /** * Performs the merging routine. */ execute() { const moduleBundles = this.createModuleBundles(); moduleBundles.forEach((bundle) => { bundle.merge(this.plugin.runsAfterCategorization); }); } /** * Creates an identifier for the module's bundle. * @param module The module for which the identifier is generated. * @returns The identifier for the module's bundle. */ // eslint-disable-next-line class-methods-use-this createModuleBundleId(module) { return module.name; } /** * Creates an object describing which modules of the project should be merged. * @returns The collection of module bundles. */ createModuleBundles() { const modules = getModulesFrom(this.project); const moduleBundleMap = new Map(); // Create bundles for modules that have the same ID for (const module of modules) { const bundleId = this.createModuleBundleId(module); if (!moduleBundleMap.has(bundleId)) { moduleBundleMap.set(bundleId, new ModuleBundle(this.project)); } moduleBundleMap.get(bundleId)?.add(module); } return [...moduleBundleMap.values()]; } }