-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: docs generator #1290
Merged
Merged
feat: docs generator #1290
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
d1a4142
feat: docs generator
marcelovicentegc 90cab57
feat: add generate-docs to pre-commit
marcelovicentegc f123dfc
docs: auto generate _meta.json
marcelovicentegc e350071
docs: fix _meta generation format
marcelovicentegc 44a47da
docs: add props under [component]/props.mdx file
marcelovicentegc 56b233a
docs: generate interfaces/props from components
marcelovicentegc 580cabf
docs: fix type links
marcelovicentegc 4059638
docs: generate sandbox
marcelovicentegc 83d4502
docs: fix example filename
marcelovicentegc 0222cc4
docs: fix type aliases inclusion
marcelovicentegc 7b6e168
docs: typedoc to shoreline links
marcelovicentegc 20be2e2
chore: split methods from doc generator script
marcelovicentegc ff2f087
chore: remove raccoon from typedoc config
marcelovicentegc 4c9ac4f
docs: update docs
marcelovicentegc 2da4ddc
docs: remove new docs and let generator apply changes to existent com…
marcelovicentegc b26eb49
chore(docs-gen): remove returns and defined in typedoc tokens
marcelovicentegc cf14570
chore: make docs-generator script self contained
marcelovicentegc 125286f
chore(docs-gen): remove exotic components note
marcelovicentegc 3463e4e
docs: gen docs for current components
marcelovicentegc 5424565
chore(docs-gen): rewrite doc gen to typescript and let it have its ow…
marcelovicentegc 176f1f2
docs: update current docs with generated code
marcelovicentegc 4012077
chore(docs-gen): add function to remove entire sections
marcelovicentegc 7a9d344
chore(doc-gen): remove redundant component signature
marcelovicentegc 1445587
chore(docs-gen): move all config interface to class
marcelovicentegc f96bab5
docs: make components header an h1
marcelovicentegc 743964e
chore: remove unexistent file from eslint ignore
marcelovicentegc 61cc8e5
chore: remove dump
marcelovicentegc 545b9b4
chore: update with playground
marcelovicentegc 6647b72
chore(docs-gen): replace typedoc default example header by custom one
marcelovicentegc 2d8225d
chore(docs-gen): add best practices for writing meaningful docs
marcelovicentegc 0595d0d
chore(docs-gen): move props from interfaces to code page
marcelovicentegc af81add
chore(docs-gen): merge props and code page
marcelovicentegc 8095e52
feat: generate docs with handlebars
marcelovicentegc 915d56e
chore: remove typedoc-plugin-markdown
marcelovicentegc 87c32e1
chore: update lock file from root
marcelovicentegc 93feaca
chore: split docs-generator methods to improve dx
marcelovicentegc 582003c
chore: readd search docs
marcelovicentegc 9b7d10d
chore(docs-gen): use pnpm's patch to patch typedoc-json-parser
marcelovicentegc 0fd1bc9
chore: downgrade deps versions
marcelovicentegc c5e0423
chore(docs-gen): move typedoc-json-parser patch to docs-generator pkg
marcelovicentegc f054555
chore(docs-gen): improve config api
marcelovicentegc 4b310ee
chore(docs-gen): bump version to 0.0.0
marcelovicentegc d4b6b25
chore(docs-gen): type components prop
marcelovicentegc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,4 +80,4 @@ out | |
.idea | ||
|
||
# File system stuff | ||
**/.DS_Store | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
"dev-storybook": "pnpm storybook dev -p 6006", | ||
"build:storybook": "pnpm build && pnpm storybook build", | ||
"chromatic": "chromatic --exit-zero-on-changes --build-script-name=build:storybook", | ||
"generate-docs": "npm --prefix packages/docs-generator run start", | ||
"next-docs": "npm --prefix packages/next-docs run dev", | ||
"build:next-docs": "npm --prefix packages/next-docs run build-docs", | ||
"commit": "cz", | ||
|
@@ -85,8 +86,8 @@ | |
"react-test-renderer": "18.2.0", | ||
"storybook": "^7.5.3", | ||
"stylelint": "^15.11.0", | ||
"stylelint-prettier": "^4.0.2", | ||
"stylelint-config-recommended": "^13.0.0", | ||
"stylelint-prettier": "^4.0.2", | ||
"tslib": "2.6.2", | ||
"tsup": "8.0.1", | ||
"turbo": "1.4.3", | ||
|
@@ -108,5 +109,10 @@ | |
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "packages/docs-generator/patches/[email protected]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"@vtex/prettier-config" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# @vtex/docs-generator | ||
|
||
## Description | ||
|
||
This is a package that generates documentation from Typescript code. It uses TypeDoc under the hood to generate the documentation from code, and then it passes its output down the pipeline to our own parser, which generates markdown files from TypeDoc's JSON output using Handlebars. | ||
|
||
## Usage | ||
|
||
Clone the repository, and run `pnpm install` from the root of the repository. | ||
|
||
Configure the `docs-generator` package by editing the config variable from `docs-generator/src/index.ts` file. The configuration file is documented on code, so you should be able to understand what each configuration option does. | ||
|
||
Run `pnpm run generate-docs` from the root of the repository: | ||
|
||
```sh | ||
pnpm run generate-docs | ||
``` | ||
|
||
## Architecture | ||
|
||
The `docs-generator` package is composed of two main parts: | ||
|
||
- The TypeDoc parser, which is responsible for generating the documentation from Typescript code. | ||
- The JSON parser, which is responsible for generating markdown files from TypeDoc's JSON output. | ||
|
||
### TypeDoc parser | ||
|
||
The TypeDoc parser is a wrapper around TypeDoc's Node API. It is responsible for generating the documentation from Typescript code. | ||
|
||
### JSON parser | ||
|
||
The JSON parser is responsible for generating markdown files from TypeDoc's JSON output. [It is a patch on top of the `typedoc-json-parser` library](../../patches/[email protected]). This patch is necessary because the `typedoc-json-parser` library types are currently broken. | ||
|
||
### Code organization | ||
|
||
The `docs-generator` package is organized as follows: | ||
|
||
```bash | ||
docs-generator | ||
├── src | ||
│ ├── json-parser # The typedoc-json-parser library patch | ||
│ ├── templates # The Handlebars templates used to generate .mdx files | ||
│ ├── config.ts # The configuration file for TypeDoc | ||
│ ├── templates.ts # Handlebars utilities | ||
│ ├── handlers.ts # A set of functions that handle our different use cases (such as genreating a component documentation) | ||
│ ├── io.ts # A set of functions that handle IO operations | ||
│ ├── parser.ts # The JSON parser entrypoint | ||
│ └── index.ts # The entrypoint of this package where TypeDoc is configured, executed and its output is passed down the pipeline to our JSON parser | ||
``` | ||
|
||
## Best practices when writing documentation on code | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can create a eslint-plugin to check for this in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely! I've created an issue as a follow up for this: #1371 |
||
|
||
### For React components | ||
|
||
- Always provide a description for the component. | ||
- Always use the `@example` tag to provide examples of how to use the component. From this tag, a playground is generated. | ||
- Always provide a description of each property of the component, including the `@default` value when necessary. | ||
|
||
Example: | ||
|
||
```jsx | ||
/** | ||
* Buttons triggers allow users to identify and start the most important actions in a container. | ||
* | ||
* @example | ||
* <Button>Action label</Button> | ||
*/ | ||
export function Button(props: ButtonProps) { | ||
const { | ||
children, | ||
size = 'normal', | ||
variant = 'secondary', | ||
...rest | ||
} = props | ||
|
||
return <button data-size={size} data-variant={variant} {...rest}>{children}</button> | ||
} | ||
|
||
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
/** | ||
* The size of the button. | ||
* | ||
* @default 'normal' | ||
*/ | ||
size?: 'small' | 'normal' | 'large' | ||
/** | ||
* The variant of the button. | ||
* | ||
* @default 'secondary' | ||
*/ | ||
variant?: 'primary' | 'secondary' | 'tertiary' | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@vtex/docs-generator", | ||
"description": "Generate a custom Markdown documentation from your Typescript code leveraging typedoc", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"private": true, | ||
"main": "./src/index.ts", | ||
"repository": "vtex/shoreline", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"scripts": { | ||
"prebuild": "rm -rf dist", | ||
"dev": "tsup --watch", | ||
"build": "pnpm run prebuild && tsup", | ||
"start": "pnpm run build && node dist/esm/index.js", | ||
"start:json": "npx ts-node src/json-parser.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.10.3", | ||
"@types/prettier": "^2.7.3", | ||
"typedoc": "0.25.3", | ||
"typedoc-plugin-mdn-links": "3.1.4" | ||
}, | ||
"dependencies": { | ||
"colorette": "^2.0.20", | ||
"handlebars": "^4.7.8", | ||
"typedoc-json-parser": "^9.0.1" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice piece of docs, 👏🏾