ドキュメントJsonデータ
マークダウンでフォーマットされた自動生成されたreadmeファイルは便利ですが、すべてのドキュメントをjsonデータの形式で取得したほうがよいシナリオもあります。 ドキュメントをjsonとしてビルドするには、 --docs-jsonフラグを使用し、その後にjsonファイルを書き込む場所のパスを続けます。
scripts: {
"docs.data": "stencil build --docs-json path/to/docs.json"
}
別のオプションは、ビルドごとにこのファイルを自動生成するために、 docs-json出力ターゲットをstencil.config.tsに追加することです。
import { Config } from '@stencil/core';
export const config: Config = {
outputTargets: [
{
type: 'docs-json',
file: 'path/to/docs.json'
}
]
};
Check out the typescript declarations for the JSON output: https://github.com/ionic-team/stencil/blob/main/src/declarations/stencil-public-docs.ts
CSS Variables
Stencil will also document CSS variables when you specify them via jsdoc-style comments inside your css/scss files:
/**
* @prop --background: Background of the button
* @prop --background-activated: Background of the button when activated
* @prop --background-focused: Background of the button when focused
*/
使用法
Slots can be documented by adding @slot tags to the doc comments above the @Component decorator.
/**
* @slot slotName - slotDescription
* @slot buttonContent - Slot for the content of the button
*/
@Component({
tag: '...'
}) ...
使用法
The content of .md files in a usage subdirectory of a component will be added to the usage property of the generated json.
src/
components/
my-component/
usage/
usage-example.md
another-example.md
my-component.css
my-component.tsx
カスタムJSDocsタグ
事前定義されたJSDocタグを読み取ることに加えて、ユーザーは独自のカスタムタグを提供できます。これもJSONデータに含まれます。 これにより、チームが独自のドキュメントと規則を提供して、JSONデータ内に構築することが容易になります。 たとえば、次のようにソースコードにコメントを追加した場合:
/**
* @myDocTag someName - some value
* @myOtherDocTag someOtherName - some other name
*/
@Component({
tag: '...'
}) ...
最終的には次のようなJSONデータになります。
"docsTags": [
{
"text": "someName - some value",
"name": "myDocTag"
},
{
"text": "someOtherName - some other name",
"name": "myOtherDocTag"
}
],