Skip to content

Commit

Permalink
Remove .renderSync(), .getTemplateDataSync() and .getJsdocDataSync().…
Browse files Browse the repository at this point in the history
… The jsdoc2md API is now async-only.

Fixed a bug where handlebars templates could be passed into the jsdoc-api template option
  • Loading branch information
75lb committed Aug 27, 2024
1 parent ddfacc8 commit 0605ec8
Show file tree
Hide file tree
Showing 7 changed files with 678 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [12, 14, 16, 18, 20, 22]
node-version: [20, 22]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ function parseCommandLine () {
}

function handleError (err) {
tool.halt(err.toString())
tool.halt(err.stack)
}
62 changes: 7 additions & 55 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,13 @@ class JsdocToMarkdown {
* > jsdoc2md.render({ files: 'lib/*.js' }).then(console.log)
* ```
*/
render (options) {
options = options || {}
const dmdOptions = new DmdOptions(options)
if (options.data) {
return dmd.async(options.data, dmdOptions)
} else {
return this.getTemplateData(options)
.then(templateData => dmd.async(templateData, dmdOptions))
}
}

/**
* Sync version of {@link module:jsdoc-to-markdown#render}.
*
* @param [options] {object} - Identical options to {@link module:jsdoc-to-markdown#render}.
* @return {string}
* @engine nodejs >= 0.12
* @category sync
* @example
* const docs = jsdoc2md.renderSync({ files: 'lib/*.js' })
*/
renderSync (options) {
options = options || {}
async render (options = {}) {
const dmdOptions = new DmdOptions(options)
if (options.data) {
return dmd(options.data, dmdOptions)
} else {
return dmd(this.getTemplateDataSync(options), dmdOptions)
const templateData = await this.getTemplateData(options)
return dmd(templateData, dmdOptions)
}
}

Expand All @@ -81,25 +60,10 @@ class JsdocToMarkdown {
* @fulfil {object[]} - the json data
* @category async
*/
getTemplateData (options) {
options = options || {}
const jsdocParse = require('jsdoc-parse')
return this.getJsdocData(options)
.then(jsdocParse)
}

/**
* Sync version of {@link module:jsdoc-to-markdown#getTemplateData}.
*
* @param [options] {object} - Identical options to {@link module:jsdoc-to-markdown#getJsdocData}.
* @return {object[]}
* @category sync
*/
getTemplateDataSync (options) {
options = options || {}
async getTemplateData (options = {}) {
const jsdocParse = require('jsdoc-parse')
const jsdocData = this.getJsdocDataSync(options)
return jsdocParse(jsdocData, options)
const jsdocData = await this.getJsdocData(options)
return jsdocParse(jsdocData)
}

/**
Expand All @@ -114,23 +78,11 @@ class JsdocToMarkdown {
* @fulfil {object[]}
* @category async
*/
getJsdocData (options) {
async getJsdocData (options) {
const jsdocOptions = new JsdocOptions(options)
return jsdocApi.explain(jsdocOptions)
}

/**
* Sync version of {@link module:jsdoc-to-markdown#getJsdocData}.
*
* @param [options] {object} - Identical options to {@link module:jsdoc-to-markdown#getJsdocData}.
* @return {object[]}
* @category sync
*/
getJsdocDataSync (options) {
const jsdocOptions = new JsdocOptions(options)
return jsdocApi.explainSync(jsdocOptions)
}

/**
* By default, the output of each invocation of the main generation methods (`render`, `getTemplateData` etc) is stored in the cache (your system's [temporary directory](https://nodejs.org/dist/latest-v6.x/docs/api/os.html#os_os_tmpdir)). Future jsdoc2md invocations with the same input options and source code will return the output immediately from cache, making the tool much faster/cheaper. If the input options or source code changes, fresh output will be generated. This method clears the cache, which you should never need to do unless the cache is failing for some reason. On Mac OSX, the system tmpdir clears itself every few days meaning your jsdoc2md cache will also be routinely cleared.
* @returns {Promise}
Expand Down
2 changes: 2 additions & 0 deletions lib/jsdoc-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class JsdocOptions {
Object.assign(this, options)
this.cache = !options['no-cache']
delete this['no-cache']
/* Remove the dmd `template` option - it will break jsdoc-api if passed in as the `template` option must be a filename */
delete this.template
}
}

Expand Down
Loading

0 comments on commit 0605ec8

Please sign in to comment.