Skip to content

Commit

Permalink
Return when done (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Apr 15, 2019
1 parent 011b215 commit 352c74a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = options => (files, metalsmith, done) => {

// Check whether the pattern option is valid
if (!(typeof settings.pattern === 'string' || Array.isArray(settings.pattern))) {
done(
return done(
new Error(
'invalid pattern, the pattern option should be a string or array of strings. See https://www.npmjs.com/package/metalsmith-layouts#pattern'
)
Expand All @@ -124,18 +124,19 @@ module.exports = options => (files, metalsmith, done) => {

// Let the user know when there are no files to process, unless the check is suppressed
if (validFiles.length === 0) {
const msg =
const message =
'no files to process. See https://www.npmjs.com/package/metalsmith-layouts#no-files-to-process';

if (settings.suppressNoFilesError) {
debug(msg);
done();
} else {
done(new Error(msg));
debug(message);
return done();
}

return done(new Error(message));
}

// Map all files that should be processed to an array of promises and call done when finished
Promise.all(
return Promise.all(
validFiles.map(filename => render({ filename, files, metadata, settings, metalsmith }))
)
.then(() => done())
Expand Down

0 comments on commit 352c74a

Please sign in to comment.