|
1 |
| -# vinyl-fs [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] |
2 |
| -## Information |
3 |
| -<table> |
4 |
| - <tr><td>Package</td><td>vinyl-fs</td></tr> |
5 |
| - <tr><td>Description</td><td>Vinyl adapter for the file system</td></tr> |
6 |
| - <tr><td>Node Version</td><td>>= 0.10</td></tr> |
7 |
| -</table> |
| 1 | +<p align="center"> |
| 2 | + <a href="http://gulpjs.com"> |
| 3 | + <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png"> |
| 4 | + </a> |
| 5 | +</p> |
| 6 | + |
| 7 | +# vinyl-fs |
| 8 | + |
| 9 | +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] |
| 10 | + |
| 11 | +[Vinyl][vinyl] adapter for the file system. |
| 12 | + |
| 13 | +## What is Vinyl? |
| 14 | + |
| 15 | +[Vinyl][vinyl] is a very simple metadata object that describes a file. When you think of a file, two attributes come to mind: `path` and `contents`. These are the main attributes on a [Vinyl][vinyl] object. A file does not necessarily represent something on your computer’s file system. You have files on S3, FTP, Dropbox, Box, CloudThingly.io and other services. [Vinyl][vinyl] can be used to describe files from all of these sources. |
| 16 | + |
| 17 | +## What is a Vinyl Adapter? |
| 18 | + |
| 19 | +While Vinyl provides a clean way to describe a file, we now need a way to access these files. Each file source needs what I call a "Vinyl adapter". A Vinyl adapter simply exposes a `src(globs)` and a `dest(folder)` method. Each return a stream. The `src` stream produces Vinyl objects, and the `dest` stream consumes Vinyl objects. Vinyl adapters can expose extra methods that might be specific to their input/output medium, such as the `symlink` method `vinyl-fs` provides. |
8 | 20 |
|
9 | 21 | ## Usage
|
10 | 22 |
|
11 | 23 | ```javascript
|
12 | 24 | var map = require('map-stream');
|
13 |
| -var fs = require('vinyl-fs'); |
| 25 | +var vfs = require('vinyl-fs'); |
14 | 26 |
|
15 | 27 | var log = function(file, cb) {
|
16 | 28 | console.log(file.path);
|
17 | 29 | cb(null, file);
|
18 | 30 | };
|
19 | 31 |
|
20 |
| -fs.src(['./js/**/*.js', '!./js/vendor/*.js']) |
| 32 | +vfs.src(['./js/**/*.js', '!./js/vendor/*.js']) |
21 | 33 | .pipe(map(log))
|
22 |
| - .pipe(fs.dest('./output')); |
| 34 | + .pipe(vfs.dest('./output')); |
23 | 35 | ```
|
24 | 36 |
|
25 | 37 | ## API
|
26 |
| -### src(globs[, opt]) |
27 |
| -- Takes a glob string or an array of glob strings as the first argument. |
28 |
| -- Globs are executed in order, so negations should follow positive globs. For example: |
| 38 | + |
| 39 | +### `src(globs[, options])` |
| 40 | + |
| 41 | +Takes a glob string or an array of glob strings as the first argument and an options object as the second. |
| 42 | +Returns a stream of [vinyl] `File` objects. |
| 43 | + |
| 44 | +__Note: UTF-8 BOM will be stripped from all UTF-8 files read with `.src` unless disabled in the options.__ |
| 45 | + |
| 46 | +#### Globs |
| 47 | + |
| 48 | +Globs are executed in order, so negations should follow positive globs. |
| 49 | + |
| 50 | +For example: |
29 | 51 |
|
30 | 52 | ```js
|
31 | 53 | fs.src(['!b*.js', '*.js'])
|
32 | 54 | ```
|
33 | 55 |
|
34 |
| -would not exclude any files, but this would |
| 56 | +would not exclude any files, but the following would: |
35 | 57 |
|
36 | 58 | ```js
|
37 | 59 | fs.src(['*.js', '!b*.js'])
|
38 | 60 | ```
|
39 | 61 |
|
40 |
| -- Possible options for the second argument: |
41 |
| - - cwd - Specify the working directory the folder is relative to. |
42 |
| - - Default is `process.cwd()`. |
| 62 | +#### Options |
| 63 | + |
| 64 | +##### `options.cwd` |
| 65 | + |
| 66 | +The working directory the folder is relative to. |
| 67 | + |
| 68 | +Type: `String` |
| 69 | + |
| 70 | +Default: `process.cwd()` |
| 71 | + |
| 72 | +##### `options.base` |
| 73 | + |
| 74 | +The folder relative to the cwd. This is used to determine the file names when saving in `.dest()`. |
| 75 | + |
| 76 | +Type: `String` |
| 77 | + |
| 78 | +Default: The part of the path before the glob (if any) begins. For example, `path/to/**/*.js` would resolve to `path/to`. If there is no glob (i.e. a file path with no pattern), then the dirname of the path is used. For example, `path/to/some/file.js` would resolve to `path/to/some`. |
43 | 79 |
|
44 |
| - - base - Specify the folder relative to the cwd. This is used to determine the file names when saving in `.dest()`. |
45 |
| - - Default is where the glob begins, if any. For example, `path/to/**/*.js` would resolve to `path/to`. |
46 |
| - - If there is no glob (i.e. a file path with no pattern), then the dirname of the path is used. For example, `path/to/some/file.js` would resolve to `path/to/some`. |
| 80 | +##### `options.buffer` |
47 | 81 |
|
48 |
| - - buffer - `true` or `false` if you want to buffer the file. |
49 |
| - - Default value is `true`. |
50 |
| - - `false` will make `file.contents` a paused Stream. |
| 82 | +Whether or not you want to buffer the file contents into memory. Setting to `false` will make `file.contents` a paused Stream. |
51 | 83 |
|
52 |
| - - read - `true` or `false` if you want the file to be read or not. Useful for stuff like `rm`ing files. |
53 |
| - - Default value is `true`. |
54 |
| - - `false` will disable writing the file to disk via `.dest()`. |
| 84 | +Type: `Boolean` |
55 | 85 |
|
56 |
| - - since - `Date` or `number` if you only want files that have been modified since the time specified. |
57 |
| - - stripBOM - `true` or `false` if you want the BOM to be stripped on UTF-8 encoded files. |
58 |
| - - Default value is `true`. |
| 86 | +Default: `true` |
59 | 87 |
|
60 |
| - - passthrough - `true` or `false` if you want a duplex stream which passes items through and emits globbed files. |
61 |
| - - Default is `false`. |
| 88 | +##### `options.read` |
62 | 89 |
|
63 |
| - - sourcemaps - `true` or `false` if you want files to have sourcemaps enabled. |
64 |
| - - Default is `false`. |
65 |
| - - Will load inline sourcemaps and resolve sourcemap links from files |
66 |
| - - Uses `gulp-sourcemaps` under the hood |
| 90 | +Whether or not you want the file to be read at all. Useful for stuff like removing files. Setting to `false` will make `file.contents` `null` and will disable writing the file to disk via `.dest()`. |
67 | 91 |
|
68 |
| - - followSymlinks - `true` if you want to recursively resolve symlinks to their targets; set to `false` to preserve them as symlinks. |
69 |
| - - Default is `true`. |
70 |
| - - `false` will make `file.symlink` equal the original symlink's target path. |
| 92 | +Type: `Boolean` |
71 | 93 |
|
72 |
| - - Any glob-related options are documented in [glob-stream] and [node-glob]. |
| 94 | +Default: `true` |
73 | 95 |
|
74 |
| - - Any through2-related options are documented in [through2] |
| 96 | +##### `options.since` |
75 | 97 |
|
76 |
| -- Returns a Readable stream by default, or a Duplex stream if the `passthrough` option is set to `true`. |
77 |
| -- This stream emits matching [vinyl] File objects. |
| 98 | +Only streams files that have been modified since the time specified. |
78 | 99 |
|
79 |
| -_Note:_ UTF-8 BOM will be stripped from all UTF-8 files read with `.src`. |
| 100 | +Type: `Date` or `Number` |
80 | 101 |
|
81 |
| -### dest(folder[, opt]) |
82 |
| -- Takes a folder path as the first argument. |
83 |
| -- First argument can also be a function that takes in a file and returns a folder path. |
84 |
| -- Possible options for the second argument: |
85 |
| - - cwd - Specify the working directory the folder is relative to. |
86 |
| - - Default is `process.cwd()`. |
| 102 | +Default: `undefined` |
87 | 103 |
|
88 |
| - - base - Specify the folder relative to the cwd. This is used to determine the file names when saving in `.dest()`. |
89 |
| - - Default is the `cwd` resolves to the folder path. |
90 |
| - - Can also be a function that takes in a file and returns a folder path. |
| 104 | +##### `options.stripBOM` |
91 | 105 |
|
92 |
| - - mode - Specify the mode the files should be created with. |
93 |
| - - Default is the mode of the input file (file.stat.mode) if any. |
94 |
| - - Default is the process mode if the input file has no mode property. |
| 106 | +Causes the BOM to be stripped on UTF-8 encoded files. Set to `false` if you need the BOM for some reason. |
95 | 107 |
|
96 |
| - - dirMode - Specify the mode the directory should be created with. |
97 |
| - - Default is the process mode. |
| 108 | +Type: `Boolean` |
98 | 109 |
|
99 |
| - - overwrite - Specify if existing files with the same path should be overwritten or not. |
100 |
| - - Default is `true`, to always overwrite existing files. |
101 |
| - - Can also be a function that takes in a file and returns `true` or `false`. |
| 110 | +Default: `true` |
102 | 111 |
|
103 |
| - - sourcemaps - |
104 |
| - - Default is `null` aka do not write sourcemaps. |
105 |
| - - Uses `gulp-sourcemaps` under the hood |
106 |
| - - Examples: |
107 |
| - - Write as inline comments |
108 |
| - - fs.dest('./', {sourcemaps: true}) |
109 |
| - - Write as files in the same folder |
110 |
| - - fs.dest('./', {<br> sourcemaps: {<br> path: '.'<br> }<br>}) |
111 |
| - - Any other options are passed through to `gulp-sourcemaps` |
112 |
| - - fs.dest('./', {<br> sourcemaps: {<br> path: '.',<br> addComment: false,<br> includeContent: false<br> }<br>}) |
| 112 | +##### `options.passthrough` |
113 | 113 |
|
114 |
| - - Any through2-related options are documented in [through2] |
| 114 | +Allows `.src` to be used in the middle of a pipeline (using a duplex stream) which passes through all objects received and adds all files globbed to the stream. |
115 | 115 |
|
116 |
| -- Returns a Readable/Writable stream. |
117 |
| -- On write the stream will save the [vinyl] File to disk at the folder/cwd specified. |
118 |
| -- After writing the file to disk, it will be emitted from the stream so you can keep piping these around. |
119 |
| -- If the file has a `symlink` attribute specifying a target path, then a symlink will be created. |
120 |
| -- The file will be modified after being written to this stream: |
| 116 | +Type: `Boolean` |
| 117 | + |
| 118 | +Default: `false` |
| 119 | + |
| 120 | +##### `options.sourcemaps` |
| 121 | + |
| 122 | +Enables sourcemap support on files passed through the stream. Will load inline sourcemaps and resolve sourcemap links from files. Uses [gulp-sourcemaps] under the hood. |
| 123 | + |
| 124 | +Type: `Boolean` |
| 125 | + |
| 126 | +Default: `false` |
| 127 | + |
| 128 | +##### `options.followSymlinks` - `true` if you want |
| 129 | + |
| 130 | +Whether or not to recursively resolve symlinks to their targets. Setting to `false` to preserve them as symlinks and make `file.symlink` equal the original symlink's target path. |
| 131 | + |
| 132 | +Type: `Boolean` |
| 133 | + |
| 134 | +Default: `true` |
| 135 | + |
| 136 | +##### other |
| 137 | + |
| 138 | +Any glob-related options are documented in [glob-stream] and [node-glob]. |
| 139 | +Any through2-related options are documented in [through2]. |
| 140 | + |
| 141 | +### `dest(folder[, options])` |
| 142 | + |
| 143 | +Takes a folder path string or a function as the first argument and an options object as the second. If given a function, it will be called with each [vinyl] `File` object and must return a folder path. |
| 144 | +Returns a stream that accepts [vinyl] `File` objects, writes them to disk at the folder/cwd specified, and passes them downstream so you can keep piping these around. |
| 145 | + |
| 146 | +If the file has a `symlink` attribute specifying a target path, then a symlink will be created. |
| 147 | + |
| 148 | +__Note: The file will be modified after being written to this stream.__ |
121 | 149 | - `cwd`, `base`, and `path` will be overwritten to match the folder.
|
122 | 150 | - `stat.mode` will be overwritten if you used a mode parameter.
|
123 | 151 | - `contents` will have it's position reset to the beginning if it is a stream.
|
124 | 152 |
|
125 |
| -### symlink(folder[, opt]) |
126 |
| -- Takes a folder path as the first argument. |
127 |
| -- First argument can also be a function that takes in a file and returns a folder path. |
128 |
| -- Possible options for the second argument: |
129 |
| - - cwd - Specify the working directory the folder is relative to. |
130 |
| - - Default is `process.cwd()`. |
| 153 | +#### Options |
| 154 | + |
| 155 | +##### `options.cwd` |
| 156 | + |
| 157 | +The working directory the folder is relative to. |
| 158 | + |
| 159 | +Type: `String` |
| 160 | + |
| 161 | +Default: `process.cwd()` |
| 162 | + |
| 163 | +##### `options.base` |
| 164 | + |
| 165 | +The folder relative to the cwd. This is used to determine the file names when saving in `.dest()`. Can also be a function that takes in a file and returns a folder path. |
131 | 166 |
|
132 |
| - - base - Specify the folder relative to the cwd. This is used to determine the file names when saving in `.dest()`. |
133 |
| - - Default is the `cwd` resolves to the folder path. |
134 |
| - - Can also be a function that takes in a file and returns a folder path. |
| 167 | +Type: `String` or `Function` |
135 | 168 |
|
136 |
| - - dirMode - Specify the mode the directory should be created with. |
137 |
| - - Default is the process mode. |
| 169 | +Default: The `cwd` resolved to the folder path. |
138 | 170 |
|
139 |
| - - Any through2-related options are documented in [through2] |
| 171 | +##### `options.mode` |
140 | 172 |
|
141 |
| -- Returns a Readable/Writable stream. |
142 |
| -- On write the stream will create a symbolic link (i.e. symlink) on disk at the folder/cwd specified. |
143 |
| -- After creating the symbolic link, it will be emitted from the stream so you can keep piping these around. |
144 |
| -- The file will be modified after being written to this stream: |
| 173 | +The mode the files should be created with. |
| 174 | + |
| 175 | +Type: `Number` |
| 176 | + |
| 177 | +Default: The `mode` of the input file (`file.stat.mode`) if any, or the process mode if the input file has no `mode` property. |
| 178 | + |
| 179 | +##### `options.dirMode` |
| 180 | + |
| 181 | +The mode the directory should be created with. |
| 182 | + |
| 183 | +Type: `Number` |
| 184 | + |
| 185 | +Default: The process `mode`. |
| 186 | + |
| 187 | +##### `options.overwrite` |
| 188 | + |
| 189 | +Whether or not existing files with the same path should be overwritten. Can also be a function that takes in a file and returns `true` or `false`. |
| 190 | + |
| 191 | +Type: `Boolean` or `Function` |
| 192 | + |
| 193 | +Default: `true` (always overwrite existing files) |
| 194 | + |
| 195 | +##### `options.sourcemaps` |
| 196 | + |
| 197 | +Enables sourcemap support on files passed through the stream. Will write inline soucemaps if specified as `true`. Uses [gulp-sourcemaps] under the hood. |
| 198 | + |
| 199 | +Examples: |
| 200 | + |
| 201 | +```js |
| 202 | +// Write as inline comments |
| 203 | +vfs.dest('./', { |
| 204 | + sourcemaps: true |
| 205 | +}); |
| 206 | + |
| 207 | +// Write as files in the same folder |
| 208 | +vfs.dest('./', { |
| 209 | + sourcemaps: { |
| 210 | + path: '.' |
| 211 | + } |
| 212 | +}); |
| 213 | + |
| 214 | +// Any other options are passed through to [gulp-sourcemaps] |
| 215 | +vfs.dest('./', { |
| 216 | + sourcemaps: { |
| 217 | + path: '.', |
| 218 | + addComment: false, |
| 219 | + includeContent: false |
| 220 | + } |
| 221 | +}); |
| 222 | +``` |
| 223 | + |
| 224 | +Type: `Boolean` or `Object` |
| 225 | + |
| 226 | +Default: `undefined` (do not write sourcemaps) |
| 227 | + |
| 228 | +##### other |
| 229 | + |
| 230 | +Any through2-related options are documented in [through2]. |
| 231 | + |
| 232 | +### `symlink(folder[, options])` |
| 233 | + |
| 234 | +Takes a folder path string or a function as the first argument and an options object as the second. If given a function, it will be called with each [vinyl] `File` object and must return a folder path. |
| 235 | +Returns a stream that accepts [vinyl] `File` objects, create a symbolic link (i.e. symlink) at the folder/cwd specified, and passes them downstream so you can keep piping these around. |
| 236 | + |
| 237 | +__Note: The file will be modified after being written to this stream.__ |
145 | 238 | - `cwd`, `base`, and `path` will be overwritten to match the folder.
|
146 | 239 |
|
| 240 | +#### Options |
| 241 | + |
| 242 | +##### `options.cwd` |
| 243 | + |
| 244 | +The working directory the folder is relative to. |
| 245 | + |
| 246 | +Type: `String` |
| 247 | + |
| 248 | +Default: `process.cwd()` |
| 249 | + |
| 250 | +##### `options.base` |
| 251 | + |
| 252 | +The folder relative to the cwd. This is used to determine the file names when saving in `.symlink()`. Can also be a function that takes in a file and returns a folder path. |
| 253 | + |
| 254 | +Type: `String` or `Function` |
| 255 | + |
| 256 | +Default: The `cwd` resolved to the folder path. |
| 257 | + |
| 258 | +##### `options.dirMode` |
| 259 | + |
| 260 | +The mode the directory should be created with. |
| 261 | + |
| 262 | +Type: `Number` |
| 263 | + |
| 264 | +Default: The process mode. |
| 265 | + |
| 266 | +##### other |
| 267 | + |
| 268 | +Any through2-related options are documented in [through2]. |
| 269 | + |
147 | 270 | [glob-stream]: https://github.com/gulpjs/glob-stream
|
| 271 | +[gulp-sourcemaps]: https://github.com/floridoo/gulp-sourcemaps |
148 | 272 | [node-glob]: https://github.com/isaacs/node-glob
|
149 | 273 | [gaze]: https://github.com/shama/gaze
|
150 | 274 | [glob-watcher]: https://github.com/wearefractal/glob-watcher
|
151 | 275 | [vinyl]: https://github.com/wearefractal/vinyl
|
152 | 276 | [through2]: https://github.com/rvagg/through2
|
| 277 | + |
| 278 | +[downloads-image]: http://img.shields.io/npm/dm/vinyl-fs.svg |
153 | 279 | [npm-url]: https://www.npmjs.com/package/vinyl-fs
|
154 | 280 | [npm-image]: https://badge.fury.io/js/vinyl-fs.svg
|
| 281 | + |
155 | 282 | [travis-url]: https://travis-ci.org/gulpjs/vinyl-fs
|
156 | 283 | [travis-image]: https://travis-ci.org/gulpjs/vinyl-fs.svg?branch=master
|
157 |
| -[coveralls-url]: https://coveralls.io/r/wearefractal/vinyl-fs |
158 |
| -[coveralls-image]: https://img.shields.io/coveralls/wearefractal/vinyl-fs.svg?style=flat |
159 |
| -[depstat-url]: https://david-dm.org/gulpjs/vinyl-fs |
160 |
| -[depstat-image]: https://david-dm.org/gulpjs/vinyl-fs.svg |
| 284 | + |
| 285 | +[coveralls-url]: https://coveralls.io/r/gulpjs/vinyl-fs |
| 286 | +[coveralls-image]: https://coveralls.io/repos/gulpjs/vinyl-fs/badge.svg |
| 287 | + |
| 288 | +[gitter-url]: https://gitter.im/gulpjs/gulp |
| 289 | +[gitter-image]: https://badges.gitter.im/gulpjs/gulp.png |
0 commit comments