liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const jsdoc2md = require('jsdoc-to-markdown')
const fs = require('fs')
const path = require('path')
 
module.exports = function (grunt) {
  grunt.registerMultiTask('jsdoc2md', 'API documentation generator', function () {
    const options = this.options()
    const done = this.async()
    const promises = this.files.map(function (file) {
      const outputPath = file.dest
      grunt.file.mkdir(path.dirname(outputPath))
      options.files = file.src
      grunt.log.oklns('writing ' + outputPath)
      return jsdoc2md.render(options)
        .then(function (output) {
          fs.writeFileSync(outputPath, output)
        })
        .catch(grunt.fail.fatal)
    })
 
    Promise.all(promises).then(done)
  })
}