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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
9411
97
0
10
7
2
105
2
2
+ Addedbufferstreams@^0.0.2
+ Addedes6-promise@^2.0.1
+ Addedfs-readfile-promise@^1.1.0
+ Addedthrough2@^0.6.3
+ Addedtryit@^1.0.1
+ Addedbufferstreams@0.0.2(transitive)
+ Addedes6-promise@2.3.0(transitive)
+ Addedfs-readfile-promise@1.1.0(transitive)
+ Addedgraceful-fs@3.0.12(transitive)
+ Addednatives@1.1.6(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedthrough2@0.6.5(transitive)
+ Addedtryit@1.0.3(transitive)
- Removedevent-stream@*
- Removedduplexer@0.1.2(transitive)
- Removedevent-stream@4.0.1(transitive)
- Removedfrom@0.1.7(transitive)
- Removedmap-stream@0.0.7(transitive)
- Removedpause-stream@0.0.11(transitive)
- Removedsplit@1.0.1(transitive)
- Removedstream-combiner@0.2.2(transitive)
- Removedthrough@2.3.8(transitive)
Updatedgulp-util@^3.0.2
Updatedlodash@^2.4.1
Updatednode.extend@^1.1.2