从jsDoc输出中排除外部

时间:2017-03-12 11:16:54

标签: node.js jsdoc

我们如何才能正确地从jsDoc输出中排除Externals部分?

我的项目中有许多外部因素,我根本不想在导航面板上显示,因为它占用了所有空间,对我们来说毫无用处。

我已经能够通过更改文件node_modules\jsdoc\lib\util\templateHelper.js中的代码手动破解它,但这对我的开发团队来说不是一种可重用的方法。

黑客用一个空数组覆盖members.externals

/*
    members.externals = members.externals.map(function(doclet) {
        doclet.name = doclet.name.replace(/(^"|"$)/g, '');
        return doclet;
    });
*/
    members.externals = [];

2 个答案:

答案 0 :(得分:1)

不幸的是,经过多年使用jsDoc之后,我所能做的就是在每次更新依赖项后,在文件node_modules\jsdoc\lib\util\templateHelper.js中继续重新攻击它。

幸运的是,即使使用当前版本3.5.5,黑客仍然可以正常工作:

// HACK: set Externals to an empty list:
members.externals = []; /*members.externals.map(function(doclet) {
    doclet.name = doclet.name.replace(/(^"|"$)/g, '');

    return doclet;
});*/

答案 1 :(得分:0)

我不确定这更优雅,但这就是我最终要做的事情。它适用于所有项目,无需破解jsdoc安装。

我的问题:我有从导入的node_modules派生的类,我想要包含在我的文档中的继承信息,但我不希望基类阻塞侧边栏导航。

首先,我在jsdoc-template中添加了一个插件(我称之为skip-node_modules):

exports.handlers = {
    processingComplete: function (e)
    {
        for (let i = 0; i < e.doclets.length; i++)
        {
            const doclet = e.doclets[i]
            if (!doclet.undocumented && doclet.meta && doclet.meta.path.indexOf('node_modules') !== -1)
            {
                // hack the name so I can find it in the .tmpl file
                // I tried to add a new flag to the doclet, but it didn't pass through
                doclet.longname += '~'
            }
        }
    }
};

然后我在navigation.tmpl中添加了一张支票:

<ul class="list">
<?js
this.nav.forEach(function (item) {
?>
    <?js if (item.longname[item.longname.length - 1] !== '~') { ?>
    <li class="item" data-name="<?js= item.longname ?>">
    ...
    <? } ?>

噗,我的侧边栏中没有更多的node_module导入。 (当你点击这些课程时,这确实有不显示侧边栏的缺点。我确信更多的黑客可以摆脱它,但它并不重要。)

将其更改为检查外部符号会很容易。插件中的console.log(e)获取doclet提供的所有信息,并找到适合您情况的信息。

相关问题