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

Custom rank function #29

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/node_modules
/lib
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/src
/test
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You'll need two streams:

- A stream that emits the JavaScript files, and
- a stream that emits the compiled CoffeeScript files.

To combine the streams you can pipe into another `gulp.src` or use `es.merge` (from `event-stream`). But you'll notice that in both cases the files are emitted in the same order as they come in - and this can seem very random. With `gulp-order` you can reorder the files.

## Usage
Expand Down Expand Up @@ -63,10 +63,47 @@ gulp
.pipe(order([...], options))
```

#### `base`
### `base`

Some plugins might provide a wrong `base` on the Vinyl file objects. `base` allows you to set a base directory (for example: your application root directory) for all files.

### `rank`

Although this plugin solves most of the order problems with minimatch, sometimes you might need to use a custom ranking function.
The params received by the rank function are:

- `matchers` The order param mapped as minimatch matchers
- `files` vinyl pipeline files

This function **must** return a rank number for the given file.

A usage example would be:

```javascript

function customRank(matcher, file){
for(const i in matchers){
if(matchers[i].match(file.path)){
return i;
}
}
return matchers.length;
}

const files = [
"C:/files/script.js",
"C:/files/*.config.js",
"C:/files/*.run.js"
"C:/files/*.module.js",
"C:/files/**/*.controller.js",
];

gulp
.src(files)
// ...
.pipe(order(files, {rank: customRank})) // this should keep the same order of the files array
```

## Features

Uses [`minimatch`](https://github.com/isaacs/minimatch) for matching.
Expand All @@ -75,7 +112,7 @@ Uses [`minimatch`](https://github.com/isaacs/minimatch) for matching.

- Try to move your ordering out of your `gulp.src(...)` calls into `order(...)` instead.
- You can see the order of the outputted files with [`gulp-print`](https://github.com/alexgorbatchev/gulp-print)

## Troubleshooting

If your files aren't being ordered in the manner that you expect, try adding the [`base`](#base) option.
Expand Down
63 changes: 63 additions & 0 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading