package/LICENSE000644 0000002037 3560116604 010267 0ustar00000000 000000 Copyright 2014 Mario Gutierrez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/Makefile000644 0000000146 3560116604 010721 0ustar00000000 000000 lib/tap.js lib/tap.js.map: src/tap.coffee @npm run coffee -- --compile --bare --map --output lib src package/tests/base.test.coffee000644 0000001212 3560116604 013457 0ustar00000000 000000 fs = require 'fs' path = require 'path' gulp = require 'gulp' tap = require '../' tapTest = require 'tap' # helper function to get a path relative to the root getPath = (rel) -> path.resolve __dirname, '..', rel tapTest.test "change file.base twice will end with 'Error: no writecb in Transform classh' #5", (test) -> test.plan 1 fixturePath = getPath 'tests/fixtures/' gulp.src fixturePath + '/js.js' .pipe tap (file) -> file.old_base = file.base file.base += 'random-path/' .pipe tap (file) -> file.base = file.old_base .pipe tap (file) -> test.ok true test.end() package/tests/dest.test.coffee000644 0000004170 3560116604 013512 0ustar00000000 000000 fs = require 'fs' path = require 'path' gulp = require 'gulp' tap = require '../' tapTest = require 'tap' deleteDirectory = (p) -> if fs.existsSync p fs.readdirSync(p).forEach (file) -> curP = (p + '/' + file) if fs.lstatSync(curP).isDirectory() deleteDirectory curP else fs.unlinkSync curP fs.rmdirSync p clean = -> deleteDirectory 'assets' deleteDirectory 'scripts' deleteDirectory 'sass' # helper function to get a path relative to the root getPath = (rel) -> path.resolve __dirname, '..', rel tapTest.test "gulp-tap can change dest in the middle of stream", (test) -> test.tearDown(clean) test.plan 3 destinations = 'scss': 'sass' 'js': 'scripts' 'img': 'assets/images' fixturePath = getPath 'tests/fixtures/' where = (file, t) -> match = (p) -> ext = (path.extname p) .substr 1 # remove leading '.' if( ext in ['jpg', 'png', 'svg', 'gif'] ) ext = 'img' destinations[ext] or false # for debugging # console.log 'destPath', destPath, file.path destPath = match file.path if destPath t.through gulp.dest, [destPath] fs.readdir fixturePath, (err, files) -> if err console.trace('Can not read fixtures from ' + fixturePath) test.end() gulp.src files.map (p) -> (fixturePath + '/' + p) .pipe tap where .on 'end', -> setTimeout (-> test.ok fs.existsSync getPath 'assets/images/img.png' test.ok fs.existsSync getPath 'scripts/js.js' test.ok fs.existsSync getPath 'sass/s.scss' test.end() ), 500 # give gulp.dest a (500ms) chance to write the files .on 'error', (err) -> console.trace(err) test.end() .pipe tap(->) # We must provide a pipe to make stream end ### stub for https://github.com/geejs/gulp-tap/issues/3 exports.sameIOFileName = 'test for infinite loop, issue #3': (test) -> test.plan 1 fixturePath = getPath 'tests/fixtures/' gulp.src fixturePath + '/*' test.ok true test.end()### package/src/tap.coffee000644 0000002777 3560116604 012021 0ustar00000000 000000 'use strict' baseStream = require('stream') through = require('through2') DEBUG = process.env.NODE_ENV is 'development' ### # Taps into the pipeline and allows user to easily route data through # another stream or change content. ### module.exports = (lambda) -> utils = (tapStream, file) -> ### # Routes through another stream. The filter must not be # created. This will create the filter as needed. # # @param filter {stream} # @param args {Array} Array containg arguments to apply to filter. # # @example # t.through coffee, [{bare: true}] ### through: (filter, args) -> if DEBUG if not Array.isArray(args) throw new TypeError("Args must be an array to `apply` to the filter") stream = filter.apply(null, args) stream.on "error", (err) -> tapStream.emit "error", err # Use original stream pipe file when emit `end/data` event # stream.pipe tapStream stream.write file stream modifyFile = (file, enc, cb) -> inst = file: file obj = lambda(inst.file, utils(this, inst.file), inst) next = () => this.push(file) cb() # if user returned a stream # passthrough when the stream is ended if obj instanceof baseStream and not obj._readableState.ended obj.on('end', next) obj.on('data', data = -> obj.removeListener 'end', next obj.removeListener 'data', data next()) else next() return through.obj(modifyFile, (cb) -> cb()) package/tests/throws.test.coffee000644 0000002037 3560116604 014101 0ustar00000000 000000 process.env['NODE_ENV'] = 'development' fs = require 'fs' path = require 'path' gulp = require 'gulp' tap = require '../' tapTest = require 'tap' # helper function to get a path relative to the root getPath = (rel) -> path.resolve __dirname, '..', rel identity = (x) -> x tapTest.test "throw errors", (test) -> test.plan 2 gulp.src getPath 'tests/fixtures/' + 'js.js' .pipe tap (file, t) -> test.throws t.through.bind(null, gulp.dest, "wrong"), new TypeError("Args must be an array to `apply` to the filter") gulp.src getPath 'tests/fixtures/' + 'js.js' .pipe tap (file, t) -> test.throws t.through.bind(null, identity, ["right"]), {}, "should throw if supplied function doesn't return a stream'" ### Giving up due to lack of knowledge about vinyl-fs streams - I don't know how to get them to emit an error tapTest.test "emit errors from stream errors", (test) -> test.plan 1 gulp.src getPath 'tests/fixtures/' + 'js.js' .pipe tap (file, t) -> test.doesNotThrow t.through.bind(null, gulp.src, ['non-existing.txt'])### package/index.js000644 0000000052 3560116604 010722 0ustar00000000 000000 module.exports = require('./lib/tap.js'); package/tests/fixtures/js.js000644 0000000026 3560116604 013243 0ustar00000000 000000 I'm a javascript file package/lib/tap.js000644 0000003547 3560116604 011161 0ustar00000000 000000 // Generated by CoffeeScript 1.12.5 'use strict'; var DEBUG, baseStream, through; baseStream = require('stream'); through = require('through2'); DEBUG = process.env.NODE_ENV === 'development'; /* * Taps into the pipeline and allows user to easily route data through * another stream or change content. */ module.exports = function(lambda) { var modifyFile, utils; utils = function(tapStream, file) { return { /* * Routes through another stream. The filter must not be * created. This will create the filter as needed. * * @param filter {stream} * @param args {Array} Array containg arguments to apply to filter. * * @example * t.through coffee, [{bare: true}] */ through: function(filter, args) { var stream; if (DEBUG) { if (!Array.isArray(args)) { throw new TypeError("Args must be an array to `apply` to the filter"); } } stream = filter.apply(null, args); stream.on("error", function(err) { return tapStream.emit("error", err); }); stream.write(file); return stream; } }; }; modifyFile = function(file, enc, cb) { var data, inst, next, obj; inst = { file: file }; obj = lambda(inst.file, utils(this, inst.file), inst); next = (function(_this) { return function() { _this.push(file); return cb(); }; })(this); if (obj instanceof baseStream && !obj._readableState.ended) { obj.on('end', next); return obj.on('data', data = function() { obj.removeListener('end', next); obj.removeListener('data', data); return next(); }); } else { return next(); } }; return through.obj(modifyFile, function(cb) { return cb(); }); }; //# sourceMappingURL=tap.js.map package/package.json000644 0000002103 3560116604 011542 0ustar00000000 000000 { "name": "gulp-tap", "version": "2.0.0", "description": "Easiest way to tap into a pipeline", "main": "index.js", "scripts": { "pretest": "coffee --compile --map tests", "test": "tap -J tests/*.js", "posttest": "rm tests/*.js tests/*.js.map", "test:cov": "npm test -- --cov", "coffee": "coffee", "dev": "coffee --watch --compile tests & coffee --watch --compile src" }, "repository": { "type": "git", "url": "https://github.com/geejs/gulp-tap" }, "keywords": [ "tap", "gulp", "stream" ], "authors": [ "Mario Gutierrez ", "Rubén Salvador García San Juan ", "Jon Ege Ronnenberg ", "Javey " ], "license": "MIT", "bugs": { "url": "https://github.com/geejs/gulp-tap/issues" }, "homepage": "https://github.com/geejs/gulp-tap", "dependencies": { "through2": "^3.0.1" }, "devDependencies": { "coffee-script": "^1.12.4", "coveralls": "^3.0.5", "gulp": "^4.0.2", "tap": "^14.4.1" } } package/lib/tap.js.map000644 0000002620 3560116604 011724 0ustar00000000 000000 { "version": 3, "file": "tap.js", "sourceRoot": "..", "sources": [ "src/tap.coffee" ], "names": [], "mappings": ";AAAA;AAAA,IAAA;;AAEA,UAAA,GAAa,OAAA,CAAQ,QAAR;;AACb,OAAA,GAAU,OAAA,CAAQ,UAAR;;AAEV,KAAA,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mB,MAAnB,EAA2B,IAA3B;eACA,IAAA,CAAA;MAHoB,CAAtB,EAHF;KAAA,MAAA;aAQE,IAAA,CAAA,EARF;;EAVW;AAoBb,SAAO,OAAO,CAAC,GAAR,CAAY,UAAZ,EAAwB,SAAC,EAAD;WAAQ,EAAA,CAAA;EAAR,CAAxB;AAjDQ" }package/README.md000644 0000002515 3560116604 010542 0ustar00000000 000000 # gulp-tap [![Build Status](https://travis-ci.org/geejs/gulp-tap.svg?branch=master)](https://travis-ci.org/geejs/gulp-tap) [![Coverage Status](https://coveralls.io/repos/github/geejs/gulp-tap/badge.svg?branch=master)](https://coveralls.io/github/geejs/gulp-tap?branch=master) [![Dependencies Status](https://david-dm.org/geejs/gulp-tap.svg)](https://david-dm.org/geejs/gulp-tap) Easily tap into a pipeline. ## Install `npm install gulp-tap --save-dev` ## Uses Some filters like `gulp-coffee` process all files. What if you want to process all JS and Coffee files in a single pipeline. Use `tap` to filter out `.coffee` files and process them through the `coffee` filter and let JavaScript files pass through. ```js gulp.src("src/**/*.{coffee,js}") .pipe(tap(function(file, t) { if (path.extname(file.path) === '.coffee') { return t.through(coffee, []); } })) .pipe(gulp.dest('build')); ``` What if you want to change content like add a header? No need for a separate filter, just change the content. ```js tap(function(file) { file.contents = Buffer.concat([ new Buffer('HEADER'), file.contents ]); }); ``` If you do not return a stream, tap forwards your changes. ## Examples See [Wiki](https://github.com/geejs/gulp-tap/wiki) for more examples. ## License The MIT License (MIT) package/tests/fixtures/img.png000644 0000000022 3560116604 013547 0ustar00000000 000000 I'm an image file package/tests/fixtures/s.scss000644 0000000020 3560116604 013422 0ustar00000000 000000 I'm a SASS file package/.travis.yml000644 0000000076 3560116604 011374 0ustar00000000 000000 language: node_js node_js: - "node" - "lts/*" cache: yarn