Skip to content

Commit

Permalink
remove event-stream from the package, only used for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael J. Ryan committed Dec 13, 2018
1 parent 76934c2 commit df5af41
Show file tree
Hide file tree
Showing 5 changed files with 2,390 additions and 1,482 deletions.
27 changes: 16 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
'use strict';

/**
* Module dependencies.
*/
* Module dependencies.
*/

var Concat = require('concat-with-sourcemaps');
var through = require('through2');
Expand All @@ -13,16 +13,21 @@ var path = require('path');
var fs = require('fs');

/**
* gulp-header plugin
*/
* gulp-header plugin
*/

module.exports = function (headerText, data) {
module.exports = function(headerText, data) {
headerText = headerText || '';

function TransformStream(file, enc, cb) {
// format template
var filename = path.basename(file.path);
var template = data === false ? headerText : lodashTemplate(headerText)(Object.assign({}, file.data || {}, { file: file, filename: filename }, data));
var template =
data === false
? headerText
: lodashTemplate(headerText)(
Object.assign({}, file.data || {}, { file: file, filename: filename }, data)
);

if (file && typeof file === 'string') {
this.push(template + file);
Expand All @@ -38,7 +43,7 @@ module.exports = function (headerText, data) {
// handle file stream;
if (file.isStream()) {
var stream = through();
stream.write(new Buffer(template));
stream.write(Buffer.from(template));
stream.on('error', this.emit.bind(this, 'error'));
file.contents = file.contents.pipe(stream);
this.push(file);
Expand All @@ -49,7 +54,7 @@ module.exports = function (headerText, data) {
var concat = new Concat(true, filename);

// add template
concat.add(null, new Buffer(template));
concat.add(null, Buffer.from(template));

// add sourcemap
concat.add(file.relative, file.contents, file.sourceMap);
Expand All @@ -75,8 +80,8 @@ module.exports = function (headerText, data) {
};

/**
* is stream?
*/
* is stream?
*/
function isStream(obj) {
return obj instanceof stream.Stream;
}
Expand All @@ -91,6 +96,6 @@ function isExistingFile(file) {
if (file.isStream()) return true;
if (file.isBuffer()) return true;
if (typeof file.contents === 'string') return true;
} catch(err) {}
} catch (err) {}
return false;
}
Loading

0 comments on commit df5af41

Please sign in to comment.