diff --git a/gulp-sort/gulp-sort-tests.ts b/gulp-sort/gulp-sort-tests.ts new file mode 100644 index 000000000..12685c085 --- /dev/null +++ b/gulp-sort/gulp-sort-tests.ts @@ -0,0 +1,50 @@ +/** Tests taken from https://github.com/pgilad/gulp-sort#usage */ +/// +/// +/// + +import gulp = require('gulp'); +import sort = require('gulp-sort'); +import gulpUtil = require('gulp-util'); + +// default sort +gulp.src('./src/js/**/*.js') + .pipe(sort()) + .pipe(gulp.dest('./build/js')); + +// pass in a custom comparator function +gulp.src('./src/js/**/*.js') + .pipe(sort(customComparator)) + .pipe(gulp.dest('./build/js')); + +// sort descending +gulp.src('./src/js/**/*.js') + .pipe(sort({ + asc: false + })) + .pipe(gulp.dest('./build/js')); + +// sort with a custom comparator +gulp.src('./src/js/**/*.js') + .pipe(sort({ + comparator: function(file1, file2) { + if (file1.path.indexOf('build') > -1) { + return 1; + } + if (file2.path.indexOf('build') > -1) { + return -1; + } + return 0; + } + })) + .pipe(gulp.dest('./build/js')); + +function customComparator(file1: gulpUtil.File, file2: gulpUtil.File) { + if (file1.path.indexOf('build') > -1) { + return 1; + } + if (file2.path.indexOf('build') > -1) { + return -1; + } + return 0; +} \ No newline at end of file diff --git a/gulp-sort/gulp-sort.d.ts b/gulp-sort/gulp-sort.d.ts new file mode 100644 index 000000000..c06b9c3e0 --- /dev/null +++ b/gulp-sort/gulp-sort.d.ts @@ -0,0 +1,44 @@ +// Type definitions for gulp-sort +// Project: https://github.com/pgilad/gulp-sort +// Definitions by: Joe Skeen +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +/** Sort files in stream by path or any custom sort comparator */ +declare module 'gulp-sort' { + + import gulpUtil = require('gulp-util'); + + interface IOptions { + /** + * A function to compare two files. + * Returns: + * -1 if file1 should be before file2, + * 0 if file1 is equivalent to file2, and + * 1 if file1 should be after file2 + */ + comparator?: IComparatorFunction; + /** Whether to sort in ascending order, default is true */ + asc?: boolean; + } + + interface IComparatorFunction { + /** + * A function to compare two files. + * Returns: + * -1 if file1 should be before file2, + * 0 if file1 is equivalent to file2, and + * 1 if file1 should be after file2 + */ + (file1: gulpUtil.File, file2: gulpUtil.File): number; + } + + /** Sort files in stream by path or any custom sort comparator */ + function gulpSort(): NodeJS.ReadWriteStream; + function gulpSort(comparator: IComparatorFunction): NodeJS.ReadWriteStream; + function gulpSort(options: IOptions): NodeJS.ReadWriteStream; + + export = gulpSort; +}