Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support certain files to be "last" #5

Open
mariusmarais opened this issue Jul 18, 2014 · 7 comments
Open

Support certain files to be "last" #5

mariusmarais opened this issue Jul 18, 2014 · 7 comments

Comments

@mariusmarais
Copy link

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?

@mrcljx
Copy link
Collaborator

mrcljx commented Jul 21, 2014

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)
]

@mrcljx mrcljx closed this as completed Jul 21, 2014
@mrcljx mrcljx reopened this Jul 21, 2014
@atomless
Copy link

+1 or just put the above minmatch work around on the docs page.

@mariusmarais
Copy link
Author

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.

@borismee
Copy link

borismee commented Aug 4, 2015

+1

@acarnwath
Copy link

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' ]));

@elliot-nelson
Copy link

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
])

@elliot-nelson
Copy link

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants