gulp-metalsmith
Advanced tools
Comparing version 0.2.0 to 0.2.2
@@ -26,4 +26,6 @@ var through = require('through2'); | ||
var m = metalsmith(opts.root || process.cwd()); | ||
(opts.use || []).forEach(m.use); | ||
var root = opts.root || process.cwd(); | ||
var m = metalsmith(root); | ||
prepareMiddleware().forEach(m.use); | ||
m.metadata(opts.metadata || {}); | ||
@@ -33,2 +35,7 @@ | ||
function prepareMiddleware() { | ||
var use = opts.use || []; | ||
return _.isFunction(use) ? [use] : use; | ||
} | ||
function transform(file, enc, cb) { | ||
@@ -40,9 +47,5 @@ if (file.isStream()) { | ||
if (file.isBuffer()) { | ||
try { | ||
var key = file.path.replace(file.base, ''); | ||
var contents = file.contents; | ||
add(key, contents); | ||
} catch (err) { | ||
emitError(err); | ||
} | ||
var key = file.path.replace(file.base, ''); | ||
var contents = file.contents; | ||
add(key, contents); | ||
} | ||
@@ -87,5 +90,12 @@ | ||
var parsed = JSON.parse(contents.toString()); | ||
var parsed = {}; | ||
try { | ||
parsed = JSON.parse(contents.toString()); | ||
} catch (err) { | ||
emitError(err); | ||
} | ||
if (!_.isPlainObject(parsed)) { | ||
throw new Error('JSON file should contain a single root object.'); | ||
emitError('JSON file should contain a single root object.'); | ||
} | ||
@@ -92,0 +102,0 @@ |
{ | ||
"name": "gulp-metalsmith", | ||
"version": "0.2.0", | ||
"version": "0.2.2", | ||
"description": "Lightweight gulp plugin for Metalsmith", | ||
@@ -8,3 +8,5 @@ "keywords": [ | ||
"gulp", | ||
"gulpplugin" | ||
"gulpplugin", | ||
"static site", | ||
"ssg" | ||
], | ||
@@ -11,0 +13,0 @@ "repository": "jelz/gulp-metalsmith", |
@@ -90,2 +90,12 @@ var test = require('tape'); | ||
test('Accept a single middleware function', function (t) { | ||
t.plan(1); | ||
prepare('index.html', { | ||
use: function () { | ||
t.pass(); | ||
} | ||
}); | ||
}); | ||
test('Add metadata from configuration options', function (t) { | ||
@@ -92,0 +102,0 @@ t.plan(3); |
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
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
195470
487
0