-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: Utilize vinyl-prepare & vinyl-sourcemap dependencies (closes …
- Loading branch information
1 parent
40ac6e9
commit af035a5
Showing
16 changed files
with
241 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,28 @@ | ||
'use strict'; | ||
|
||
var through2 = require('through2'); | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
var duplexify = require('duplexify'); | ||
var valueOrFunction = require('value-or-function'); | ||
var pumpify = require('pumpify'); | ||
var prepare = require('vinyl-prepare'); | ||
|
||
var sink = require('../sink'); | ||
var prepareWrite = require('../prepare-write'); | ||
var writeContents = require('./write-contents'); | ||
var saveFile = require('./save-file'); | ||
var sourcemap = require('./sourcemap'); | ||
|
||
function dest(outFolder, opt) { | ||
if (!opt) { | ||
opt = {}; | ||
} | ||
|
||
var sourcemapsOpt = valueOrFunction( | ||
['boolean', 'string', 'object'], opt.sourcemaps); | ||
|
||
function saveFile(file, enc, callback) { | ||
prepareWrite(outFolder, file, opt, onPrepare); | ||
|
||
function onPrepare(prepareErr) { | ||
if (prepareErr) { | ||
return callback(prepareErr); | ||
} | ||
writeContents(file, callback); | ||
} | ||
} | ||
|
||
var saveStream = through2.obj(opt, saveFile); | ||
if (!sourcemapsOpt) { | ||
// Sink the save stream to start flowing | ||
// Do this on nextTick, it will flow at slowest speed of piped streams | ||
process.nextTick(sink(saveStream)); | ||
|
||
return saveStream; | ||
} | ||
|
||
if (typeof sourcemapsOpt === 'boolean') { | ||
sourcemapsOpt = {}; | ||
} else if (typeof sourcemapsOpt === 'string') { | ||
sourcemapsOpt = { | ||
path: sourcemapsOpt, | ||
}; | ||
} | ||
|
||
var mapStream = sourcemaps.write(sourcemapsOpt.path, sourcemapsOpt); | ||
var outputStream = duplexify.obj(mapStream, saveStream); | ||
mapStream.pipe(saveStream); | ||
var saveStream = pumpify.obj( | ||
prepare.dest(outFolder, opt), | ||
sourcemap(opt), | ||
saveFile(opt) | ||
); | ||
|
||
// Sink the output stream to start flowing | ||
// Do this on nextTick, it will flow at slowest speed of piped streams | ||
process.nextTick(sink(outputStream)); | ||
process.nextTick(sink(saveStream)); | ||
|
||
return outputStream; | ||
return saveStream; | ||
} | ||
|
||
module.exports = dest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
var through = require('through2'); | ||
var valueOrFunction = require('value-or-function'); | ||
|
||
var fo = require('../file-operations'); | ||
var writeContents = require('./write-contents'); | ||
|
||
var number = valueOrFunction.number; | ||
|
||
function saveFileStream(opt) { | ||
|
||
function saveFile(file, enc, callback) { | ||
// TODO: Can this be put on file.stat? | ||
var dirMode = number(opt.dirMode, file); | ||
|
||
fo.mkdirp(file.dirname, dirMode, onMkdirp); | ||
|
||
function onMkdirp(mkdirpErr) { | ||
if (mkdirpErr) { | ||
return callback(mkdirpErr); | ||
} | ||
writeContents(file, callback); | ||
} | ||
} | ||
|
||
return through.obj(saveFile); | ||
} | ||
|
||
module.exports = saveFileStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var through = require('through2'); | ||
var sourcemap = require('vinyl-sourcemap'); | ||
var valueOrFunction = require('value-or-function'); | ||
|
||
var stringOrBool = valueOrFunction.bind(null, ['string', 'boolean']); | ||
|
||
function sourcemapStream(opt) { | ||
|
||
function saveSourcemap(file, enc, callback) { | ||
var self = this; | ||
|
||
var srcMap = stringOrBool(opt.sourcemaps, file); | ||
|
||
if (!srcMap) { | ||
return callback(null, file); | ||
} | ||
|
||
var srcMapLocation = (typeof srcMap === 'string' ? srcMap : undefined); | ||
|
||
sourcemap.write(file, srcMapLocation, onWrite); | ||
|
||
function onWrite(sourcemapErr, updatedFile, sourcemapFile) { | ||
if (sourcemapErr) { | ||
return callback(sourcemapErr); | ||
} | ||
|
||
self.push(updatedFile); | ||
if (sourcemapFile) { | ||
self.push(sourcemapFile); | ||
} | ||
|
||
callback(); | ||
} | ||
} | ||
|
||
return through.obj(saveSourcemap); | ||
} | ||
|
||
module.exports = sourcemapStream; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,56 @@ | ||
'use strict'; | ||
|
||
var assign = require('object-assign'); | ||
var pumpify = require('pumpify'); | ||
var through2 = require('through2'); | ||
var gs = require('glob-stream'); | ||
var duplexify = require('duplexify'); | ||
var merge = require('merge-stream'); | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
var isValidGlob = require('is-valid-glob'); | ||
var valueOrFunction = require('value-or-function'); | ||
var koalas = require('koalas'); | ||
|
||
var filterSince = require('../filter-since'); | ||
var prepare = require('vinyl-prepare'); | ||
var sourcemap = require('./sourcemap'); | ||
var readContents = require('./read-contents'); | ||
var wrapWithVinylFile = require('./wrap-with-vinyl-file'); | ||
var resolveSymlinks = require('./resolve-symlinks'); | ||
|
||
var boolean = valueOrFunction.boolean; | ||
var date = valueOrFunction.date; | ||
|
||
function src(glob, opt) { | ||
if (!opt) { | ||
opt = {}; | ||
} | ||
|
||
var options = assign({}, opt, { | ||
buffer: koalas(boolean(opt.buffer), true), | ||
read: koalas(boolean(opt.read), true), | ||
since: date(opt.since), | ||
stripBOM: koalas(boolean(opt.stripBOM), true), | ||
sourcemaps: koalas(boolean(opt.sourcemaps), false), | ||
passthrough: koalas(boolean(opt.passthrough), false), | ||
followSymlinks: koalas(boolean(opt.followSymlinks), true), | ||
}); | ||
|
||
// Don't pass `read` option on to through2 | ||
var read = options.read !== false; | ||
options.read = undefined; | ||
|
||
var inputPass; | ||
|
||
if (!isValidGlob(glob)) { | ||
throw new Error('Invalid glob argument: ' + glob); | ||
} | ||
|
||
var globStream = gs.create(glob, options); | ||
var passthroughOpt = koalas(boolean(opt.passthrough), false); | ||
|
||
var outputStream = globStream | ||
.pipe(wrapWithVinylFile(options)); | ||
// Don't pass `read` option on to through2 | ||
opt.readFile = opt.read; | ||
opt.read = undefined; | ||
|
||
if (options.since != null) { | ||
outputStream = outputStream | ||
.pipe(filterSince(options.since)); | ||
} | ||
var inputStream; | ||
|
||
if (read) { | ||
outputStream = outputStream | ||
.pipe(readContents(options)); | ||
} | ||
var streams = [ | ||
gs.create(glob, opt), | ||
resolveSymlinks(opt), | ||
prepare.src(opt), | ||
readContents(opt), | ||
sourcemap(opt), | ||
]; | ||
|
||
if (options.passthrough === true) { | ||
inputPass = through2.obj(options); | ||
outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass)); | ||
} | ||
if (options.sourcemaps === true) { | ||
outputStream = outputStream | ||
.pipe(sourcemaps.init({ loadMaps: true })); | ||
var outputStream = pumpify.obj(streams); | ||
|
||
if (passthroughOpt) { | ||
inputStream = through2.obj(opt); | ||
outputStream = merge(outputStream, inputStream); | ||
outputStream = duplexify.obj(inputStream, outputStream); | ||
} | ||
globStream.on('error', outputStream.emit.bind(outputStream, 'error')); | ||
|
||
return outputStream; | ||
} | ||
|
||
|
||
module.exports = src; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.