UNPKG

12.7 kBTypeScriptView Raw
1// Type definitions for Gulp 3.8
2// Project: http://gulpjs.com
3// Definitions by: Drew Noakes <https://drewnoakes.com>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.3
6
7/// <reference types="node" />
8/// <reference types="orchestrator" />
9/// <reference types="vinyl" />
10
11import Orchestrator = require("orchestrator");
12import VinylFile = require("vinyl");
13
14declare namespace gulp {
15 interface Gulp extends Orchestrator {
16 task(name: string): never;
17 /**
18 * Define a task
19 * @param name The name of the task.
20 * @param deps An array of task names to be executed and completed before your task will run.
21 * @param fn The function that performs the task's operations. For asynchronous tasks, you need to provide a hint when the task is complete:
22 * <ul>
23 * <li>Take in a callback</li>
24 * <li>Return a stream or a promise</li>
25 * </ul>
26 */
27 task(name: string, fn?: Orchestrator.TaskFunc): Gulp;
28 /**
29 * Define a task
30 * @param name The name of the task.
31 * @param deps An array of task names to be executed and completed before your task will run.
32 * @param fn The function that performs the task's operations. For asynchronous tasks, you need to provide a hint when the task is complete:
33 * <ul>
34 * <li>Take in a callback</li>
35 * <li>Return a stream or a promise</li>
36 * </ul>
37 */
38 task(name: string, deps?: string[], fn?: Orchestrator.TaskFunc): Gulp;
39
40 /**
41 * Emits files matching provided glob or an array of globs. Returns a stream of Vinyl files that can be piped to plugins.
42 * @param glob Glob or array of globs to read.
43 * @param opt Options to pass to node-glob through glob-stream.
44 */
45 src: SrcMethod;
46 /**
47 * Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.
48 * Folders that don't exist will be created.
49 *
50 * @param outFolder The path (output folder) to write files to. Or a function that returns it, the function will be provided a vinyl File instance.
51 * @param opt
52 */
53 dest: DestMethod;
54 /**
55 * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
56 *
57 * @param glob a single glob or array of globs that indicate which files to watch for changes.
58 * @param opt options, that are passed to the gaze library.
59 * @param fn a callback or array of callbacks to be called on each change, or names of task(s) to run when a file changes, added with task().
60 */
61 watch: WatchMethod;
62 }
63
64 interface GulpPlugin {
65 (...args: any[]): NodeJS.ReadWriteStream;
66 }
67
68 interface WatchMethod {
69 /**
70 * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
71 *
72 * @param glob a single glob or array of globs that indicate which files to watch for changes.
73 * @param fn a callback or array of callbacks to be called on each change, or names of task(s) to run when a file changes, added with task().
74 */
75 (glob: string | string[], fn: WatchCallback | string): NodeJS.EventEmitter;
76 /**
77 * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
78 *
79 * @param glob a single glob or array of globs that indicate which files to watch for changes.
80 * @param fn a callback or array of callbacks to be called on each change, or names of task(s) to run when a file changes, added with task().
81 */
82 (glob: string | string[], fn: (WatchCallback | string)[]): NodeJS.EventEmitter;
83 /**
84 * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
85 *
86 * @param glob a single glob or array of globs that indicate which files to watch for changes.
87 * @param opt options, that are passed to the gaze library.
88 * @param fn a callback or array of callbacks to be called on each change, or names of task(s) to run when a file changes, added with task().
89 */
90 (glob: string | string[], opt: WatchOptions, fn: WatchCallback | string): NodeJS.EventEmitter;
91 /**
92 * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
93 *
94 * @param glob a single glob or array of globs that indicate which files to watch for changes.
95 * @param opt options, that are passed to the gaze library.
96 * @param fn a callback or array of callbacks to be called on each change, or names of task(s) to run when a file changes, added with task().
97 */
98 (glob: string | string[], opt: WatchOptions, fn: (WatchCallback | string)[]): NodeJS.EventEmitter;
99 }
100
101 interface DestMethod {
102 /**
103 * Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.
104 * Folders that don't exist will be created.
105 *
106 * @param outFolder The path (output folder) to write files to. Or a function that returns it, the function will be provided a vinyl File instance.
107 * @param opt
108 */
109 (outFolder: string | ((file: VinylFile) => string), opt?: DestOptions): NodeJS.ReadWriteStream;
110 }
111
112 interface SrcMethod {
113 /**
114 * Emits files matching provided glob or an array of globs. Returns a stream of Vinyl files that can be piped to plugins.
115 * @param glob Glob or array of globs to read.
116 * @param opt Options to pass to node-glob through glob-stream.
117 */
118 (glob: string | string[], opt?: SrcOptions): NodeJS.ReadWriteStream;
119 }
120
121 /**
122 * Options to pass to node-glob through glob-stream.
123 * Specifies two options in addition to those used by node-glob:
124 * https://github.com/isaacs/node-glob#options
125 */
126 interface SrcOptions {
127 /**
128 * Setting this to <code>false</code> will return <code>file.contents</code> as <code>null</code>
129 * and not read the file at all.
130 * Default: <code>true</code>.
131 */
132 read?: boolean | undefined;
133
134 /**
135 * Setting this to false will return <code>file.contents</code> as a stream and not buffer files.
136 * This is useful when working with large files.
137 * Note: Plugins might not implement support for streams.
138 * Default: <code>true</code>.
139 */
140 buffer?: boolean | undefined;
141
142 /**
143 * The base path of a glob.
144 *
145 * Default is everything before a glob starts.
146 */
147 base?: string | undefined;
148
149 /**
150 * The current working directory in which to search.
151 * Defaults to process.cwd().
152 */
153 cwd?: string | undefined;
154
155 /**
156 * The place where patterns starting with / will be mounted onto.
157 * Defaults to path.resolve(options.cwd, "/") (/ on Unix systems, and C:\ or some such on Windows.)
158 */
159 root?: string | undefined;
160
161 /**
162 * Include .dot files in normal matches and globstar matches.
163 * Note that an explicit dot in a portion of the pattern will always match dot files.
164 */
165 dot?: boolean | undefined;
166
167 /**
168 * Set to match only fles, not directories. Set this flag to prevent copying empty directories
169 */
170 nodir?: boolean | undefined;
171
172 /**
173 * By default, a pattern starting with a forward-slash will be "mounted" onto the root setting, so that a valid
174 * filesystem path is returned. Set this flag to disable that behavior.
175 */
176 nomount?: boolean | undefined;
177
178 /**
179 * Add a / character to directory matches. Note that this requires additional stat calls.
180 */
181 mark?: boolean | undefined;
182
183 /**
184 * Don't sort the results.
185 */
186 nosort?: boolean | undefined;
187
188 /**
189 * Set to true to stat all results. This reduces performance somewhat, and is completely unnecessary, unless
190 * readdir is presumed to be an untrustworthy indicator of file existence. It will cause ELOOP to be triggered one
191 * level sooner in the case of cyclical symbolic links.
192 */
193 stat?: boolean | undefined;
194
195 /**
196 * When an unusual error is encountered when attempting to read a directory, a warning will be printed to stderr.
197 * Set the silent option to true to suppress these warnings.
198 */
199 silent?: boolean | undefined;
200
201 /**
202 * When an unusual error is encountered when attempting to read a directory, the process will just continue on in
203 * search of other matches. Set the strict option to raise an error in these cases.
204 */
205 strict?: boolean | undefined;
206
207 /**
208 * See cache property above. Pass in a previously generated cache object to save some fs calls.
209 */
210 cache?: boolean | undefined;
211
212 /**
213 * A cache of results of filesystem information, to prevent unnecessary stat calls.
214 * While it should not normally be necessary to set this, you may pass the statCache from one glob() call to the
215 * options object of another, if you know that the filesystem will not change between calls.
216 */
217 statCache?: boolean | undefined;
218
219 /**
220 * Perform a synchronous glob search.
221 */
222 sync?: boolean | undefined;
223
224 /**
225 * In some cases, brace-expanded patterns can result in the same file showing up multiple times in the result set.
226 * By default, this implementation prevents duplicates in the result set. Set this flag to disable that behavior.
227 */
228 nounique?: boolean | undefined;
229
230 /**
231 * Set to never return an empty set, instead returning a set containing the pattern itself.
232 * This is the default in glob(3).
233 */
234 nonull?: boolean | undefined;
235
236 /**
237 * Perform a case-insensitive match. Note that case-insensitive filesystems will sometimes result in glob returning
238 * results that are case-insensitively matched anyway, since readdir and stat will not raise an error.
239 */
240 nocase?: boolean | undefined;
241
242 /**
243 * Set to enable debug logging in minimatch and glob.
244 */
245 debug?: boolean | undefined;
246
247 /**
248 * Set to enable debug logging in glob, but not minimatch.
249 */
250 globDebug?: boolean | undefined;
251 }
252
253 interface DestOptions {
254 /**
255 * The output folder. Only has an effect if provided output folder is relative.
256 * Default: process.cwd()
257 */
258 cwd?: string | undefined;
259
260 /**
261 * Octal permission string specifying mode for any folders that need to be created for output folder.
262 * Default: 0777.
263 */
264 mode?: string | undefined;
265 }
266
267 /**
268 * Options that are passed to <code>gaze</code>.
269 * https://github.com/shama/gaze
270 */
271 interface WatchOptions {
272 /** Interval to pass to fs.watchFile. */
273 interval?: number | undefined;
274 /** Delay for events called in succession for the same file/event. */
275 debounceDelay?: number | undefined;
276 /** Force the watch mode. Either 'auto' (default), 'watch' (force native events), or 'poll' (force stat polling). */
277 mode?: string | undefined;
278 /** The current working directory to base file patterns from. Default is process.cwd().. */
279 cwd?: string | undefined;
280 }
281
282 interface WatchEvent {
283 /** The type of change that occurred, either added, changed or deleted. */
284 type: string;
285 /** The path to the file that triggered the event. */
286 path: string;
287 }
288
289 /**
290 * Callback to be called on each watched file change.
291 */
292 interface WatchCallback {
293 (event: WatchEvent): void;
294 }
295
296 interface TaskCallback {
297 /**
298 * Defines a task.
299 * Tasks may be made asynchronous if they are passing a callback or return a promise or a stream.
300 * @param cb callback used to signal asynchronous completion. Caller includes <code>err</code> in case of error.
301 */
302 (cb?: (err?: any) => void): any;
303 }
304}
305
306declare var gulp: gulp.Gulp;
307
308export = gulp;
309
\No newline at end of file