【问题标题】:Complete documentation for stencil components with jsdoc, specifically a component description?带有 jsdoc 的模板组件的完整文档,特别是组件描述?
【发布时间】:2020-11-11 22:23:54
【问题描述】:

我正在使用 stencil.js 创建一个 Web 组件库。我想利用 docs-readme 输出功能,但必须对实际将哪些 cmets 输出到文档中进行大量试验和错误。

我现在遇到的具体问题是我无法获取组件本身的文档以使用自述文件生成。例如:

/**
 * This is a description of the component that I would like to generate in the readme.md for MyComponent
 */
@Component({
  tag: 'my-component',
  styleUrl: 'my-component.css',  
  shadow: true,
})
/** I've also tried this comment style and this location, but no dice */
export class MyComponent {
   ...
}

根据jsdoc documentation,似乎我应该能够记录课程,但似乎没有任何效果。是否有一份详尽的清单,列出了 Stencil 会和不会实际生成文档的内容?

【问题讨论】:

标签: jsdoc stenciljs


【解决方案1】:

您需要将 Web 组件(元素类)本身的文档放置到(部分)生成的 readme.md 中。源文件(.tsx、.css)中只需要类成员(属性/属性、方法)和 CSS 变量的文档。

(更新:有关组件注释的用途,请参阅下面的更新部分。)

将文档插入到src/components/my-component/readme.md以下行上方:

<!-- Auto Generated Below -->

此行下方的内容将使用源文件中的 JSDoc cmets 生成。

示例

# x-eyes

Shows a pair of eyes following movements of ...

<!-- Auto Generated Below -->

参见上述示例的full readme、TS source 和CSS source。

更新

其实,如果你按照自己的意愿给组件添加文档注释:

/**
 * Alternative summary...
 */
@Component({ tag: 'x-eyes', styleUrl: 'x-eyes.css' })
export class XEyesElement {

它会被使用,但是not in the readme file;但only in the docs property 的docs-json 或docs-vscode 输出目标:

{
  "filePath": "./src/components/x-eyes/x-eyes.tsx",
  "encapsulation": "shadow",
  "tag": "x-eyes",
  "docs": "Alternative summary...",
  "readme": "# &lt;x-eyes&gt;\n\nShows a pair of eyes following movements ...

如果你不给组件添加文档注释,docs属性的内容会从你的readme.md的第一部分中提取,在主标题和第一个副标题之间(由@发起987654339@):

{
  "filePath": "./src/components/x-eyes/x-eyes.tsx",
  "encapsulation": "shadow",
  "tag": "x-eyes",
  "docs": "Shows a pair of eyes following movements of ...",
  "readme": "# &lt;x-eyes&gt;\n\nShows a pair of eyes following movements ...

因此,如果您想将组件的描述摘要更改为比 readme.md 的介绍部分更短或不同,您可以将组件注释插入到组件源中。

【讨论】:

  • 我认为是这样。我希望我可以评论课程本身。
  • 是的,@aasukisuki,如果您想将生成的readme.md 的所有 cmets 保留在组件源文件中,这将无济于事。我更新了我的答案,并提供了有关如果您添加组件注释会发生什么情况的信息。它将成为写入JSON docs 输出的摘要描述,或者将传递给自定义文档生成器。
猜你喜欢
  • 2014-09-14
  • 2017-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-25
  • 1970-01-01
相关资源
最近更新 更多