/**
* @file exports/plugins.js
* @copyright @spmhome @_2025
* @author Scott Meesseman @spmeesseman
*//** */
const plugins = require("../plugins");
const WpwWebpackExport = require("./base");
// const xPlugins = require(".").webpackExportPlugins;
const { isWpwBuildOptionsGroupKey } = require("../utils");
/**
* @augments WpwWebpackExport
*/
class WpwPluginsExport extends WpwWebpackExport
{
/**
* @param {WpwExportOptions} options Plugin options to be applied
*/
constructor(options)
{
super(options);
}
/**
* @override
*/
static create = WpwPluginsExport.wrap.bind(this);
/**
* @private
* @param {WpwBuild} build
* @param {string | null} gName
* @param {string} pName
*/
addPlugin(build, gName, pName)
{
let enabled, pCreateFn;
if (!gName)
{
pCreateFn = plugins[pName];
enabled = this._types_.isDefined(build.options[pName]) && this._obj_.asObject(build.options[pName]).enabled;
}
else
{ pCreateFn = plugins[gName][pName];
enabled = this._types_.isDefined(build.options[gName]) && this._obj_.asObject(build.options[gName]).enabled &&
this._types_.isDefined(build.options[gName][pName]) && this._obj_.asObject(build.options[gName][pName]).enabled;
}
if (enabled && pCreateFn)
{
const pInst = pCreateFn(build);
if (pInst)
{
build.logger.write(` add plugin '${pName}'`, 2);
build.wpc.plugins.push(pInst);
}
}
}
/**
* @override
* @param {WpwBuild} build
*/
create(build)
{
build.logger.write("configure required plugins", 1);
Object.keys(plugins).forEach((p) =>
{ if (!isWpwBuildOptionsGroupKey(p))
{
this.addPlugin(build, null, p);
}
else {
Object.keys(plugins[p]).forEach((gp) => this.addPlugin(build, p, gp), this);
}
});
const pluginCt = build.wpc.plugins.length;
build.logger.write(` configured ${pluginCt} ${this._str_.pluralize("plugin", pluginCt)}`, 1);
// Object.keys(xPlugins).forEach((p) => { this.addPlugin(build, p, xPlugins[p]); });
// pluginCt = build.wpc.plugins.length - pluginCt;
// build.logger.write(` configured ${pluginCt} ${this._str_.pluralize("plugin", pluginCt)}`, 1);
// pluginCt = build.wpc.plugins.length;
// build.logger.write(` configured ${pluginCt} total ${this._str_.pluralize("plugin", pluginCt)}`, 1);
build.logger.write("plugin configuration completed successfully", 1);
};
};
module.exports = WpwPluginsExport.create;