Get path from currently processed file in Gulp and use it to set dynamic option in plugin
I'm trying to dynamically set the path where postcss-uncss looks for unused css, because this is a multi asset setup where folders hold assets for multiple domains / themes.
So I just want uncss to compare the html.twig templates in the current directory with the css in the current directory.
I have a function that returns the correct path, when I use parsePath() in the pipeline, and change the parsePath() function to return log(path.relative(...)). I assumed I would have to return the closure in the function though because according to documentation path.relative() returns a string, which is what I need. But it just won't work.
So to be clear, when Gulp processes the css files of let's say:
views/groups/group_1/page_1/v1/assets/css/app.css
I want uncss to look ONLY in:
views/groups/group_1/page_1/v1/**/*.html.twig
To figure out what css can be removed.
What I came up with so far:
function parsePath() {
return through.obj(function (file, enc, cb) {
var basePath = path.relative(path.join(file.cwd, file.base), file.path+"../../../../");
return basePath.toString();
});
}
And in my pipeline I'm trying to set the config object like this:
.pipe(postcss([
uncss({html: ['views/groups/' + parsePath() + '/!**!/!*.html.twig']})
]))
And Gulp is throwing this error:
[15:01:04] Using gulpfile ~/Business/Code/xxxxxxx/gulpfile.js
[15:01:04] Starting 'default'...
[15:01:04] Starting 'scripts'...
[15:01:04] Finished 'scripts' after 171 ms
[15:01:04] Starting 'styles'...
[15:01:05] 'styles' errored after 399 ms
[15:01:05] Error in plugin "gulp-postcss"
Message:
UnCSS: no HTML files found
Because the path I get back is just this: [object Object], this happens when I return the closure in the parsePath() function. If I just do a log() it looks fine!
Not sure how to solve this, been trying various things for hours, but I am a total newb with NodeJS & Gulp.
Would highly appreciate some pro's giving me input :)
Thanks!
Please or to participate in this conversation.