How to use the src function from vinyl-fs
Find comprehensive JavaScript vinyl-fs.src code examples handpicked from public code repositorys.
vinyl-fs.src is a function in the Vinyl-fs library used to read files from a source directory and create Vinyl file objects representing those files.
146 147 148 149 150 151 152 153 154 155
let input; if (Array.isArray(some) || typeof some === 'string' || !some) { const options = { base: '.', follow: true, allowEmpty: true }; if (some) { input = vfs.src(some, options).pipe(filter(all)); // split this up to not unnecessarily filter all a second time } else { input = vfs.src(all, options); } } else {
63 64 65 66 67 68 69 70 71 72 73
function loadSampleUiModel (src) { return fs.readFile(ospath.join(src, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents)) } function registerPartials (src) { return vfs.src('partials/*.hbs', { base: src, cwd: src }).pipe( map((file, enc, next) => { handlebars.registerPartial(file.stem, file.contents.toString()) next() })
+ 11 other calls in file
How does vinyl-fs.src work?
vinyl-fs.src is a function provided by the Vinyl-fs library used to read files from a source directory and create Vinyl file objects representing those files. When vinyl-fs.src is called, it takes as input a glob pattern or an array of glob patterns specifying which files to include. It then returns a stream of Vinyl file objects that can be manipulated and piped to other streams. The glob pattern is a way of specifying which files to include or exclude from the stream. The pattern can contain wildcards such as * and ** to match multiple files or directories, as well as negation patterns such as ! to exclude certain files or directories. By default, vinyl-fs.src reads files from the current working directory, but you can also specify a different directory by setting the cwd option. You can also set other options, such as base to specify the base directory for relative paths, and buffer to read files as buffers instead of streams. vinyl-fs.src is often used in Gulp or Grunt tasks to read files from a source directory and manipulate them in various ways. By returning a stream of Vinyl file objects, src makes it easy to pipe files to other streams, such as gulp.dest or gulp-rename, for further processing. vinyl-fs.src is a powerful and flexible function that can be used to read and manipulate files in a wide variety of use cases.
119 120 121 122 123 124 125 126 127 128
}), ].reduce((accum, it) => (it ? accum.concat(it) : accum), []) ) ), vfs.src('helpers/*.js', opts), vfs.src('layouts/*.hbs', opts), vfs.src('partials/*.hbs', opts) ).pipe(vfs.dest(dest, { sourcemaps: sourcemaps && '.' })) }
+ 19 other calls in file
229 230 231 232 233 234 235 236 237 238 239
return uiModel }) } function registerPartials (src) { return vfs.src('partials/**/*.hbs', { base: src, cwd: src }).pipe( map((file, enc, next) => { handlebars.registerPartial(file.stem, file.contents.toString()) next() })
+ 19 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const gulp = require("gulp"); const through2 = require("through2"); const vfs = require("vinyl-fs"); gulp.task("copy-js", () => { return vfs .src("src/**/*.js") .pipe( through2.obj((file, enc, cb) => { // Modify the file in some way file.contents = new Buffer('console.log("Hello, World!");'); cb(null, file); }) ) .pipe(vfs.dest("dist")); });
In this example, we first import the gulp, through2, and vinyl-fs modules. We then define a Gulp task called copy-js that uses vfs.src to read all .js files in the src directory and its subdirectories. We pipe the resulting stream of Vinyl file objects to a through2 transform stream that modifies the contents of each file by replacing it with a simple JavaScript snippet. We then pipe the modified stream to vfs.dest to write the modified files to the dist directory. By using vfs.src, we can easily read files from a source directory and pipe them to other streams for further processing. In this case, we use a through2 stream to modify the contents of each file, but we could also use other streams for tasks such as minification or bundling.
95 96 97 98 99 100 101 102 103 104
].reduce((accum, it) => (it ? accum.concat(it) : accum), []) ) ), vfs.src('helpers/*.js', opts), vfs.src('layouts/*.hbs', opts), vfs.src('partials/*.hbs', opts), vfs.src('static/**/*[!~]', { ...opts, base: ospath.join(src, 'static'), dot: true }) ).pipe(vfs.dest(dest, { sourcemaps: sourcemaps && '.' })) }
+ 34 other calls in file
vinyl-fs.src is the most popular function in vinyl-fs (335 examples)