-
Notifications
You must be signed in to change notification settings - Fork 12
Home
Atlas Cove edited this page Feb 15, 2020
·
7 revisions
Tap into the Gulp pipeline and console.log
the string of what's being passed through
const tap = require('gulp-tap')
const log = require('fancy-log')
.pipe(tap(function (file, t) {
log(file.contents.toString())
}))
Tap into Gulp pipeline, convert Buffer to string, perform operations on it and replace the stream with the new results.
const tap = require('gulp-tap')
.pipe(tap(function (file) {
file.contents = Buffer.from(yourFunction(file.contents.toString()))
}))
A yourFunction
could be any function that reads string and outputs string. For example it could replace all occurrences of string zzz
with yyy
:
function yourFunction (input) {
return input.replace(/zzz/g, 'yyy')
}
var destinations = {
"scss": "sass",
"js": "scripts",
"img": "assets/images"
};
var files = ["loongpath/s.scss", "another/js.js", "verylongpath/img.png"]
gulp.src(files).pipe(tap(where))
function where(file, t) {
var destPath, match
match = function(p) {
var ext
ext = path.extname(p).substr(1); // remove leading "."
if ((ext === "jpg" || ext === "png" || ext === "svg" || ext === "gif")) {
ext = "img"
}
return destinations[ext] || false
}
destPath = match(file.path)
if (destPath) {
return t.through(gulp.dest, [destPath])
}
}