Skip to content

Commit

Permalink
Add a warning when a common mistake is detected: '@module tag required'
Browse files Browse the repository at this point in the history
Fixes #96
  • Loading branch information
75lb committed Sep 1, 2024
1 parent bae4c23 commit 2e4b60c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const DmdOptions = require('./lib/dmd-options')
const FileSet = require('file-set')
const os = require('os')
const partialCache = require('./partials/partial-cache.js')
const handlebars = require('handlebars')
const arrayify = require('array-back')
const walkBack = require('walk-back')
const HandlebarsTemplate = require('./lib/handlebars-template.js')
Expand Down Expand Up @@ -61,7 +60,18 @@ async function loadHelperFiles (helpers) {
})
}

function validateIncomingTemplateData (templateData) {
const moduleTagRequired = templateData.filter(d => d.id === 'module.exports' && d.memberof === 'module')
if (moduleTagRequired.length) {
for (const doclet of moduleTagRequired) {
console.warn(`Module tag required in this file: ${doclet.meta.path}${path.sep}${doclet.meta.filename}`)
console.warn('See the wiki for an explanation: https://github.com/jsdoc2md/jsdoc-to-markdown/wiki/How-to-document-an-ES2015-module-(single-default-export)')
}
}
}

async function generate (templateData, options) {
validateIncomingTemplateData(templateData)
const handlebarsTemplate = new HandlebarsTemplate()

/* Copy input data */
Expand Down Expand Up @@ -109,7 +119,7 @@ async function generate (templateData, options) {
const internalPartials = Array.from(partialCache)
const externalPartials = await loadPartialFiles(options.partial)
for (const [name, content] of [...internalPartials, ...externalPartials]) {
handlebars.registerPartial(name, content)
handlebarsTemplate.handlebars.registerPartial(name, content)
}

/* Register internal helpers first so they can be overriden by user-defined helpers */
Expand Down

0 comments on commit 2e4b60c

Please sign in to comment.