metalsmith-jstransformer
Advanced tools
Comparing version 0.13.0 to 0.13.2
# Changelog | ||
## v0.13.0: Unreleased | ||
## v0.13.2: 2018-05-17 | ||
- [#38](https://github.com/kalamuna/metalsmith-jstransformer/pull/38) Catch exceptions from JSTransformer compileAsync and renderAsync | ||
- By [@ycherniavsky](https://github.com/ycherniavsky) | ||
- Updated dependencies | ||
@@ -6,0 +8,0 @@ - Fixed repo URL |
68
index.js
@@ -0,1 +1,2 @@ | ||
/* eslint valid-jsdoc: 0 */ | ||
'use strict' | ||
@@ -34,3 +35,3 @@ | ||
opts.engineOptions = opts.engineOptions || {} | ||
let defaultLayout = opts.defaultLayout | ||
let defaultLayout = opts.defaultLayout // eslint-disable-line prefer-destructuring | ||
@@ -60,4 +61,10 @@ // Execute the plugin. | ||
// Compile the content. | ||
const content = files[layout].contents.toString() | ||
transform.compileAsync(content, options).then(results => { | ||
let compiling | ||
try { | ||
// In some condition jstransformer compileAsync can throw excepton. | ||
compiling = transform.compileAsync(files[layout].contents.toString(), options) | ||
} catch (err) { | ||
return done(err) | ||
} | ||
compiling.then(results => { | ||
// Wire up the template for the layout. | ||
@@ -102,3 +109,3 @@ templates[layout] = results | ||
const thefilename = path.join(metalsmith._directory, metalsmith._source, layoutName) | ||
const transformName = templates[layoutName].transformName | ||
const transformName = templates[layoutName].transformName // eslint-disable-line prefer-destructuring | ||
const locals = extend({}, metalsmith.metadata(), opts.engineLocals[transformName], files[layoutName], files[file], { | ||
@@ -150,4 +157,11 @@ contents: files[file].contents.toString(), | ||
// Get the transformer to render the contents. | ||
transformer.renderAsync(files[file].contents.toString(), options, locals).then(result => { | ||
// Render the contents. | ||
let rendering | ||
try { | ||
// In some condition jstransformer renderAsync can throw excepton. | ||
rendering = transformer.renderAsync(files[file].contents.toString(), options, locals) | ||
} catch (err) { | ||
return done(err) | ||
} | ||
rendering.then(result => { | ||
// Allow providing the default output format. | ||
@@ -228,28 +242,24 @@ files[file].jstransformerOutputFormat = transformer.outputFormat | ||
if (err) { | ||
done(err) | ||
} else { | ||
// Render the content within the layouts. | ||
async.map(contentFiles, renderContent, err => { | ||
return done(err) | ||
} | ||
// Render the content within the layouts. | ||
async.map(contentFiles, renderContent, err => { | ||
if (err) { | ||
return done(err) | ||
} | ||
// Delete the layout data. | ||
async.map(layouts, deleteFile, err => { | ||
if (err) { | ||
done(err) | ||
} else { | ||
// Delete the layout data. | ||
async.map(layouts, deleteFile, err => { | ||
if (err) { | ||
done(err) | ||
} else { | ||
// Now rename all the files. | ||
async.map(Object.keys(files), renameFile, err => { | ||
if (err) { | ||
done(err) | ||
} else { | ||
// Now delete auxiliary metadata from files. | ||
async.map(Object.keys(files), deleteAuxiliaryMetadata, done) | ||
} | ||
}) | ||
} | ||
}) | ||
return done(err) | ||
} | ||
// Now rename all the files. | ||
async.map(Object.keys(files), renameFile, err => { // eslint-disable-line max-nested-callbacks | ||
if (err) { | ||
return done(err) | ||
} | ||
// Now delete auxiliary metadata from files. | ||
async.map(Object.keys(files), deleteAuxiliaryMetadata, done) | ||
}) | ||
}) | ||
} | ||
}) | ||
}) | ||
@@ -256,0 +266,0 @@ } |
{ | ||
"name": "metalsmith-jstransformer", | ||
"version": "0.13.0", | ||
"version": "0.13.2", | ||
"description": "Metalsmith JSTransformer Plugin", | ||
@@ -47,4 +47,4 @@ "files": [ | ||
"testit": "^3.0.0", | ||
"xo": "^0.20.3" | ||
"xo": "^0.21.0" | ||
} | ||
} |
18048
240