Skip to content

Commit

Permalink
Support Plugin return Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
dacsang97 committed Apr 24, 2018
1 parent c72bf9d commit 5cdb744
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 7 additions & 5 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const yamlParser = require('js-yaml')
const tomlParser = require('toml')
const createMarkdown = require('./markdown')
const tempPath = path.resolve(__dirname, 'app/.temp')
const { inferTitle, extractHeaders, parseFrontmatter, loadPlugin, isAsyncFunction } = require('./util')
const { inferTitle, extractHeaders, parseFrontmatter, loadPlugin } = require('./util')

fs.ensureDirSync(tempPath)

Expand Down Expand Up @@ -88,10 +88,12 @@ if (!Object.assign) Object.assign = require('object-assign')`
pluginRequired = pluginRequired(plugin.options)
}
}
if (isAsyncFunction(pluginRequired)) {
await pluginRequired(options)
} else {
pluginRequired(options)
if (pluginRequired) {
try {
await pluginRequired(options)
} catch (e) {
throw e
}
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,3 @@ exports.loadPlugin = (pluginPath, options) => {
}
return plugin
}

exports.isAsyncFunction = (func) => {
const AsyncFunction = (async () => {}).constructor
return (func instanceof AsyncFunction && AsyncFunction !== Function)
}

0 comments on commit 5cdb744

Please sign in to comment.