/
index.d.ts
74 lines (58 loc) · 1.58 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import File = require('vinyl');
export type Options = {
/**
Whether the plugin can handle directories.
@default false
*/
readonly supportsDirectories: boolean;
/**
Whether the plugin can handle any Vinyl file type.
Useful for custom type filtering.
Supersedes `supportsDirectories`.
@default false
*/
readonly supportsAnyType: boolean;
/**
An async generator function executed for finalization after all files have been processed.
You can yield more files from it if needed.
@example
```
import {gulpPlugin} from 'gulp-plugin-extras';
export default function gulpFoo() {
return gulpPlugin(
'gulp-foo',
async file => { … },
{
async * onFinish() {
yield someVinylFile;
yield someVinylFile2;
}
}
);
}
```
*/
readonly onFinish?: (stream: NodeJS.ReadableStream) => AsyncGenerator<File.BufferFile>;
};
/**
Create a Gulp plugin.
@param name - The plugin name.
@param onFile - The async function called for each vinyl file in the stream. Must return a modified or new vinyl file.
If you throw an error with a `.isPresentable = true` property, it will not display the error stack.
_This does not support streaming unless you enable the `supportsAnyType` option._
@example
```
import {gulpPlugin} from 'gulp-plugin-extras';
export default function gulpFoo() {
return gulpPlugin('gulp-foo', async file => {
file.contents = await someKindOfTransformation(file.contents);
return file;
});
}
```
*/
export function gulpPlugin(
name: string,
onFile: (file: File.BufferFile) => Promise<File.BufferFile>,
options?: Options
): NodeJS.ReadableStream;