I'm trying to implement an abstraction layer over the Gulp API by allowing easy configuration over a dedicated file.
To sum it up, I have a function (builder) that requires that file (gulpconfig.js) and calls functions that return ReadableStreams from an object the config file exports with parallel().
Here's the gist (simplified from my private source).
However, when I do gulp build, it doesn't call the TestHandler function as it should. After debugging for a while, I have identified that everything (including variable assignments etc) work perfectly fine, but it just won't execute the returned parallel() instance.
How can I fix this behaviour?
Here are the code snippets from GitHub Gist:
gulpfile.js:
/* REQUIRES */
const { parallel } = require('gulp');
const user = require('./gulpconfig');
let params = {};
let fns = [];
async function builder() {
for (let [name, props] of Object.entries(user.config)) {
let fnName = name;
let fn = user[fnName];
let src = props.src;
let dest = props.dest;
params[fnName] = { src, dest };
fns.push(fn);
}
user.paramCp(params);
return parallel(...fns);
}
exports.build = builder;
gulpconfig.js:
/* REQUIRES */
const { src, dest, on, watch } = require('gulp');
const pipeline = require('readable-stream');
/* USER CONFIG */
exports.config = {
testHandler: {
src: "./input/*",
dest: "./output/",
},
};
/* LOCAL PARAM HANDLER. USED INTERNALLY. */
var params;
exports.paramCp = _params => {
params = _params;
};
var tSrc;
var tDest;
function getParams() {
let obj = params[getParams.caller.name];
tSrc = obj.src;
tDest = obj.dest;
}
/* HANDLERS. DEFINED BY handler KEY IN CONFIG */
exports.testHandler = function testHandler() {
getParams(); // You can now use tSrc and tDest
return pipeline(src(tSrc), dest(tDest));
};