Skip to content
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 43 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d1a4142
feat: docs generator
marcelovicentegc Dec 5, 2023
90cab57
feat: add generate-docs to pre-commit
marcelovicentegc Nov 22, 2023
f123dfc
docs: auto generate _meta.json
marcelovicentegc Nov 22, 2023
e350071
docs: fix _meta generation format
marcelovicentegc Nov 22, 2023
44a47da
docs: add props under [component]/props.mdx file
marcelovicentegc Nov 22, 2023
56b233a
docs: generate interfaces/props from components
marcelovicentegc Nov 22, 2023
580cabf
docs: fix type links
marcelovicentegc Nov 23, 2023
4059638
docs: generate sandbox
marcelovicentegc Nov 23, 2023
83d4502
docs: fix example filename
marcelovicentegc Nov 23, 2023
0222cc4
docs: fix type aliases inclusion
marcelovicentegc Nov 23, 2023
7b6e168
docs: typedoc to shoreline links
marcelovicentegc Nov 24, 2023
20be2e2
chore: split methods from doc generator script
marcelovicentegc Nov 27, 2023
ff2f087
chore: remove raccoon from typedoc config
marcelovicentegc Nov 28, 2023
4c9ac4f
docs: update docs
marcelovicentegc Nov 28, 2023
2da4ddc
docs: remove new docs and let generator apply changes to existent com…
marcelovicentegc Nov 30, 2023
b26eb49
chore(docs-gen): remove returns and defined in typedoc tokens
marcelovicentegc Dec 4, 2023
cf14570
chore: make docs-generator script self contained
marcelovicentegc Dec 5, 2023
125286f
chore(docs-gen): remove exotic components note
marcelovicentegc Dec 5, 2023
3463e4e
docs: gen docs for current components
marcelovicentegc Dec 5, 2023
5424565
chore(docs-gen): rewrite doc gen to typescript and let it have its ow…
marcelovicentegc Dec 6, 2023
176f1f2
docs: update current docs with generated code
marcelovicentegc Dec 6, 2023
4012077
chore(docs-gen): add function to remove entire sections
marcelovicentegc Dec 6, 2023
7a9d344
chore(doc-gen): remove redundant component signature
marcelovicentegc Dec 6, 2023
1445587
chore(docs-gen): move all config interface to class
marcelovicentegc Dec 7, 2023
f96bab5
docs: make components header an h1
marcelovicentegc Dec 7, 2023
743964e
chore: remove unexistent file from eslint ignore
marcelovicentegc Dec 7, 2023
61cc8e5
chore: remove dump
marcelovicentegc Dec 7, 2023
545b9b4
chore: update with playground
marcelovicentegc Dec 7, 2023
6647b72
chore(docs-gen): replace typedoc default example header by custom one
marcelovicentegc Dec 7, 2023
2d8225d
chore(docs-gen): add best practices for writing meaningful docs
marcelovicentegc Dec 7, 2023
0595d0d
chore(docs-gen): move props from interfaces to code page
marcelovicentegc Dec 7, 2023
af81add
chore(docs-gen): merge props and code page
marcelovicentegc Dec 8, 2023
8095e52
feat: generate docs with handlebars
marcelovicentegc Dec 11, 2023
915d56e
chore: remove typedoc-plugin-markdown
marcelovicentegc Dec 11, 2023
87c32e1
chore: update lock file from root
marcelovicentegc Dec 11, 2023
93feaca
chore: split docs-generator methods to improve dx
marcelovicentegc Dec 11, 2023
582003c
chore: readd search docs
marcelovicentegc Dec 11, 2023
9b7d10d
chore(docs-gen): use pnpm's patch to patch typedoc-json-parser
marcelovicentegc Dec 12, 2023
0fd1bc9
chore: downgrade deps versions
marcelovicentegc Dec 12, 2023
c5e0423
chore(docs-gen): move typedoc-json-parser patch to docs-generator pkg
marcelovicentegc Dec 12, 2023
f054555
chore(docs-gen): improve config api
marcelovicentegc Dec 12, 2023
4b310ee
chore(docs-gen): bump version to 0.0.0
marcelovicentegc Dec 12, 2023
d4b6b25
chore(docs-gen): type components prop
marcelovicentegc Dec 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ storybook-static
packages/create-raccoon-app/src/index.js

# Resolve: Expected exception block, space or tab after '//' in comment
examples/shoreline-nextjs-integration/next-env.d.ts
examples/shoreline-nextjs-integration/next-env.d.ts

# Resolve: ES2015 module syntax is preferred over namespaces
packages/docs-generator/src/json-parser
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
".vscode/",
".cache/",
"__mocks__/",
"__generated__/"
"__generated__/",
"scripts/format-docs.js"
],
"env": {
"es2022": true
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ out
.idea

# File system stuff
**/.DS_Store
**/.DS_Store
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -108,5 +109,10 @@
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"pnpm": {
"patchedDependencies": {
"[email protected]": "packages/docs-generator/patches/[email protected]"
}
}
}
2 changes: 1 addition & 1 deletion packages/components/src/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface ButtonProps extends ComponentPropsWithoutRef<'button'> {
children: ReactNode
/**
* Increase or decrease padding.
* @default normal
* @default 'normal'
*/
size?: 'normal' | 'large'
/**
Expand Down
1 change: 1 addition & 0 deletions packages/docs-generator/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@vtex/prettier-config"
4 changes: 4 additions & 0 deletions packages/docs-generator/CHANGELOG.md
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.
93 changes: 93 additions & 0 deletions packages/docs-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# @vtex/docs-generator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice piece of docs, 👏🏾


## 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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'
}
```
34 changes: 34 additions & 0 deletions packages/docs-generator/package.json
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"
}
}
Loading