plugins_resource.js

/**
 * @file plugins/resource.js
 * @copyright @spmhome @_2025
 * @author Scott Meesseman @spmeesseman
 *//** */

const WpwTaskPlugin = require("./basetask");


/**
 * @augments WpwTaskPlugin
 * @example Replace 'NewPluginName' with a name that will match the rc setting, e.g. WpwSchemaPlugin would
 * have an options key of 'schema' in the rc config file.
 */
class WpwResourcePlugin extends WpwTaskPlugin
{
    /**
     * @param {WpwPluginOptions} options
     */
    constructor(options)
    {
        super("resource", { taskHandler: "executeStaticResourceBuild", ...options });
        this.buildOptions = /** @type {WpwBuildOptionsPluginConfig<"resource">} */(this.buildOptions); // reset for typings
    }

    /**
     * @override
     */
    static create = WpwResourcePlugin.wrap.bind(this);


    /**
	 * @returns {Promise<WpwPluginTaskResult | SpmhError>}
     */
    async executeStaticResourceBuild()
    {
		// let tct = 0;
		const // b = this.build,
		      // l = b.logger,
			  bo = this.buildOptions,
			  assets = bo.assets || { immutable: false }
		try
		{
            // if (bo.)
           // for (const i of bo.items)
			// {   if (this._fs_.isDirectory(i.input))
			// 	{
			// 		tct += await this._fs_.copyDirAsync(i.input, i.output);
			// 	}
			// 	else
			// 	{   await this._fs_.copyFileAsync(i.input, i.output);
			// 		tct += 1;
			// 	}
			// }
			// l.write(`${tct} total files processed`, 1);
            return {
                tag: assets.tag,
                glob: assets.glob,
                immutable: !!assets.immutable,
                paths: this._arr_.asArray(bo.output),
                srcpaths: this._arr_.asArray(bo.input)
            };
		}
		catch (e)
		{   this.addMessage(
            {   exception: e,
                code: this.MsgCode.ERROR_PLUGIN_HOOK_FAILED,
                message: "failed to execute 'resource' type build"
            }, true);
		}
    }
}


module.exports = WpwResourcePlugin.create;