1 | # [gulp](https://github.com/wearefractal/gulp)-sort
|
2 | > Sort files in stream by path or any custom sort comparator
|
3 |
|
4 | [![Build Status](http://img.shields.io/travis/pgilad/gulp-sort/master.svg?style=flat)](https://travis-ci.org/pgilad/gulp-sort)
|
5 |
|
6 | ## Install
|
7 |
|
8 | `$ npm install gulp-sort --save-dev`
|
9 |
|
10 | ## Usage
|
11 |
|
12 | ```js
|
13 | var sort = require('gulp-sort');
|
14 |
|
15 | // default sort
|
16 | gulp.src('./src/js/**/*.js')
|
17 | .pipe(sort())
|
18 | .pipe(gulp.dest('./build/js'));
|
19 |
|
20 | // sort descending
|
21 | gulp.src('./src/js/**/*.js')
|
22 | .pipe(sort({
|
23 | asc: false
|
24 | }))
|
25 | .pipe(gulp.dest('./build/js'));
|
26 |
|
27 | // sort with a custom comparator
|
28 | gulp.src('./src/js/**/*.js')
|
29 | .pipe(sort({
|
30 | comparator: function(file1, file2) {
|
31 | if (file1.path.indexOf('build') > -1) {
|
32 | return 1;
|
33 | }
|
34 | if (file2.path.indexOf('build') > -1) {
|
35 | return -1;
|
36 | }
|
37 | return 0;
|
38 | }
|
39 | }))
|
40 | .pipe(gulp.dest('./build/js'));
|
41 | ```
|
42 |
|
43 | ## Options
|
44 |
|
45 | ### asc
|
46 |
|
47 | Sort ascending. Defaults to true. Specify false to sort descending.
|
48 |
|
49 | ### comparator
|
50 |
|
51 | Comparator function to use. `comparator(file1, file2)`. Defaults to `localeCompare` of file paths.
|
52 |
|
53 | ## License
|
54 |
|
55 | MIT ©[Gilad Peleg](http://giladpeleg.com)
|