TypeDoc如何定义externalPattern?

TypeDoc how to define externalPattern?

我正在使用 grunt 和 typedoc 开发应用程序。

我需要使用 TypeDoc 准备文档,但我遇到了一种情况。

我必须从文档中排除一些外部库文件。 我无法将这些文件放入 exclude 部分,因为这些文件与另一个文件相关。如果我试图排除它(通过将这些文件放入 exclude 部分)我有一个错误 - 类似于 cannot find to xxx into yyy.ts - 其中 xxx 是我排除的元素并且 yyy 是相关的文件 xxx。那些 本文档需要相关文件,因此我也不能排除这些文件。

我阅读了有关 excludeExternals 的 TypeDoc 文档。所以我想如果我将这个布尔值设置为 true 那么我可以定义 externalPattern 来排除我的外部文件。它可以工作,但前提是我输入一个文件的名称 - 仅此而已。

你知道怎么做吗?

这是我在 gruntfile.js 中的 typedoc 配置(没有 excludeExternals 选项):

typedoc: {
    build: {
        options: {
            module: 'commonjs',
            out: '../Documentation/',
            name: 'MyApp',
            target: 'es5',
            exclude: [
                'node_modules',
                '**/*.d.ts'
            ],
            excludePrivate: true,
            mode: 'file'
        },
        src: [
            ...some source...
        ]
    }
} 

这是我必须排除的外部文件列表:A.ts、B.ts、C.ts、D.ts ...

这是我在 gruntfile.js 中的 typedoc 配置(带有 excludeExternals 选项):

typedoc: {
    build: {
        options: {
            module: 'commonjs',
            out: '../Documentation/',
            name: 'MyApp',
            target: 'es5',
            exclude: [
                'node_modules',
                '**/*.d.ts'
            ],
            excludeExternals: true,
            externalPattern: '**/*/A.ts',
            excludePrivate: true,
            mode: 'file'
        },
        src: [
            ...some source...
        ]
    }
} 

此配置运行良好。我有一份没有 A.ts 文件的文档。所以现在我需要放一些文件,所以我试着放 externalPattern 类似的东西:**/*/(A|B|C|D).ts 但没有成功(因为在重新编译文档时我有错误:Process terminated with code 3. 'B' is not recognized as an internal or external command, operable program or batch file.)。

有什么想法吗?

根据 this comment,正确的语法是 **/*/+(A|B|C|D).ts。此外,看起来您 运行 遇到了 shell 试图解释竖线字符的问题,因此请尝试在整个事物周围添加双引号:

externalPattern: '"**/*/+(A|B|C|D).ts"'

我找到了解决方案。如果我想使用 externalPattern 排除外部文件,我应该这样写模式:

externalPattern: "**/*/{A,B,C,D}.ts"

{ } = allows for a comma-separated list of "or" expressions

, = or

对我有用的是 this comment 来自关于 gruntfile 中正则表达式的主题。