Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#64102 Fix types for gulp-if by @stof
Browse files Browse the repository at this point in the history
All conditions supported by gulp-match are supported by gulp-if.
This also describes the optional 4th argument allowing to pass the
minimatch options for glob conditions.
  • Loading branch information
stof authored Feb 10, 2023
1 parent 51b5a3b commit a18df2b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 62 deletions.
9 changes: 6 additions & 3 deletions types/gulp-if/gulp-if-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ gulp.src('test.css')

gulp.src('test.css')
.pipe(_if(false, gulp.src('test.css'), gulp.src('test.css')));

gulp.src('test.css')
.pipe(_if({isDirectory: true}, gulp.src('test.css')));

gulp.src('test.css')
.pipe(_if({isFile: true}, gulp.src('test.css')));

gulp.src('test.css')
.pipe(_if(file => true, gulp.src('test.css')));

gulp.src('test.css')
.pipe(_if(/.*?\.css/, gulp.src('test.css')));

gulp.src('test.css')
.pipe(_if('*.css', gulp.src('test.css')));
67 changes: 14 additions & 53 deletions types/gulp-if/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,23 @@
// Type definitions for gulp-if
// Type definitions for gulp-if 3.0
// Project: https://github.com/robrich/gulp-if
// Definitions by: Asana <https://asana.com>, Joe Skeen <https://github.com/joeskeen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node"/>
/// <reference types="vinyl" />

import fs = require('fs');
import vinyl = require('vinyl');
import gulpMatch = require('gulp-match');
import minimatch = require("minimatch");

interface GulpIf {
/**
* gulp-if will pipe data to stream whenever condition is truthy.
* If condition is falsey and elseStream is passed, data will pipe to elseStream
* After data is piped to stream or elseStream or neither, data is piped down-stream.
*
* @param condition whether input should be piped to stream
* @param stream the stream to pipe to if condition is true
* @param elseStream (optional) the stream to pipe to if condition is false
*/
(condition: boolean, stream: NodeJS.ReadWriteStream, elseStream?: NodeJS.ReadWriteStream): NodeJS.ReadWriteStream;
/**
* gulp-if will pipe data to stream whenever condition is truthy.
* If condition is falsey and elseStream is passed, data will pipe to elseStream
* After data is piped to stream or elseStream or neither, data is piped down-stream.
*
* @param condition a Node Stat filter condition to be executed on the vinyl file's Stats object
* @param stream the stream to pipe to if condition is true
* @param elseStream (optional) the stream to pipe to if condition is false
*/
(condition: StatFilterCondition, stream: NodeJS.ReadWriteStream, elseStream?: NodeJS.ReadWriteStream): NodeJS.ReadWriteStream;
/**
* gulp-if will pipe data to stream whenever condition is truthy.
* If condition is falsey and elseStream is passed, data will pipe to elseStream
* After data is piped to stream or elseStream or neither, data is piped down-stream.
*
* @param condition a function taking a vinyl file and returning a boolean
* @param stream the stream to pipe to if condition is true
* @param elseStream (optional) the stream to pipe to if condition is false
*/
(condition: (fs: vinyl) => boolean, stream: NodeJS.ReadWriteStream, elseStream?: NodeJS.ReadWriteStream): NodeJS.ReadWriteStream;
/**
* gulp-if will pipe data to stream whenever condition is truthy.
* If condition is falsey and elseStream is passed, data will pipe to elseStream
* After data is piped to stream or elseStream or neither, data is piped down-stream.
*
* @param condition a RegularExpression that works on the file.path
* @param stream the stream to pipe to if condition is true
* @param elseStream (optional) the stream to pipe to if condition is false
*/
(condition: RegExp, stream: NodeJS.ReadWriteStream, elseStream?: NodeJS.ReadWriteStream): NodeJS.ReadWriteStream;
}

interface StatFilterCondition {
isDirectory?: boolean | undefined;
isFile?: boolean | undefined;
}

declare var gulpIf: GulpIf;
/**
* gulp-if will pipe data to stream whenever condition is truthy.
* If condition is falsey and elseStream is passed, data will pipe to elseStream
* After data is piped to stream or elseStream or neither, data is piped down-stream.
*
* @param condition whether input should be piped to stream
* @param stream the stream to pipe to if condition is true
* @param elseStream (optional) the stream to pipe to if condition is false
* @param minimatchOptions (optional) the minimatch options when matching glob conditions
*/
declare function gulpIf(condition: gulpMatch.MatchCondition, stream: NodeJS.ReadWriteStream, elseStream?: NodeJS.ReadWriteStream, minimatchOptions?: minimatch.IOptions): NodeJS.ReadWriteStream;

export = gulpIf;
6 changes: 6 additions & 0 deletions types/gulp-if/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"@types/minimatch": "*"
}
}
7 changes: 1 addition & 6 deletions types/gulp-if/tslint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"extends": "@definitelytyped/dtslint/dt.json",
"rules": {
"no-reference-import": false,
"no-trailing-whitespace": false,
"unified-signatures": false
}
"extends": "@definitelytyped/dtslint/dt.json"
}

0 comments on commit a18df2b

Please sign in to comment.