Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-wrap

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-wrap - npm Package Compare versions

Comparing version 0.9.0 to 0.10.0

158

index.js
'use strict';
var es = require('event-stream');
var gutil = require('gulp-util');
var path = require('path');
var BufferStreams = require('bufferstreams');
var consolidate = require('consolidate');
var fs = require('fs');
var extend = require('node.extend');
var PluginError = gutil.PluginError;
var PluginError = require('gulp-util').PluginError;
var ES6Promise = global.Promise || require('es6-promise').Promise;
var readFile = require('fs-readfile-promise');
var through = require('through2');
var tryit = require('tryit');
var PLUGIN_NAME = 'gulp-wrap';
function compile(file, contents, template, data, options, callback){
module.exports = function gulpWrap(opts, data, options) {
var promise;
if (typeof opts === 'object') {
if (typeof opts.src !== 'string') {
throw new PluginError(PLUGIN_NAME, new TypeError('Expecting `src` option.'));
}
promise = readFile(opts.src, 'utf8');
} else {
if (typeof opts !== 'string' && typeof opts !== 'function') {
throw new PluginError(PLUGIN_NAME, 'Template must be a string or a function.');
}
promise = ES6Promise.resolve(opts);
}
data = data || {};
options = options || {};

@@ -19,85 +38,78 @@

data = data || {};
data.contents = contents;
function gulpWrapTransform(file, enc, cb) {
var self = this;
// attempt to parse the file contents for JSON or YAML files
if (options.parse !== false) {
try {
if (file.path.match(/json$/)) {
data.contents = JSON.parse(contents);
} else if (file.path.match(/ya?ml$/)) {
data.contents = require('js-yaml').safeLoad(contents);
}
} catch (err) {
throw new PluginError(PLUGIN_NAME, PLUGIN_NAME + ': error parsing ' + file.path);
if (file.isNull()) {
cb(null, file);
return;
}
}
/*
* Add `file` field to source obj used when interpolating
* the template. Ensure the user supplied data object is not
* augmented to prevent file prop leakage across multiple
* streams. Properties specified in the user supplied data
* object should take precedence over properties supplied
* by the file.
*/
data = extend(true, { file: file }, file.data, data);
function compile(contents, done) {
// attempt to parse the file contents for JSON or YAML files
if (options.parse !== false) {
var ext = path.extname(file.path).toLowerCase();
/*
* Allow template to be a function, pass it the data object.
*/
if (typeof template === 'function') {
template = template(data);
}
data = extend(data, options);
tryit(function() {
if (ext === '.json') {
contents = JSON.parse(contents);
} else if (ext === '.yml' || ext === '.yaml') {
contents = require('js-yaml').safeLoad(contents);
}
}, function(err) {
if (!err) {
return;
}
throw new PluginError(PLUGIN_NAME, PLUGIN_NAME + ': error parsing ' + file.path);
});
}
consolidate[options.engine].render(template, data, callback);
}
var newData = extend({file: file}, options, data, file.data, {contents: contents});
module.exports = function(opts, data, options){
if (!opts) {
throw new PluginError(PLUGIN_NAME, PLUGIN_NAME + ': Missing template parameter');
}
promise.then(function(template) {
if (typeof template === 'function') {
template = template(newData);
}
var template;
if (typeof(opts) === 'object') {
template = fs.readFileSync(opts.src, 'utf-8');
} else {
template = opts;
}
function wrap(file, callback){
if (gutil.isStream(file.contents)) {
var through = es.through();
var wait = es.wait(function(err, contents){
compile(file, contents, template, data, options, function(compileErr, output) {
if (compileErr) {
callback(compileErr);
} else {
through.write(output);
through.end();
consolidate[options.engine].render(template, newData, function(err, result) {
if (err) {
done(new PluginError(PLUGIN_NAME, err));
return;
}
done(null, new Buffer(result));
});
});
}, done);
}
file.contents.pipe(wait);
file.contents = through;
callback(null, file);
} else if (gutil.isBuffer(file.contents)) {
compile(file, file.contents.toString('utf-8'), template, data, options, function(compileErr, output) {
if (compileErr) {
callback(compileErr);
if (file.isStream()) {
file.contents = file.contents.pipe(new BufferStreams(function(none, buf, done) {
compile(buf, function(err, contents) {
process.nextTick(function() {
if (err) {
self.emit('error', err);
done(err);
} else {
done(null, contents);
self.push(file);
}
cb();
});
});
}));
return;
}
compile(file.contents, function(err, contents) {
process.nextTick(function() {
if (err) {
self.emit('error', err);
} else {
file.contents = new Buffer(output);
callback(null, file);
file.contents = contents;
self.push(file);
}
cb();
});
} else {
callback(null, file);
}
});
}
return es.map(wrap);
return through.obj(gulpWrapTransform);
};
{
"name": "gulp-wrap",
"version": "0.9.0",
"description": "A gulp plugin to wrap the stream contents with a lodash template.",
"version": "0.10.0",
"description": "A gulp plugin to wrap the stream contents with a template.",
"repository": "adamayres/gulp-wrap",
"author": {
"name": "Adam Ayres",
"email": "magicaj@gmail.com",
"url": "https://github.com/adamayres"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/adamayres/gulp-wrap/blob/master/LICENSE"
}
],
"files": [
"index.js",
"LICENSE"
],
"scripts": {
"pretest": "jscs *.js test/test.js && eslint *.js test/test.js",
"test": "_mocha",
"coverage": "istanbul cover _mocha",
"coveralls": "${npm_package_scripts_coverage} && istanbul-coveralls"
},
"keywords": [

@@ -13,28 +35,22 @@ "gulpplugin",

],
"homepage": "https://github.com/adamayres/gulp-wrap",
"bugs": "https://github.com/adamayres/gulp-wrap/issues",
"author": {
"name": "Adam Ayres",
"email": "magicaj@gmail.com",
"url": "https://github.com/adamayres"
},
"main": "./index.js",
"repository": {
"type": "git",
"url": "git://github.com/adamayres/gulp-wrap.git"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"bufferstreams": "^0.0.2",
"consolidate": "^0.10.0",
"event-stream": "*",
"gulp-util": "~3.0.1",
"es6-promise": "^2.0.1",
"fs-readfile-promise": "^1.1.0",
"gulp-util": "^3.0.2",
"js-yaml": "^3.2.3",
"lodash": "~2.4.1",
"node.extend": "~1.1.2"
"lodash": "^2.4.1",
"node.extend": "^1.1.2",
"through2": "^0.6.3",
"tryit": "^1.0.1"
},
"devDependencies": {
"mocha": "~1.21.5",
"should": "~4.0.4"
"eslint": "^0.11.0",
"istanbul": "^0.3.5",
"istanbul-coveralls": "^1.0.1",
"jscs": "^1.10.0",
"mocha": "^2.1.0",
"simple-bufferstream": "0.0.4",
"vinyl": "^0.4.6"
},

@@ -45,7 +61,8 @@ "engines": {

},
"licenses": [
{
"type": "MIT"
}
]
"jscsConfig": {
"preset": "google",
"maximumLineLength": 98,
"requireBlocksOnNewline": true,
"validateLineBreaks": "LF"
}
}

@@ -1,3 +0,9 @@

# gulp-wrap [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
# gulp-wrap
[![NPM version](https://img.shields.io/npm/v/gulp-wrap.svg?style=flat)](https://www.npmjs.com/package/gulp-wrap)
[![Build Status](https://secure.travis-ci.org/adamayres/gulp-wrap.svg?branch=master)](http://travis-ci.org/adamayres/gulp-wrap)
[![Coverage Status](https://img.shields.io/coveralls/adamayres/gulp-wrap.svg?style=flat)](https://coveralls.io/r/adamayres/gulp-wrap)
[![Dependency Status](https://img.shields.io/david/adamayres/gulp-wrap.svg?style=flat&label=deps)](https://david-dm.org/adamayres/gulp-wrap)
[![devDependency Status](https://img.shields.io/david/dev/adamayres/gulp-wrap.svg?style=flat&label=devDeps)](https://david-dm.org/adamayres/gulp-wrap#info=devDependencies)
> A [gulp](https://github.com/gulpjs/gulp) plugin to wrap the stream contents with a [lodash](http://lodash.com/docs#template) template.

@@ -99,10 +105,1 @@

[MIT License](http://en.wikipedia.org/wiki/MIT_License)
[npm-url]: https://npmjs.org/package/gulp-wrap
[npm-image]: https://badge.fury.io/js/gulp-wrap.png
[travis-url]: http://travis-ci.org/adamayres/gulp-wrap
[travis-image]: https://secure.travis-ci.org/adamayres/gulp-wrap.png?branch=master
[depstat-url]: https://david-dm.org/adamayres/gulp-wrap
[depstat-image]: https://david-dm.org/adamayres/gulp-wrap.png
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc