Skip to content

Commit

Permalink
Drop support for node versions < v20
Browse files Browse the repository at this point in the history
Upgrade deps

the exported dmd() method is now async.. removed dmd.async
  • Loading branch information
75lb committed Aug 25, 2024
1 parent 98ea3af commit d5df7f3
Show file tree
Hide file tree
Showing 15 changed files with 475 additions and 677 deletions.
36 changes: 12 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@ const FileSet = require('file-set')
* Transforms doclet data into markdown documentation.
* @param {object[]}
* @param [options] {module:dmd-options} - The render options
* @return {string}
* @return {Promise<string>}
* @alias module:dmd
*/
function dmd (templateData, options) {
async function dmd (templateData, options) {
options = new DmdOptions(options)
if (skipCache(options)) {
return generate(templateData, options)
} else {
const cached = dmd.cache.readSync([templateData, options, dmdVersion])
if (cached) {
return cached
} else {
return generate(templateData, options)
}
}
}

dmd.async = function (templateData, options) {
options = new DmdOptions(options)
if (skipCache(options)) {
return Promise.resolve(generate(templateData, options))
} else {
return dmd.cache.read([templateData, options, dmdVersion])
.catch(function () {
Expand All @@ -43,16 +29,17 @@ dmd.async = function (templateData, options) {

dmd.cache = new Cache({ dir: path.join(require('os').tmpdir(), 'dmd') })

function generate (templateData, options) {
async function generate (templateData, options) {
const fs = require('fs')
const path = require('path')
const arrayify = require('array-back')
const handlebars = require('handlebars')
const walkBack = require('walk-back')
const DmdOptions = require('./lib/dmd-options')

function registerPartials (paths) {
const fileSet = new FileSet(paths)
async function registerPartials (paths) {
const fileSet = new FileSet()
await fileSet.add(paths)
for (const file of fileSet.files) {
handlebars.registerPartial(
path.basename(file, '.hbs'),
Expand All @@ -61,8 +48,9 @@ function generate (templateData, options) {
}
}

function registerHelpers (helpers) {
const fileSet = new FileSet(helpers)
async function registerHelpers (helpers) {
const fileSet = new FileSet()
await fileSet.add(helpers)
for (const file of fileSet.files) {
handlebars.registerHelper(require(path.resolve(process.cwd(), file)))
}
Expand Down Expand Up @@ -90,7 +78,7 @@ function generate (templateData, options) {
state.options = options

/* register all dmd partials. */
registerPartials(path.resolve(__dirname, './partials/**/*.hbs'))
await registerPartials(path.resolve(__dirname, './partials/**/*.hbs'))

/* if plugins were specified, register the helpers/partials from them too */
if (options.plugin) {
Expand Down Expand Up @@ -118,8 +106,8 @@ function generate (templateData, options) {
}

/* if additional partials/helpers paths were specified, register them too */
if (options.partial.length) registerPartials(options.partial)
if (options.helper.length) registerHelpers(options.helper)
if (options.partial.length) await registerPartials(options.partial)
if (options.helper.length) await registerHelpers(options.helper)

const compiled = handlebars.compile(options.template, {
preventIndent: true,
Expand Down
Loading

0 comments on commit d5df7f3

Please sign in to comment.