UNPKG

3.94 kBTypeScriptView Raw
1// Type definitions for Gulp 4.0
2// Project: http://gulpjs.com
3// Definitions by: Drew Noakes <https://drewnoakes.com>
4// Juan Arroyave <http://jarroyave.co>
5// Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
6// David Gabison <https://github.com/pulsovi>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8
9import * as chokidar from "chokidar";
10import * as fs from "fs";
11import { Duplex } from "stream";
12import * as Undertaker from "undertaker";
13import * as vfs from "vinyl-fs";
14
15declare namespace GulpClient {
16 type Globs = string | string[];
17
18 type TaskFunction = Undertaker.TaskFunction;
19
20 /**
21 * @deprecated - Now use `TaskFunction`.
22 */
23 type TaskCallback = TaskFunction;
24
25 type TaskFunctionCallback = Undertaker.TaskCallback;
26
27 interface Gulp extends Undertaker {
28 /**
29 * Emits files matching provided glob or array of globs. Returns a stream of Vinyl files that can be piped to plugins.
30 * @param globs Glob or array of globs to read.
31 * @param options Options to pass to node-glob through glob-stream.
32 */
33 src: SrcMethod;
34
35 /**
36 * Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.
37 * Folders that don't exist will be created.
38 * @param path The path (output folder) to write files to. Or a function that returns it, the function will be provided a vinyl File instance.
39 */
40 dest: DestMethod;
41
42 /**
43 * Functions exactly like gulp.dest, but will create symlinks instead of copying a directory.
44 * @param folder A folder path or a function that receives in a file and returns a folder path.
45 */
46 symlink: typeof vfs.symlink;
47
48 /**
49 * Takes a path string, an array of path strings, a glob string or an array of glob strings as globs to watch on the filesystem.
50 * Also optionally takes options to configure the watcher and a fn to execute when a file changes.
51 * @param globs A path string, an array of path strings, a glob string or an array of glob strings that indicate which files to watch for changes.
52 * @param opts Options that are passed to chokidar.
53 * @param fn Once async completion is signalled, if another run is queued, it will be executed.
54 */
55 watch: WatchMethod;
56 }
57
58 interface WatchOptions extends chokidar.WatchOptions {
59 /**
60 * The delay to wait before triggering the fn.
61 * Useful for waiting on many changes before doing the work on changed files, e.g. find-and-replace on many files.
62 * @default 200
63 */
64 delay?: number | undefined;
65 /**
66 * Whether or not a file change should queue the fn execution if the fn is already running. Useful for a long running fn.
67 * @default true
68 */
69 queue?: boolean | undefined;
70 /**
71 * An event name or array of event names to listen for. Useful if you only need to watch specific events.
72 * @example
73 * gulp.watch is imported from glob-watcher (see https://github.com/gulpjs/gulp/blob/v4.0.2/index.js lines 6, 28 and 48)
74 * gulp use glob-watcher@^5.0.3 (see https://github.com/gulpjs/gulp/blob/v4.0.2/package.json#L33)
75 * glob-watcher declare publicly options.events (see https://github.com/gulpjs/glob-watcher/blob/v5.0.3/README.md?plain=1#L101)
76 * @default ['add','change','unlink']
77 */
78 events?: string | string[];
79 }
80
81 interface WatchMethod {
82 (globs: Globs, fn?: Undertaker.TaskFunction): fs.FSWatcher;
83 (globs: Globs, opts?: WatchOptions, fn?: Undertaker.TaskFunction): fs.FSWatcher;
84 }
85
86 type SrcMethod = typeof vfs.src;
87
88 type DestMethod = typeof vfs.dest;
89}
90
91declare const GulpClient: GulpClient.Gulp;
92export = GulpClient;