Open terinjokes opened 10 years ago
+1 for the feature
+1
I like the idea of an array of match conditions. Should we hard-code that all must match? Or any? (e.g. ||
vs &&
)
+1
plus one more here!
I like the idea of an array of match conditions. Should we hard-code that all must match? Or any? (e.g. || vs &&)
@robrich hardcoding would be the "easy" way to go, but implementing one or the other would likely cause people to want the other one as well, and once they have both, then a way to specify chains of conditionals. If you give a mouse a cookie...
Without creating a complex builder system, you could probably do gif.and([conditional, ...], function)
and gif.or([conditional, ...], function)
for the &&
and ||
, respectively, keeping the original syntax for backwards compatibility.
If we wanted to get wild, you might be able to go with an object structure, that allowed for multiple nested conditionals, something like the following:
var crazy = {
AND: [ {
OR:[ boolean_conditional, bool_function(), ETC ]
},
boolean_conditional,
"string_matcher*.js"
]
}
gif(crazy, minify())
but that's crazy and needlessly complex.
... and this "give a mouse a cookie" is part of my hesitation here. It almost sounds like you should pass in a function, I hand off the arguments you need to run your crazy, and you hand me back a boolean answer ... which by the way is the work-around the original author uses. :D
I'm thinking if we take an opinion, &&
seems the most discoverable -- matches the multiple glob array metaphor.
For the record. I no longer need this. On Dec 1, 2015 7:27 AM, "Rob Richardson" notifications@github.com wrote:
... and this "give a mouse a cookie" is part of my hesitation here. It almost sounds like you should pass in a function, I hand off the arguments you need to run your crazy, and you hand me back a boolean answer ... which by the way is the work-around the original author uses. :D
I'm thinking if we take an opinion, && seems the most discoverable -- matches the multiple glob array metaphor.
— Reply to this email directly or view it on GitHub https://github.com/robrich/gulp-if/issues/37#issuecomment-161001149.
Perhaps then the "easiest" solution then, would be to provide examples of multi-conditional external functions, added as a pattern in the README? If the file object is always available, it is less work for @robrich to "implement".
Otherwise, while I don't know enough about what is kosher in terms of the multi file glob pattern, but mixing booleans with strings in an array, and checking them internally, sounds like an anti-pattern. Similarly, using an array of strings, conditionals, and/or string arrays (for the glob array), leaves you with nested arrays, and the likelihood of people accidentally assuming the array is flat, even if that inherently gets you an "or" pattern with anything in a sub array (assuming the sub array is a glob array and not mixed.)
Quite the rabbit hole!
Bump. Currently doing ugly stuff like this:
var wa_mode = true //boolean switch
.pipe($.if(wa_mode,
$.if('*.html',
$.replace('rel="stylesheet" href="', 'rel="stylesheet" href="{$wa_theme_url}')
)
))
Is there a better solution for this?
Also, it there a way to do this in one line? (match one glob OR the other)
.pipe($.if('*.css', $.cached('CSSandJScache')))
.pipe($.if('*.js', $.cached('CSSandJScache')))
I really miss the good old || and &&.
@Trost123: in your first example, you could replace it with a function. I think what you've got isn't bad though. In your second example, pass in this: /*\.(css|js)$/
.
Thanks, that helps!
Could you also help me with function soultion?
I'm trying to use what @terinjokes suggested:
gif(function(file) { return PRODUCTION && gulpmatch(file, '*.js'); }, minify());
But I want to declare the function outside of task/pipe.
What should I use in place of "file"? If I try to use it as-is, it tell me that file is undefined.
that's the correct way to do it. Do you have a gist or pastebin we can review?
Nevermind, I found the mistake (in my code).
:D Problem solved.
You might wanna fix your previous advice though:
/.*\.(css|js)$/
(The dot before *)
Spent around 20 min trying to figure our why it didn't work.
On the bright side - you made me learn more about regexp ;)
old issue, still open, my workaround on it is using vinyl directly:
const matchesExtensionsAndConditional = (includes, excludes, conditional) =>
(file) => (conditional
&& includes.some((include) => file.basename.endsWith(include))
&& excludes.every((exclude) => !file.basename.endsWith(exclude)));
gulp.src('src/**/*')
.pipe($gulp.if(
matchesExtensionsAndConditional(['.js'], ['.min.js'], runUglify),
uglify(uglifyOpts)))
can be extended to parse !.min.js
, but I wanted to make it simple. Uses different syntax than glob, so might be a deal breaker for some. Works for me though
One currently has multiple options to support multiple conditions with
gulp-if
:But all of these (and more involving
lazypipe
), distract from the goal of this simple problem: matching a boolean condition with a glob condition.I propose something similar to the following to allow multiple conditions without nesting
gulp-if
instances:I don't believe the above will work as is because it conflicts with the multiple glob support in
gulp-match
, but it's the general idea of what i've got.