diff --git a/README.md b/README.md index 001bd197..703619d1 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,8 @@ fs.src(['*.js', '!b*.js']) ``` - Possible options for the second argument: - - cwd - Specify the working directory the folder is relative to. Default is `process.cwd()` + - cwd - Specify the working directory the folder is relative to. + - Default is `process.cwd()` - base - Specify the folder relative to the cwd. Default is where the glob begins. This is used to determine the file names when saving in `.dest()` - buffer - `true` or `false` if you want to buffer the file. - Default value is `true` @@ -60,6 +61,9 @@ fs.src(['*.js', '!b*.js']) - `false` will disable writing the file to disk via `.dest()` - since - `Date` or `number` if you only want files that have been modified since the time specified. - passthrough - `true` or `false` if you want a duplex stream which passes items through and emits globbed files. + - Default is `false`. + - sourcemaps - `true` or `false` if you want files to have sourcemaps enabled. + - Default is `false`. - Any glob-related options are documented in [glob-stream] and [node-glob] - Returns a Readable stream by default, or a Duplex stream if the `passthrough` option is set to `true`. - This stream emits matching [vinyl] File objects diff --git a/lib/src/index.js b/lib/src/index.js index 1f2616b1..8cd13ac2 100644 --- a/lib/src/index.js +++ b/lib/src/index.js @@ -6,8 +6,9 @@ var gs = require('glob-stream'); var File = require('vinyl'); var duplexify = require('duplexify'); var merge = require('merge-stream'); - +var sourcemaps = require('gulp-sourcemaps'); var filterSince = require('vinyl-filter-since'); + var getContents = require('./getContents'); var resolveSymlinks = require('./resolveSymlinks'); @@ -18,7 +19,9 @@ function createFile(globFile, enc, cb) { function src(glob, opt) { var options = assign({ read: true, - buffer: true + buffer: true, + sourcemaps: false, + passthrough: false }, opt); var pass, inputPass; @@ -40,7 +43,7 @@ function src(glob, opt) { .pipe(resolveSymlinks()) .pipe(through.obj(createFile)); - if (options.since) { + if (options.since != null) { outputStream = outputStream .pipe(filterSince(options.since)); } @@ -50,11 +53,15 @@ function src(glob, opt) { .pipe(getContents(options)); } - if (options.passthrough) { + if (options.passthrough === true) { inputPass = through.obj(); outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass)); } - + if (options.sourcemaps === true) { + outputStream = outputStream + .pipe(sourcemaps.init({loadMaps: true})); + } + globStream.on('error', outputStream.emit.bind(outputStream, 'error')); return outputStream; } diff --git a/package.json b/package.json index 2915ef1b..978eabb5 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "glob-stream": "^5.0.0", "glob-watcher": "^2.0.0", "graceful-fs": "^3.0.0", + "gulp-sourcemaps": "^1.5.2", "merge-stream": "^0.1.7", "mkdirp": "^0.5.0", "object-assign": "^2.0.0",