UNPKG

vinyl-fs-mock

Version:

A fake file system implementation, used for test code written based on vinyl and vinyl-fs. Including gulp plugins

82 lines (63 loc) 2.52 kB
(function() { var FSReadStream, File, FileSystem, FileSystemIterator, Readable, createReadStreamDeprecated, deprecate, pathUtil, _, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; pathUtil = require('path'); File = require('vinyl'); FileSystem = require('./FileSystem'); Readable = require('readable-stream/readable'); FileSystemIterator = require('./FileSystemIterator'); _ = require('lodash'); deprecate = require('util-deprecate'); FSReadStream = (function(_super) { __extends(FSReadStream, _super); function FSReadStream(fileSystem, iterator, defaults) { this.fileSystem = fileSystem; this.iterator = iterator; this.defaults = defaults != null ? defaults : {}; FSReadStream.__super__.constructor.call(this, { objectMode: true }); _.defaults(this.defaults, { cwd: this.fileSystem.fullpath(), base: this.fileSystem.fullpath() }); this.defaults.cwd = this.fileSystem.resolvePath(this.defaults.cwd); this.defaults.base = this.fileSystem.resolvePath(this.defaults.base); } FSReadStream.prototype.createFile = function(file) { return new File(_.merge({}, this.defaults, file, { contents: this.fileSystem.readFileAsBuffer(file.path) })); }; FSReadStream.prototype._read = function() { var path; path = this.iterator.next(); if (path != null) { return this.push(this.createFile(path)); } else { return this.push(null); } }; return FSReadStream; })(Readable); module.exports = FSReadStream; createReadStreamDeprecated = function(path) { var iterator; if (path == null) { path = '.'; } iterator = new FileSystemIterator(this, [], { cwd: path }); return new FSReadStream(this, iterator, { cwd: path }); }; FileSystem.prototype.createReadStream = deprecate(createReadStreamDeprecated, 'fileSystem.createReadStream is deprecated, use fileSystem.src instead.'); FileSystem.prototype.src = function(patterns, options) { var iterator; iterator = new FileSystemIterator(this, patterns, options); return new FSReadStream(this, iterator, options); }; }).call(this);