Skip to content

How to use with gulp

Lloyd Brookes edited this page Oct 19, 2016 · 10 revisions

1. Install jsdoc2md in your project. For the async example below, I'm also using fs-then-native.

$ npm i jsdoc-to-markdown fs-then-native --save-dev

2. Add a simple task to your gulpfile.js (consult the API docs for instructions how to use jsdoc2md.render)

gulp.task('docs', function () {
  const fs = require('fs-then-native')
  const jsdoc2md = require('jsdoc-to-markdown')

  return jsdoc2md.render({ files: 'lib/*.js' })
    .then(output => fs.writeFile('api.md', output))
    .catch(err => {
      console.err(err.stack)
    })
})

3. Or, the synchronous equivalent (node v0.12.0 and over):

gulp.task('docs', function () {
  const fs = require('fs')
  const jsdoc2md = require('jsdoc-to-markdown')

  const output = jsdoc2md.renderSync({ files: 'lib/*.js' })
  fs.writeFileSync('docs/api.md', output)
})
Clone this wiki locally