A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/jsdoc2md/jsdoc-to-markdown/wiki/How-to-create-one-output-file-per-class below:

How to create one output file per class · jsdoc2md/jsdoc-to-markdown Wiki · GitHub

1. Say you have several documented classes in a file named example.js:

/**
 * Animal.
 */
class Animal {
  constructor () {
    /**
     * Favourite food.
     */
    this.food = null
  }
}

/**
 * Habitat.
 */
class Habitat {
  constructor () {
    /**
     * Contains wood.
     */
    this.wood = null
  }
}

2. This example script will generate one output file per documented class found in the input. See also:

import jsdoc2md from 'jsdoc-to-markdown'
import { promises as fs } from 'node:fs'
import path from 'path'

/* input and output paths */
const inputFile = 'example.js'

/* get template data */
const templateData = await jsdoc2md.getTemplateData({ files: inputFile })

/* reduce templateData to an array of class names */
const classNames = templateData.filter(i => i.kind === 'class').map(i => i.name)

/* create a documentation file for each class */
for (const className of classNames) {
  const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`
  console.log(`rendering ${className}, template: ${template}`)
  const output = await jsdoc2md.render({ data: templateData, template: template })
  await fs.writeFile(path.resolve(`${className}.md`), output)
}

3. Two output files are created, the first Animal.md:

Animal.

Kind: global class

Favourite food.

Kind: instance property of Animal

4. The second output file, Habitat.md:

Habitat.

Kind: global class

Contains wood.

Kind: instance property of Habitat


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4