metalsmith-jstransformer
Advanced tools
Comparing version 0.11.0 to 0.12.1
# Changelog | ||
## v0.12.1: 2018-01-10 | ||
- Updated dependencies | ||
## v0.12.0: 2017-05-25 | ||
- Update code standards | ||
## v0.11.0: 2017-05-10 | ||
@@ -4,0 +12,0 @@ |
82
index.js
@@ -1,11 +0,13 @@ | ||
var path = require('path') | ||
var jstransformer = require('jstransformer') | ||
var toTransformer = require('inputformat-to-jstransformer') | ||
var extend = require('extend') | ||
var async = require('async') | ||
var clone = require('clone') | ||
var minimatch = require('minimatch') | ||
'use strict' | ||
var transformers = {} | ||
const path = require('path') | ||
const jstransformer = require('jstransformer') | ||
const toTransformer = require('inputformat-to-jstransformer') | ||
const extend = require('extend') | ||
const async = require('async') | ||
const clone = require('clone') | ||
const minimatch = require('minimatch') | ||
const transformers = {} | ||
/** | ||
@@ -20,3 +22,3 @@ * Get the transformer from the given name. | ||
} | ||
var transformer = toTransformer(name) | ||
const transformer = toTransformer(name) | ||
transformers[name] = transformer ? jstransformer(transformer) : false | ||
@@ -33,3 +35,3 @@ return transformers[name] | ||
opts.engineOptions = opts.engineOptions || {} | ||
var defaultLayout = opts.defaultLayout | ||
let defaultLayout = opts.defaultLayout | ||
@@ -39,5 +41,5 @@ // Execute the plugin. | ||
// Retrieve all layouts. | ||
var templates = {} | ||
var filesKeys = Object.keys(files) | ||
var layouts = minimatch.match(filesKeys, opts.layoutPattern, {matchBase: true}) | ||
const templates = {} | ||
const filesKeys = Object.keys(files) | ||
const layouts = minimatch.match(filesKeys, opts.layoutPattern, {matchBase: true}) | ||
@@ -49,8 +51,8 @@ /** | ||
// Find which JSTransformer to compile with. | ||
var transform = path.extname(layout).substring(1) | ||
let transform = path.extname(layout).substring(1) | ||
transform = getTransformer(transform) | ||
if (transform) { | ||
// Retrieve the options for the JSTransformer. | ||
var thefilename = path.join(metalsmith._directory, metalsmith._source, layout) | ||
var options = extend({}, opts.engineOptions[transform.name], files[layout], { | ||
const thefilename = path.join(metalsmith._directory, metalsmith._source, layout) | ||
const options = extend({}, opts.engineOptions[transform.name], files[layout], { | ||
filename: thefilename, | ||
@@ -61,4 +63,4 @@ root: metalsmith.source() | ||
// Compile the content. | ||
var content = files[layout].contents.toString() | ||
transform.compileAsync(content, options).then(function (results) { | ||
const content = files[layout].contents.toString() | ||
transform.compileAsync(content, options).then(results => { | ||
// Wire up the template for the layout. | ||
@@ -75,3 +77,3 @@ templates[layout] = results | ||
done() | ||
}, function (err) { | ||
}, err => { | ||
done(err) | ||
@@ -100,8 +102,8 @@ }) | ||
if (!(file in layouts)) { | ||
var layoutName = files[file].layout || defaultLayout | ||
let layoutName = files[file].layout || defaultLayout | ||
while (layoutName && templates[layoutName]) { | ||
// Build the options/locals. | ||
var thefilename = path.join(metalsmith._directory, metalsmith._source, layoutName) | ||
var transformName = templates[layoutName].transformName | ||
var locals = extend({}, metalsmith.metadata(), opts.engineLocals[transformName], files[layoutName], files[file], { | ||
const thefilename = path.join(metalsmith._directory, metalsmith._source, layoutName) | ||
const transformName = templates[layoutName].transformName | ||
const locals = extend({}, metalsmith.metadata(), opts.engineLocals[transformName], files[layoutName], files[file], { | ||
contents: files[file].contents.toString(), | ||
@@ -135,3 +137,3 @@ filename: thefilename, | ||
// Retrieve the transformer. | ||
var transformer = getTransformer(extension) | ||
const transformer = getTransformer(extension) | ||
@@ -141,4 +143,4 @@ // Process the extension until the transformation is done. | ||
// Construct the options. | ||
var engineOpts = opts.engineOptions[transformer.name] | ||
var options = extend({}, metalsmith.metadata(), engineOpts, files[file], { | ||
const engineOpts = opts.engineOptions[transformer.name] | ||
const options = extend({}, metalsmith.metadata(), engineOpts, files[file], { | ||
filename: metalsmith.source() + '/' + file, | ||
@@ -148,4 +150,4 @@ root: metalsmith.source() | ||
// Construct the locals. | ||
var engineLocals = opts.engineLocals[transformer.name] | ||
var locals = extend({}, metalsmith.metadata(), engineLocals, files[file], { | ||
const engineLocals = opts.engineLocals[transformer.name] | ||
const locals = extend({}, metalsmith.metadata(), engineLocals, files[file], { | ||
filename: metalsmith.source() + '/' + file, | ||
@@ -156,3 +158,3 @@ root: metalsmith.source() | ||
// Get the transformer to render the contents. | ||
transformer.renderAsync(files[file].contents.toString(), options, locals).then(function (result) { | ||
transformer.renderAsync(files[file].contents.toString(), options, locals).then(result => { | ||
// Allow providing the default output format. | ||
@@ -162,5 +164,5 @@ files[file].jstransformerOutputFormat = transformer.outputFormat | ||
files[file].jstransformerFilePath.pop() | ||
files[file].contents = new Buffer(result.body) | ||
files[file].contents = Buffer.from(result.body) | ||
done() | ||
}, function (err) { | ||
}, err => { | ||
files[file].jstransformerDone = true | ||
@@ -177,3 +179,3 @@ done(err) | ||
// Prepare the extension processing. | ||
var extensions = file.split('.') | ||
const extensions = file.split('.') | ||
files[file].jstransformerFilePath = clone(extensions) | ||
@@ -189,3 +191,3 @@ extensions.reverse().pop() | ||
function renameFile(file, done) { | ||
var filename = file | ||
let filename = file | ||
// Check if there is a potential filepath change. | ||
@@ -219,5 +221,5 @@ if (files[file].jstransformerFilePath) { | ||
// TODO: Clean up async function chain tree. | ||
// @todo Clean up async function chain tree. | ||
// Compile all layouts. | ||
async.map(layouts, compileLayout, function (err) { | ||
async.map(layouts, compileLayout, err => { | ||
if (err) { | ||
@@ -227,3 +229,3 @@ done(err) | ||
// Render all individual content. | ||
var contentFiles = [] | ||
let contentFiles = [] | ||
@@ -236,3 +238,3 @@ try { | ||
async.map(contentFiles, processFile, function (err) { | ||
async.map(contentFiles, processFile, err => { | ||
if (err) { | ||
@@ -242,3 +244,3 @@ done(err) | ||
// Render the content within the layouts. | ||
async.map(contentFiles, renderContent, function (err) { | ||
async.map(contentFiles, renderContent, err => { | ||
if (err) { | ||
@@ -248,3 +250,3 @@ done(err) | ||
// Delete the layout data. | ||
async.map(layouts, deleteFile, function (err) { | ||
async.map(layouts, deleteFile, err => { | ||
if (err) { | ||
@@ -254,3 +256,3 @@ done(err) | ||
// Now rename all the files. | ||
async.map(Object.keys(files), renameFile, function (err) { | ||
async.map(Object.keys(files), renameFile, err => { | ||
if (err) { | ||
@@ -257,0 +259,0 @@ done(err) |
{ | ||
"name": "metalsmith-jstransformer", | ||
"version": "0.11.0", | ||
"version": "0.12.1", | ||
"description": "Metalsmith JSTransformer Plugin", | ||
@@ -11,3 +11,3 @@ "files": [ | ||
"posttest": "npm run xo", | ||
"xo": "xo --space --no-semicolon --ignores=test/index.js" | ||
"xo": "xo --space --no-semicolon" | ||
}, | ||
@@ -28,8 +28,8 @@ "repository": { | ||
"dependencies": { | ||
"async": "^2.1.4", | ||
"clone": "^2.1.0", | ||
"extend": "^3.0.0", | ||
"inputformat-to-jstransformer": "^1.1.9", | ||
"async": "^2.6.0", | ||
"clone": "^2.1.1", | ||
"extend": "^3.0.1", | ||
"inputformat-to-jstransformer": "^1.2.1", | ||
"jstransformer": "~1.0.0", | ||
"minimatch": "^3.0.3" | ||
"minimatch": "^3.0.4" | ||
}, | ||
@@ -43,10 +43,10 @@ "devDependencies": { | ||
"jstransformer-styl": "*", | ||
"jstransformer-twig": "^1.2.0", | ||
"jstransformer-twig": "^1.4.0", | ||
"jstransformer-uglify-js": "*", | ||
"metalsmith": "2.*", | ||
"metalsmith-paths": "^3.0.1", | ||
"rimraf": "^2.5.4", | ||
"testit": "^2.1.2", | ||
"xo": "^0.17.1" | ||
"rimraf": "^2.6.2", | ||
"testit": "^3.0.0", | ||
"xo": "^0.18.2" | ||
} | ||
} |
@@ -5,2 +5,3 @@ # Metalsmith JSTransformer Plugin [![NPM version](https://img.shields.io/npm/v/metalsmith-jstransformer.svg)](https://www.npmjs.org/package/metalsmith-jstransformer) | ||
[![Dependency Status](https://david-dm.org/RobLoach/metalsmith-jstransformer.png)](https://david-dm.org/RobLoach/metalsmith-jstransformer) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/RobLoach/metalsmith-jstransformer.svg)](https://greenkeeper.io/) | ||
@@ -141,7 +142,7 @@ [Metalsmith](http://metalsmith.io) plugin to process files with any [JSTransformer](http://github.com/jstransformers). | ||
The pattern used to find your layouts. Defaults to `layouts/**`. | ||
The pattern used to find your layouts, from within the Metalsmith source directory. Defaults to `layouts/**`. | ||
### `.defaultLayout` | ||
If provided, will be used as the default layout for content that doesn't have a layout explicitly defined. Defaults to `null`. | ||
If provided, will be used as the default layout for content that doesn't have a layout explicitly defined. Needs to be the full path to the file, from the Metalsmith source directory. Defaults to `null`. | ||
@@ -148,0 +149,0 @@ ### `.engineOptions` |
17424
230
179
Updatedasync@^2.6.0
Updatedclone@^2.1.1
Updatedextend@^3.0.1
Updatedminimatch@^3.0.4