gulp-order
gulp-order copied to clipboard
Support certain files to be "last"
I'm trying to express the following order, but it's not working as I had hoped:
[
"app.js",
"**/*.js",
"debug.js"
]
I want debug.js
to always be at the end, but since it matches the **/*.js
, it get placed too early. How can I express that a certain file (certain files) should come later?
Hey @mariusmarais,
we would have to distinguish between "exact" and "glob" matches and I don't have the time for that at the moment. Pull requests are very welcome.
But maybe all you need is this (should work already, since minimatch
supports negative matches):
[
"app.js",
"!debug.js"
"debug.js" // (optional)
]
+1 or just put the above minmatch work around on the docs page.
I've actually resorted to using '**/*'
, which results in a full alphabetic sorting:
app.js
bfolder/cfile.js
dfile.js
zz_debug.js
By prefixing debug files with 'zz_' you intuitively understand that these files should be last, even though it's not that pretty. I then pipe most of my src
sets through a sort
lazypipe:
var sort = lazypipe().pipe(plugins.order, ['**/*']);
The most important thing is that it's consistent, and for my purpose alphabetical is good enough; if you want, you can still add app.js
(or probably module.js
for Angular) before the **/*
, causing them to still be sorted first.
FWIW, I'm fine with closing this wontfix.
+1
I only have one file that I want at the end, so I'm not sure that this would work in all cases, but this works for me (init.js is at the end)
gulp.src(['**/*.js'], {cwd:'./source/js/app'}).pipe(order([ '!init.js', '**/*.js' ]));
I would really like this feature as well. Ideally, I'd like having entries that are either a glob string or a glob string and a priority. Instead of exiting as soon as a matcher is found, check files against all matchers and pick the one with the highest priority -- allowing you to specify something like this:
.pipe(order([
'vendor/*.js', // default priority is always 1
'lib/*.js',
'app/*.js',
['vendor/strings.js', 3], // should always be next-to-last
['app/default.js', 10], // should always be last
])
As an alternate approach, instead of specifying manual priorities, you could match every file against every matcher, counting how many total hits were encountered for each matcher. Then, for each file with multiple matches, select the matcher with the lowest number of total hits.
This would give the "right answer" in every use case I can think of (although I'm probably missing some). For example:
// Core files, then all the rest, then EntryPoint.js
order(['app/core/*.js', 'app/**/*.js', 'app/EntryPoint.js'])
// Everything BUT the core, then core (except for markers), then EntryPoint, then markers
order(['app/**/*.js', 'app/core/*.js', 'app/EntryPoint.js', 'app/core/markers.js'])
In English: "orders files using a series of glob patterns. When a file matches more than one pattern, the most specific glob pattern is used to determine the order."