UNPKG

12.4 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
102 interface DestMethod {
103 /**
104 * Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.
105 * Folders that don't exist will be created.
106 *
107 * @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.
108 * @param opt
109 */
110 (outFolder: string | ((file: VinylFile) => string), opt?: DestOptions): NodeJS.ReadWriteStream;
111 }
112
113 interface SrcMethod {
114 /**
115 * Emits files matching provided glob or an array of globs. Returns a stream of Vinyl files that can be piped to plugins.
116 * @param glob Glob or array of globs to read.
117 * @param opt Options to pass to node-glob through glob-stream.
118 */
119 (glob: string | string[], opt?: SrcOptions): NodeJS.ReadWriteStream;
120 }
121
122 /**
123 * Options to pass to node-glob through glob-stream.
124 * Specifies two options in addition to those used by node-glob:
125 * https://github.com/isaacs/node-glob#options
126 */
127 interface SrcOptions {
128 /**
129 * Setting this to <code>false</code> will return <code>file.contents</code> as <code>null</code>
130 * and not read the file at all.
131 * Default: <code>true</code>.
132 */
133 read?: boolean;
134
135 /**
136 * Setting this to false will return <code>file.contents</code> as a stream and not buffer files.
137 * This is useful when working with large files.
138 * Note: Plugins might not implement support for streams.
139 * Default: <code>true</code>.
140 */
141 buffer?: boolean;
142
143 /**
144 * The base path of a glob.
145 *
146 * Default is everything before a glob starts.
147 */
148 base?: string;
149
150 /**
151 * The current working directory in which to search.
152 * Defaults to process.cwd().
153 */
154 cwd?: string;
155
156 /**
157 * The place where patterns starting with / will be mounted onto.
158 * Defaults to path.resolve(options.cwd, "/") (/ on Unix systems, and C:\ or some such on Windows.)
159 */
160 root?: string;
161
162 /**
163 * Include .dot files in normal matches and globstar matches.
164 * Note that an explicit dot in a portion of the pattern will always match dot files.
165 */
166 dot?: boolean;
167
168 /**
169 * Set to match only fles, not directories. Set this flag to prevent copying empty directories
170 */
171 nodir?: boolean;
172
173 /**
174 * By default, a pattern starting with a forward-slash will be "mounted" onto the root setting, so that a valid
175 * filesystem path is returned. Set this flag to disable that behavior.
176 */
177 nomount?: boolean;
178
179 /**
180 * Add a / character to directory matches. Note that this requires additional stat calls.
181 */
182 mark?: boolean;
183
184 /**
185 * Don't sort the results.
186 */
187 nosort?: boolean;
188
189 /**
190 * Set to true to stat all results. This reduces performance somewhat, and is completely unnecessary, unless
191 * readdir is presumed to be an untrustworthy indicator of file existence. It will cause ELOOP to be triggered one
192 * level sooner in the case of cyclical symbolic links.
193 */
194 stat?: boolean;
195
196 /**
197 * When an unusual error is encountered when attempting to read a directory, a warning will be printed to stderr.
198 * Set the silent option to true to suppress these warnings.
199 */
200 silent?: boolean;
201
202 /**
203 * When an unusual error is encountered when attempting to read a directory, the process will just continue on in
204 * search of other matches. Set the strict option to raise an error in these cases.
205 */
206 strict?: boolean;
207
208 /**
209 * See cache property above. Pass in a previously generated cache object to save some fs calls.
210 */
211 cache?: boolean;
212
213 /**
214 * A cache of results of filesystem information, to prevent unnecessary stat calls.
215 * While it should not normally be necessary to set this, you may pass the statCache from one glob() call to the
216 * options object of another, if you know that the filesystem will not change between calls.
217 */
218 statCache?: boolean;
219
220 /**
221 * Perform a synchronous glob search.
222 */
223 sync?: boolean;
224
225 /**
226 * In some cases, brace-expanded patterns can result in the same file showing up multiple times in the result set.
227 * By default, this implementation prevents duplicates in the result set. Set this flag to disable that behavior.
228 */
229 nounique?: boolean;
230
231 /**
232 * Set to never return an empty set, instead returning a set containing the pattern itself.
233 * This is the default in glob(3).
234 */
235 nonull?: boolean;
236
237 /**
238 * Perform a case-insensitive match. Note that case-insensitive filesystems will sometimes result in glob returning
239 * results that are case-insensitively matched anyway, since readdir and stat will not raise an error.
240 */
241 nocase?: boolean;
242
243 /**
244 * Set to enable debug logging in minimatch and glob.
245 */
246 debug?: boolean;
247
248 /**
249 * Set to enable debug logging in glob, but not minimatch.
250 */
251 globDebug?: boolean;
252 }
253
254 interface DestOptions {
255 /**
256 * The output folder. Only has an effect if provided output folder is relative.
257 * Default: process.cwd()
258 */
259 cwd?: string;
260
261 /**
262 * Octal permission string specifying mode for any folders that need to be created for output folder.
263 * Default: 0777.
264 */
265 mode?: string;
266 }
267
268 /**
269 * Options that are passed to <code>gaze</code>.
270 * https://github.com/shama/gaze
271 */
272 interface WatchOptions {
273 /** Interval to pass to fs.watchFile. */
274 interval?: number;
275 /** Delay for events called in succession for the same file/event. */
276 debounceDelay?: number;
277 /** Force the watch mode. Either 'auto' (default), 'watch' (force native events), or 'poll' (force stat polling). */
278 mode?: string;
279 /** The current working directory to base file patterns from. Default is process.cwd().. */
280 cwd?: string;
281 }
282
283 interface WatchEvent {
284 /** The type of change that occurred, either added, changed or deleted. */
285 type: string;
286 /** The path to the file that triggered the event. */
287 path: string;
288 }
289
290 /**
291 * Callback to be called on each watched file change.
292 */
293 interface WatchCallback {
294 (event: WatchEvent): void;
295 }
296
297 interface TaskCallback {
298 /**
299 * Defines a task.
300 * Tasks may be made asynchronous if they are passing a callback or return a promise or a stream.
301 * @param cb callback used to signal asynchronous completion. Caller includes <code>err</code> in case of error.
302 */
303 (cb?: (err?: any) => void): any;
304 }
305}
306
307declare var gulp: gulp.Gulp;
308
309export = gulp;
310
\No newline at end of file