metalsmith-default-values
Advanced tools
Comparing version 0.0.2 to 1.0.0
'use strict'; | ||
var debug = require('debug')('metalsmith-set-defaults'); | ||
var debug_lib = require('debug'); | ||
var debug = debug_lib('metalsmith-set-defaults'); | ||
var error = debug_lib('metalsmith-set-defaults:error'); | ||
var multimatch = require('multimatch'); | ||
@@ -10,3 +12,3 @@ var Joi = require('joi'); | ||
Joi.object().keys({ | ||
pattern : [Joi.string(), Joi.array().min(1)], | ||
pattern : [Joi.array().min(1), Joi.string()], | ||
defaults: Joi.object().min(1) | ||
@@ -25,18 +27,32 @@ }) | ||
// Check config fits schema | ||
schema.validate(config, function (err) { | ||
var schema_err; | ||
schema.validate(config, function (err, value) { | ||
if (err) { | ||
return done(err); | ||
error('Validation failed, %o', err.details[0].message); | ||
schema_err = err; | ||
} | ||
// Convert string patterns to be in an array for multimatch | ||
config = value.map(function (item) { | ||
item.pattern = item.pattern || '*'; | ||
item.pattern = (typeof item.pattern === 'string') ? [item.pattern] : item.pattern; | ||
return item; | ||
}); | ||
}); | ||
if (schema_err) { | ||
return done(schema_err); | ||
} | ||
debug('config: ', config); | ||
// Loop through files | ||
Object.keys(files).forEach(function (file) { | ||
// Loop through configurations | ||
config.forEach(function (item) { | ||
item.pattern = item.pattern || '*'; | ||
if (!item.set_defaults) { | ||
// initialise set_defaults function | ||
item.set_defaults = set_defaults(item.defaults); | ||
} | ||
debug('Checking: %s; Against: %s', file, item.pattern); | ||
if (multimatch(file, item.pattern).length) { | ||
debug('Passed - Will set defaults if required'); | ||
if (!item.set_defaults) { | ||
// initialise set_defaults function | ||
item.set_defaults = set_defaults(item.defaults); | ||
} | ||
@@ -49,3 +65,3 @@ // Set defaults if required | ||
done(); | ||
return done(); | ||
}; | ||
@@ -52,0 +68,0 @@ }; |
{ | ||
"name": "metalsmith-default-values", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"description": "A metalsmith plugin for setting default values for frontmatter metadata.", | ||
@@ -13,9 +13,10 @@ "dependencies": { | ||
"devDependencies": { | ||
"eslint": "latest", | ||
"tape": "latest", | ||
"nodemon": "latest" | ||
"eslint": "^2.10.2", | ||
"nodemon": "latest", | ||
"tape": "^4.6.0", | ||
"taper": "^0.5.0" | ||
}, | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "node test", | ||
"test": "taper test", | ||
"posttest": "npm run lint", | ||
@@ -22,0 +23,0 @@ "lint": "eslint --ignore-pattern node_modules **/*.js", |
# metalsmith-default-values | ||
[![npm version][npm-badge]][npm-url] | ||
[![Build Status][travis-badge]][travis-url] | ||
[![bitHound Dependencies][bithound-badge]][bithound-url] | ||
Metalsmith Plugin for setting default frontmatter metadata | ||
Metalsmith Plugin for setting default front-matter metadata | ||
@@ -18,3 +19,3 @@ ## Installation | ||
```js | ||
var default_values = require('./modules/default_values.js'); | ||
var default_values = require('metalsmith-default_values'); | ||
``` | ||
@@ -56,3 +57,7 @@ | ||
[npm-url]: https://www.npmjs.com/package/metalsmith-default-values | ||
[travis-badge]: https://travis-ci.org/woodyrew/metalsmith-default-values.svg?branch=master | ||
[travis-url]: https://travis-ci.org/woodyrew/metalsmith-default-values | ||
[bithound-badge]: https://www.bithound.io/github/woodyrew/metalsmith-default-values/badges/dependencies.svg | ||
[bithound-url]: https://www.bithound.io/github/woodyrew/metalsmith-default-values/master/dependencies/npm |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
47129
160
0
62
4