loaders_wpw-task-loader_lib_task.js

/**
 * @file loaders/wpw-jsdoc-loader/lib/jsdoc.js
 * @copyright @spmhome @_2025
 * @author Scott Meesseman @spmeesseman
 *
 *//** */

const { urlToRequest } = require("loader-utils");
const { SpmhSchema } = require("@spmhome/app-utils");


/** @type {WpwLogger} */
// let logger;

/** @type {SpmhJsonSchema} */
const schema = {
    type: "object",
    properties: {
        test: {
            type: "string"
        },
        options: {
            type: "object",
            // required: [
            //     "config", "ext", "inputDir", "outDir", "virtualFile"
            // ],
            properties: {
                build: {
                    type: "object"
                },
                input: {
                    type: "string"
                },
                output: {
                    type: "string"
                },
                vFile: {
                    type: "string"
                }
            }
        }
    }
};


/**
 * @param {WebpackLoaderContext} ctx
 * @param {string} source
 * @param {any} map
 * @param {any} meta
 * @returns {Promise<WpwLoaderResult>}
 */
async function taskLoader(ctx, source, map, meta)
{
    const loaderOpts = ctx.getOptions(),
          taskOpts = loaderOpts.options,
          build = /** @type {WpwBuild | undefined} */(taskOpts.build),
          logger = /** @type {WpwLogger | undefined} */(build?.logger),
          resourcePath = urlToRequest(this.resourcePath).replace(/\\/g, "/");

    // if (!logger) {
    //     logger = WpwLogger.getLoggerInst({
    //         envTag1: "task-loader", envTag2: "wpw", level: options.logLevel || 2, color: build?.logger?.color || "spmh_blue"
    //     });
    // }
    // else {
    if (logger) {
        logger.value("process task-loader request", resourcePath, 1, "", 0, 0, [ "loader", "task" ]);
        logger.value("process task-loader request", resourcePath, 1, "", 0, 0, [ "loader", "task" ]);
    }
    // }

    new SpmhSchema("WpwSchema", "schema/spmh.wpw.schema.json").validate(taskOpts, schema, logger, "   ");

    // // context.clearDependencies();
    // /** @typedef {{ input: string }} ScriptDef */
    // /** @type {{ scripts: ScriptDef[] }|undefined} */
    // const cfg = options.config;
    // const scripts = cfg?.scripts;
    // if (scripts)
    // {
    //     for (const script of scripts)
    //     {
    //         for (const path of asArray(script.input))
    //         {s
    //             let files;
    //             if (isDirectory(path)) {
    //                 files =  (await findFiles("**/*.*", { absolute: false, cwd: this.rootContext }))
    //                          .map(f => forwardSlash(f));
    //             }
    //             else {
    //                 files = [ relativePath(this.rootContext, path, { psx: true }) ];
    //             }
    //             for (const file of files) {
    //                 // const absFile = resolve(this.rootContext, file);
    //                 // context.addDependency(absFile);
    //                 // context.addBuildDependency(absFile);
    //                 // context.addContextDependency(dirname(absFile));
    //                 context._compilation?.fileDependencies.add(file);
    //                 logger.log("   add dependency " + file);
    //             }
    //         };
    //     }
    // }

    return [ source, map, meta ];

    // const resourcePath = loaderUtils.urlToRequest(this.resourcePath),
    //       resourcePathRel = posix.normalize(relativePath(options.outDir, resourcePath));
    // return `export default ${JSON.stringify(results)}`;
    // return [ data ]; //  new RawSource(data);
    // return [ source, map, meta ];
}


module.exports = taskLoader;