Added type definition for gulp cache (#11843)

This commit is contained in:
Arun Aravind
2016-10-08 10:37:06 -07:00
committed by Mohamed Hegazy
parent afee31cc2d
commit 41202eb817
2 changed files with 131 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
/// <reference path="gulp-cache.d.ts" />
/// <reference path="../gulp/gulp.d.ts" />
import * as fs from "fs";
import * as gulp from "gulp";
import * as cache from "gulp-cache";
import File = require("vinyl");
// Some gulp plugin
let jshint: any;
gulp.task('lint', function () {
gulp.src('./non/existent/path/*.js')
.pipe(cache(jshint('.jshintrc'), {
key: makeHashKey,
success: function (jshintedFile) {
return jshintedFile.jshint.success;
},
value: function (jshintedFile) {
return {
jshint: jshintedFile.jshint
};
}
}))
.pipe(jshint.reporter('default'));
});
var jsHintVersion = '2.4.1',
jshintOptions = fs.readFileSync('.jshintrc');
function makeHashKey(file: File) {
return [file.contents.toString('utf8'), jsHintVersion, jshintOptions].join('');
}
gulp.task('clear', function (done: any) {
return cache.clearAll(done);
});
+94
View File
@@ -0,0 +1,94 @@
// Type definitions for gulp-cache v0.4.5
// Project: https://github.com/jgable/gulp-cache
// Definitions by: Arun Aravind <https://github.com/aravindarun>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../vinyl/vinyl.d.ts" />
/// <reference path="../gulp-util/gulp-util.d.ts" />
declare module "gulp-cache" {
import File = require("vinyl");
import { Transform } from "stream";
import { PluginError } from "gulp-util";
namespace gc {
type Predicate<T> = (arg: T) => boolean;
interface IGulpCacheOptions {
/**
* The cache instance to use for caching.
*/
fileCache?: IGulpCache;
/**
* The name of the bucket which stores the cached objects.
* Default value = 'default'
*/
name?: string,
/**
* The hash generator to use.
*/
key?: (file: File, callback?: (err: any, result: string) => void) => string | Promise<string>;
/**
* Value representing the success of a task.
*/
success?: boolean | Predicate<any>;
/**
* Content that is to be cached.
*/
value?: (result: any) => Object | Promise<Object> | string;
}
interface ICacheOptions {
/**
* Specifies the name of the directory where the cache
* is to be stored.
*/
cacheDirName: string;
}
interface IGulpCacheStatic {
/**
* Caches the result of a task.
* @param task The task whose result is to be cached.
*/
(task: NodeJS.ReadWriteStream): Transform;
/**
* Caches the result of a task.
* @param task Task whose result is to be cached.
* @param options Override values for available settings.
*/
(task: NodeJS.ReadWriteStream, options: IGulpCacheOptions): Transform;
clear(options: IGulpCacheOptions): Transform;
/**
* Represents a cache store.
*/
Cache: IGulpCache;
/**
* Purges the cache.
* @param err PluginError instance in case of a plugin error.
* If callback is not specified an exception of type
* 'PluginError' is thrown.
*/
clearAll(callback?: (err: PluginError) => void): void;
}
/**
* Represents a cach store.
*/
interface IGulpCache {
new (options: ICacheOptions): any;
}
}
const _: gc.IGulpCacheStatic;
export = _;
}