UNPKG

8.06 kBTypeScriptView Raw
1// Type definitions for vinyl-fs 2.4
2// Project: https://github.com/gulpjs/vinyl-fs
3// Definitions by: vvakame <https://github.com/vvakame>
4// remisery <https://github.com/remisery>
5// TeamworkGuy2 <https://github.com/TeamworkGuy2>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
8/// <reference types="node" />
9
10declare global {
11 namespace NodeJS {
12 interface WritableStream {
13 write(buffer: any/* Vinyl.File */, cb?: (err?: Error | null) => void): boolean;
14 }
15 }
16}
17
18import * as _events from 'events';
19import * as File from 'vinyl';
20import * as globStream from 'glob-stream';
21
22export interface SrcOptions extends globStream.Options {
23 /** Prevents stream from emitting an error when file not found. */
24 allowEmpty?: boolean | undefined;
25
26 /** Specifies the working directory the folder is relative to */
27 cwd?: string | undefined;
28
29 /**
30 * Specifies the folder relative to the cwd
31 * This is used to determine the file names when saving in .dest()
32 * Default: where the glob begins
33 */
34 base?: string | undefined;
35
36 /**
37 * Setting this to false will make file.contents a paused stream
38 * If true it will buffer the file contents
39 * Default: true
40 */
41 buffer?: boolean | undefined;
42
43 /**
44 * The mode the directory should be created with.
45 * Default: the process mode
46 */
47 dirMode?: number | undefined;
48
49 /**
50 * Whether or not you want globs to match on dot files or not
51 * (e.g., `.gitignore`).
52 */
53 dot?: boolean | undefined;
54
55 /**
56 * Whether or not to recursively resolve symlinks to their targets.
57 * Setting to `false` to preserve them as symlinks and make `file.symlink`
58 * equal the original symlink's target path.
59 * Default: true
60 */
61 followSymlinks?: boolean | undefined;
62
63 /**
64 * Setting this to false will ignore the contents of the file and disable
65 * writing to disk to speed up operations
66 * Default: true
67 */
68 read?: boolean | undefined;
69
70 /**
71 * Whether or not the symlink should be relative or absolute.
72 * Default: false
73 */
74 relative?: boolean | undefined;
75
76 /** Only find files that have been modified since the time specified */
77 since?: Date | number | undefined;
78
79 /**
80 * Causes the BOM to be stripped on UTF-8 encoded files. Set to `false`
81 * if you need the BOM for some reason.
82 */
83 stripBOM?: boolean | undefined;
84
85 /**
86 * Setting this to true will create a duplex stream, one that passes
87 * through items and emits globbed files.
88 * Default: false
89 */
90 passthrough?: boolean | undefined;
91
92 /**
93 * Setting this to true will enable sourcemaps.
94 * Default: false
95 */
96 sourcemaps?: boolean | undefined;
97
98 /**
99 * Whether or not to recursively resolve symlinks to their targets. Setting to false to
100 * preserve them as symlinks and make file.symlink equal the original symlink's target path.
101 * Default: false
102 */
103 resolveSymlinks?: boolean | undefined;
104 /**
105 * Causes the BOM to be removed on UTF-8 encoded files. Set to false if you need the BOM for some reason.
106 * Default: true
107 */
108 removeBOM?: boolean | undefined;
109}
110
111export interface DestOptions {
112 /**
113 * Specify the working directory the folder is relative to
114 * Default is process.cwd()
115 */
116 cwd?: string | undefined;
117
118 /**
119 * Specify the mode the files should be created with
120 * Default is the mode of the input file (file.stat.mode)
121 * or the process mode if the input file has no mode property
122 */
123 mode?: number | string | undefined;
124
125 /** Specify the mode the directory should be created with. Default is the process mode */
126 dirMode?: number | string | undefined;
127
128 /** Specify if existing files with the same path should be overwritten or not. Default is true, to always overwrite existing files */
129 overwrite?: boolean | undefined;
130
131 /**
132 * Enables sourcemap support on files passed through the stream. Will write inline soucemaps if
133 * specified as true. Specifying a string path will write external sourcemaps at the given path.
134 */
135 sourcemaps?: true | string | undefined;
136
137 /**
138 * When creating a symlink, whether or not the created symlink should be relative. If false,
139 * the symlink will be absolute. Note: This option will be ignored if a junction is being created.
140 */
141 relativeSymlinks?: boolean | undefined;
142
143 /* When creating a symlink, whether or not a directory symlink should be created as a junction. */
144 useJunctions?: boolean | undefined;
145}
146
147/**
148 * Gets files that match the glob and converts them into the vinyl format
149 * @param globs Takes a glob string or an array of glob strings as the first argument
150 * Globs are executed in order, so negations should follow positive globs
151 * fs.src(['!b*.js', '*.js']) would not exclude any files, but this would: fs.src(['*.js', '!b*.js'])
152 * @param opt Options Vinyl source options, changes the way the files are read, found, or stored in the vinyl stream
153 */
154export function src(globs: string|string[], opt?: SrcOptions): NodeJS.ReadWriteStream;
155
156/**
157 * On write the stream will save the vinyl File to disk at the folder/cwd specified.
158 * After writing the file to disk, it will be emitted from the stream so you can keep piping these around.
159 * The file will be modified after being written to this stream:
160 * cwd, base, and path will be overwritten to match the folder
161 * stat.mode will be overwritten if you used a mode parameter
162 * contents will have it's position reset to the beginning if it is a stream
163 * @param folder destination folder
164 */
165export function dest(folder: string, opt?: DestOptions): NodeJS.ReadWriteStream;
166
167/**
168 * On write the stream will save the vinyl File to disk at the folder/cwd specified.
169 * After writing the file to disk, it will be emitted from the stream so you can keep piping these around.
170 * The file will be modified after being written to this stream:
171 * cwd, base, and path will be overwritten to match the folder
172 * stat.mode will be overwritten if you used a mode parameter
173 * contents will have it's position reset to the beginning if it is a stream
174 * @param getFolderPath function that takes in a file and returns a folder path
175 */
176export function dest(getFolderPath: (file: File) => string): NodeJS.ReadWriteStream;
177
178/**
179 * On write the stream will create a symbolic link (i.e. symlink) on disk at the folder/cwd specified.
180 * After creating the symbolic link, it will be emitted from the stream so you can keep piping these around.
181 * The file will be modified after being written to this stream:
182 * cwd, base, and path will be overwritten to match the folder
183 */
184export function symlink(folder: string, opts?: {
185 /**
186 * Specify the working directory the folder is relative to
187 * Default is process.cwd()
188 */
189 cwd?: string | undefined;
190
191 /** Specify the mode the directory should be created with. Default is the process mode */
192 mode?: number | string | undefined;
193
194 /**
195 * Specify the mode the directory should be created with
196 * Default is the process mode
197 */
198 dirMode?: number | undefined
199}): NodeJS.ReadWriteStream;
200
201/**
202 * On write the stream will create a symbolic link (i.e. symlink) on disk at the folder/cwd generated from getFolderPath.
203 * After creating the symbolic link, it will be emitted from the stream so you can keep piping these around.
204 * The file will be modified after being written to this stream:
205 * cwd, base, and path will be overwritten to match the folder
206 */
207export function symlink(getFolderPath: (File: File) => string, opts?: {
208 /**
209 * Specify the working directory the folder is relative to
210 * Default is process.cwd()
211 */
212 cwd?: string | undefined;
213
214 /**
215 * Specify the mode the directory should be created with
216 * Default is the process mode
217 */
218 dirMode?: number | undefined
219}): NodeJS.ReadWriteStream;