gulp-nunjucks-api
Advanced tools
Comparing version 0.8.0 to 0.9.1
78
index.js
@@ -6,3 +6,2 @@ 'use strict'; | ||
var glob = require('glob'); | ||
var gutil = require('gulp-util'); | ||
var assign = require('lodash/assign'); | ||
@@ -13,4 +12,7 @@ var cloneDeep = require('lodash/cloneDeep'); | ||
var path = require('path'); | ||
var pluginError = require('plugin-error'); | ||
var requireNew = require('require-new'); | ||
var through = require('through2'); | ||
var fancyLog = require('fancy-log'); | ||
var replaceExt = require('replace-ext'); | ||
@@ -123,3 +125,2 @@ // #region Configuration | ||
config.verbose = options.verbose || config.verbose; | ||
config.vlog = config.verbose ? log : returnGulpUtil; | ||
delete options.verbose; | ||
@@ -146,17 +147,18 @@ } | ||
function createError(message, opt) { | ||
return new gutil.PluginError(PLUGIN_NAME, message, opt); | ||
return new pluginError(PLUGIN_NAME, message, opt); | ||
} | ||
function handleError(config, sender, err, cb, opt) { | ||
config.vlog('Handling error: ' + err); | ||
if (config.verbose) { | ||
fancyLog.info('Handling error: ' + err); | ||
} | ||
var pluginErr = createError(err, opt); | ||
if (config.errors) | ||
if (config.errors) { | ||
sender.emit('error', pluginErr); | ||
} | ||
return cb(pluginErr); | ||
} | ||
function log(message) { | ||
return gutil.log.apply(gutil, arguments); | ||
} | ||
function requireFile(config, filepath, result) { | ||
@@ -170,3 +172,3 @@ if (filepath === undefined || filepath === null) | ||
catch (err) { | ||
config.vlog('File not found: ' + filepath); | ||
fancyLog.error('File not found: ' + filepath); | ||
} | ||
@@ -186,3 +188,6 @@ return false; | ||
var pattern = locals; | ||
config.vlog('Searching for locals with pattern:', pattern, 'in:', searchpath); | ||
if (config.verbose) { | ||
fancyLog.info('Searching for locals with pattern:', pattern, 'in:', searchpath); | ||
} | ||
var options = { | ||
@@ -194,6 +199,12 @@ cwd: searchpath, | ||
var i, fullpath, result; | ||
config.vlog('Found:', found.length, 'locals files.'); | ||
if (config.verbose) { | ||
fancyLog.info('Found:', found.length, 'locals files.'); | ||
} | ||
for (i = 0; i < found.length; i++) { | ||
fullpath = path.resolve(searchpath, found[i]); | ||
config.vlog('Using locals file:', found[i], 'fullpath:', fullpath); | ||
if (config.verbose) { | ||
fancyLog.info('Using locals file:', found[i], 'fullpath:', fullpath); | ||
} | ||
result = {}; | ||
@@ -218,17 +229,30 @@ if (requireFile(config, fullpath, result)) | ||
} | ||
if (file.isStream()) | ||
if (file.isStream()) { | ||
return handleError(config, _this, 'Streaming not supported', cb); | ||
if (file.data) | ||
} | ||
if (file.data) { | ||
assign(context, file.data); | ||
if (config.locals) | ||
} | ||
if (config.locals) { | ||
assignLocals(context, config, file); | ||
config.vlog('Rendering nunjucks file.path:', file.path); | ||
} | ||
if (config.verbose) { | ||
fancyLog.info('Rendering nunjucks file.path:', file.path); | ||
} | ||
if (config.renderString) { | ||
env.renderString(file.contents.toString(), context, function(err, result) { | ||
if (err) | ||
if (err) { | ||
return handleError(config, _this, err, cb); | ||
} | ||
file.contents = new Buffer(result); | ||
if (config.extension !== 'inherit') | ||
file.path = gutil.replaceExtension(file.path, config.extension); | ||
if (config.extension !== 'inherit'){ | ||
file.path = replaceExt(file.path, config.extension); | ||
} | ||
_this.push(file); | ||
@@ -239,7 +263,11 @@ cb(); | ||
env.render(file.path, context, function (err, result) { | ||
if (err) | ||
if (err){ | ||
return handleError(config, _this, err, cb); | ||
} | ||
file.contents = new Buffer(result); | ||
if (config.extension !== 'inherit') | ||
file.path = gutil.replaceExtension(file.path, config.extension); | ||
if (config.extension !== 'inherit') { | ||
file.path = replaceExt(file.path, config.extension); | ||
} | ||
_this.push(file); | ||
@@ -271,5 +299,1 @@ cb(); | ||
plugin.nunjucks = nunjucks; | ||
function returnGulpUtil() { | ||
return gutil; | ||
} |
{ | ||
"name": "gulp-nunjucks-api", | ||
"version": "0.8.0", | ||
"version": "0.9.1", | ||
"description": "Render Nunjucks templates with data, custom filters, custom context functions and options for other Nunjucks API features.", | ||
@@ -31,6 +31,8 @@ "license": "MIT", | ||
"dependencies": { | ||
"fancy-log": "^1.3.3", | ||
"glob": "^7.0.3", | ||
"gulp-util": "^3.0.7", | ||
"lodash": "^4.10.0", | ||
"nunjucks": "^2.4.1", | ||
"nunjucks": "^3.0.0", | ||
"plugin-error": "^1.0.1", | ||
"replace-ext": "^1.0.0", | ||
"require-new": "^1.1.0", | ||
@@ -40,4 +42,5 @@ "through2": "^2.0.1" | ||
"devDependencies": { | ||
"mocha": "^2.4.5", | ||
"should": "^8.3.0" | ||
"mocha": "^6.0.0", | ||
"should": "^8.3.0", | ||
"vinyl": "^2.2.0" | ||
}, | ||
@@ -44,0 +47,0 @@ "readmeFilename": "readme.md", |
@@ -0,3 +1,11 @@ | ||
<p align="center"> | ||
<a href="http://gulpjs.com"> | ||
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png"> | ||
</a> | ||
</p> | ||
# gulp-nunjucks-api | ||
[![npm version][npm-badge]][npm] [![npm downloads][npd-badge]][npm] [![dependencies Status][dps-badge]][dps] | ||
> Render [Nunjucks](https://mozilla.github.io/nunjucks/) templates with data, | ||
@@ -152,1 +160,7 @@ custom filters, custom context functions and options for other Nunjucks API | ||
Nunjucks templates. | ||
[npm-badge]: https://img.shields.io/npm/v/gulp-nunjucks-api?style=flat | ||
[npd-badge]: https://img.shields.io/npm/dm/gulp-nunjucks-api.svg?style=flat-square | ||
[dps-badge]: https://david-dm.org/waynebloss/gulp-nunjucks-api/status.svg | ||
[dps]: https://david-dm.org/waynebloss/gulp-nunjucks-api | ||
[npm]: https://www.npmjs.com/package/gulp-nunjucks-api |
Sorry, the diff of this file is not supported yet
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
15479
238
165
8
3
1
1
+ Addedfancy-log@^1.3.3
+ Addedplugin-error@^1.0.1
+ Addedreplace-ext@^1.0.0
+ Addeda-sync-waterfall@1.0.1(transitive)
+ Addedansi-colors@1.1.0(transitive)
+ Addedcommander@5.1.0(transitive)
+ Addednunjucks@3.2.4(transitive)
+ Addedplugin-error@1.0.1(transitive)
+ Addedreplace-ext@1.0.1(transitive)
- Removedgulp-util@^3.0.7
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedanymatch@1.3.2(transitive)
- Removedarr-diff@2.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedarray-unique@0.2.10.3.2(transitive)
- Removedasync-each@1.0.6(transitive)
- Removedatob@2.1.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedbinary-extensions@1.13.1(transitive)
- Removedbindings@1.5.0(transitive)
- Removedbraces@1.8.52.3.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedchokidar@1.7.0(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcliui@3.2.0(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removeddateformat@2.2.0(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@0.2.51.0.02.0.2(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedexpand-brackets@0.1.52.1.4(transitive)
- Removedexpand-range@1.8.2(transitive)
- Removedextend-shallow@2.0.1(transitive)
- Removedextglob@0.3.22.0.4(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedfilename-regex@2.0.1(transitive)
- Removedfill-range@2.2.44.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedfsevents@1.2.13(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-value@2.0.6(transitive)
- Removedglob-base@0.3.0(transitive)
- Removedglob-parent@2.0.0(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-binary-path@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-dotfile@1.0.3(transitive)
- Removedis-equal-shallow@0.1.3(transitive)
- Removedis-extendable@0.1.1(transitive)
- Removedis-extglob@1.0.0(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedis-glob@2.0.1(transitive)
- Removedis-number@2.1.03.0.04.0.0(transitive)
- Removedis-posix-bracket@0.1.1(transitive)
- Removedis-primitive@2.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@0.0.1(transitive)
- Removedisobject@2.1.0(transitive)
- Removedkind-of@3.2.24.0.06.0.3(transitive)
- Removedlcid@1.0.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmath-random@1.0.4(transitive)
- Removedmicromatch@2.3.113.1.10(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedms@2.0.0(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removednan@2.22.0(transitive)
- Removednanomatch@1.2.13(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removednunjucks@2.5.2(transitive)
- Removedobject-assign@3.0.0(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.omit@2.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedparse-glob@3.0.4(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedpreserve@0.2.0(transitive)
- Removedrandomatic@3.1.1(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedreaddirp@2.2.1(transitive)
- Removedregex-cache@0.4.4(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedret@0.1.15(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedset-value@2.0.1(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
- Removedvinyl@0.5.3(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@3.32.0(transitive)
Updatednunjucks@^3.0.0