UNPKG

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