function generateTaskByProcessors()

in core/index.js [106:154]


function generateTaskByProcessors(taskDef, targetConfig) {
    if (!Array.isArray(taskDef.processors)) {
        throw new Error("taskDef.processors (Array<string>) must be provided.");
    }

    return () => {
        /** @type {NodeJS.ReadWriteStream} */
        let lastProcessor;

        const base = (taskDef.base || path.resolve("."))
            .replace(globUtils.Regex.PathRef, (match, pathName) => configs.buildInfos.paths[pathName]);

        lastProcessor =
            gulp.src(taskDef.sources ? globUtils.toGlobs(taskDef.sources) : globUtils.normalizeGlobs("**/*"), { dot: true, base: base });

        for (const processorRef of taskDef.processors) {
            /** @type {string} */
            let processorName;

            if (utils.isString(processorRef)) {
                processorName = processorRef;
            } else {
                processorName = processorRef.name;
            }

            if (!utils.isString(processorName) || utils.string.isEmptyOrWhitespace(processorName)) {
                throw new Error("processor name must be provided. (null/undefined/empty/whitespaces are not acceptable).");
            }

            /** @type {*} */
            const processorConfig = Object.assign(Object.create(null), configs.buildInfos.configs.processors[processorName], utils.isString(processorRef) ? null : processorRef);

            /** @type {ProcessorConstructor} */
            const constructProcessor = processorDictionary[processorName];

            if (!constructProcessor) {
                throw new Error(`Unknown processor: ${processorName}`);
            }

            lastProcessor =
                lastProcessor.pipe(constructProcessor(processorConfig, targetConfig, configs.buildInfos, configs.packageJson));
        }

        const dest = (taskDef.dest || configs.buildInfos.paths.buildDir)
            .replace(globUtils.Regex.PathRef, (match, pathName) => configs.buildInfos.paths[pathName]);

        return lastProcessor.pipe(gulp.dest(dest, { overwrite: true }));
    }
}