Merge pull request #5407 from joeskeen/gulp-sort

Definitions for gulp-sort
This commit is contained in:
Masahiro Wakame
2015-08-21 21:15:52 +09:00
2 changed files with 94 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
/** Tests taken from https://github.com/pgilad/gulp-sort#usage */
/// <reference path="../node/node" />
/// <reference path="../gulp/gulp" />
/// <reference path="gulp-sort" />
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;
}
+44
View File
@@ -0,0 +1,44 @@
// Type definitions for gulp-sort
// Project: https://github.com/pgilad/gulp-sort
// Definitions by: Joe Skeen <http://github.com/joeskeen>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../gulp-util/gulp-util.d.ts" />
/** 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;
}