码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【jsdoc-to-markdown】一步步实现js文件的文档生成


    文章目录

      • 导读
        • 开发环境
      • 安装Vs code插件:Doxygen Documentation Generator
        • 效果
        • 优势
      • jsdoc-to-markdown的使用
        • 了解 jsdoc
        • jsdoc-to-markdown安装
        • 创建测试文件example.js
        • jsdoc-to-markdown使用
        • jsdoc-to-markdown踩坑!!!
      • 参考资料

    导读

    这个需求有点怪,之前基本都是后台生成文档,前端对接就行了。
    不过当团队大了,或者异地办公等原因,导致前端也需要进行对接,因此有了这篇文章。

    开发环境

    版本号描述
    文章日期2022-10-27
    操作系统Win10-1607
    nvm version1.1.9
    node -vv12.22.12npm -v (6.14.16)
    IDEA2021.3

    安装Vs code插件:Doxygen Documentation Generator

    插件安装后,直接输入/**,会自动弹出注释的选项,我们选择Document This的选项。如下图:
    在这里插入图片描述

    效果

      /**
       * 功能设置:
       *
       * @example
       *    await setValue('mega_money', true);
       * @param {*} target
       * @param {*} arg
       * @param {string} [source='']
       * @param {number} [cheatId=0]
       * @returns undefined
       * @memberof Trainer
       */
      async setValue(target, arg, source='', cheatId=0) {
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    优势

    • 支持多种语言
    • 自动识别参数及类型

    jsdoc-to-markdown的使用

    了解 jsdoc

    jsdoc-to-markdown基于jsdoc实现的,可以参考文章《jsdoc接口文档生成器》https://blog.csdn.net/youlinhuanyan/article/details/105667770

    jsdoc-to-markdown安装

    全局安装:
    npm install -g jsdoc-to-markdown

    创建测试文件example.js

    /**
     * A quite wonderful function.
     * @param {object} - Privacy gown
     * @param {object} - Security
     * @returns {survival}
     */
    function protection (cloak, dagger) {}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    jsdoc-to-markdown使用

    单文件:jsdoc2md example.js
    多文件:jsdoc2md -f example.js example2.js > all.md

    编程方式实现
    https://github.com/jsdoc2md/jsdoc-to-markdown/wiki/How-to-create-one-output-file-per-class

    'use strict'
    const jsdoc2md = require('jsdoc-to-markdown')
    const fs = require('fs')
    const path = require('path')
    
    /* input and output paths */
    const inputFile = 'example.js'
    const outputDir = __dirname
    
    /* get template data */
    const templateData = jsdoc2md.getTemplateDataSync({ files: inputFile })
    
    /* reduce templateData to an array of class names */
    const classNames = templateData.reduce((classNames, identifier) => {
      if (identifier.kind === 'class') classNames.push(identifier.name)
      return classNames
    }, [])
    
    /* 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 = jsdoc2md.renderSync({ data: templateData, template: template })
      fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output)
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    jsdoc-to-markdown踩坑!!!

    上面说的是官网教程,不过执行完后,小编的电脑会报下面的错误:
    JSDOC_ERROR: There are no input files to process.
    在这里插入图片描述

    众里寻他千百度,终于在stackoverflow上找到了答案:
    在这里插入图片描述

    我的jsdoc是全局安装的,配置文件所在目录为J:\Users\Administrator\AppData\Roaming\nvm\v12.22.12\node_modules\jsdoc-to-markdown\node_modules\jsdoc。
    |
    everything全局搜索文件jsdoc\conf.json.EXAMPLE所在目录就是了,创建个文件名为conf.json的配置,填入下面配置:

    {
        "tags": {
            "allowUnknownTags": true
        },
        "source": {
            "include": ["."]
        },
        "plugins": [],
        "templates": {
            "cleverLinks": false,
            "monospaceLinks": false,
            "default": {
                "outputSourceFiles": true
            }
        }
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    参考资料

    • Vs code自动生成Doxygen格式注释 https://www.cnblogs.com/silencehuan/p/11875958.html
    • jsdoc-to-markdown官网 https://github.com/jsdoc2md/jsdoc-to-markdown
    • 踩坑原文 https://stackoverflow.com/questions/64978721/js-includepattern-not-working-there-are-no-input-files-to-process
  • 相关阅读:
    MySQL性能优化实践:SQL查询优化之使用只读索引、IN方法和临时表分批查询(附加:索引的创建删除命令)
    已解决org.springframework.web.client.HttpServerErrorException: 500服务器端HTTP调用错误的正确解决方法,亲测有效!!!
    基于javaweb+mysql的二手交易平台二手商城二手物品(前台、后台)
    电脑技巧:推荐5个非常实用的软件
    【Web开发】Python实现Web服务器(Flask打包部署上线)
    2022系统分析师下午卷(案例分析)
    【疯壳·机器人教程9】人形街舞机器人-整机代码
    [找规律]Array Concatenation 2022CCPC桂林站C
    分享一个基于微信小程序的社区生活小助手源码调试和lw,有java+python双版本
    消息队列RabbitMQ核心:简单(Hello World)模式、队列(Work Queues)模式、发布订阅模式
  • 原文地址:https://blog.csdn.net/kinghzking/article/details/127552791
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号