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

WIP Add readme on API #33

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
82 changes: 81 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,89 @@

Utility for generating Astro pages from `TypeDoc`.

## Usage

### Basic example

Minimal config:

```js
// astro.config.mjs

import { defineConfig } from 'astro/config'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

import initAstroTypedoc from 'astro-typedoc'

const __dirname = dirname(fileURLToPath(import.meta.url))

const astroTypedoc = await initAstroTypedoc({
baseUrl: '/docs/',
entryPoints: [resolve(__dirname, 'path/to/entry/point.ts')],
Copy link
Member

Choose a reason for hiding this comment

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

path/to/entry/my-library/index.ts

Maybe we should add // Add path to your library here

tsconfig: resolve(__dirname, 'path/to/tsconfig.json')
})

const typedocProject = await astroTypedoc.getReflections()

await astroTypedoc.generateDocs(typedocProject, 'src/pages/docs')
await astroTypedoc.generateNavigationJSON(
reflections,
Copy link
Member

Choose a reason for hiding this comment

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

I can’t find this variable definition

resolve(__dirname, './src/')
)

// https://astro.build/config
export default defineConfig({})
```

## API

### `initAstroTypedoc({ baseUrl, entryPoints, tsconfig })`

Creates `astroTypedoc` instance. Accepts config object as a parameter.
Copy link
Member

Choose a reason for hiding this comment

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

It is not clear what is astroTypedoc instance and how it can be useful for me as a user.

Something like this could be better:

Creates a builder of pages and side-menu for your TypeDoc


#### `baseUrl`

Defines the root path for generated documentation.
`/docs/` means that documentation root is accessible on
`example.com/docs/`

#### `entryPoints`

An array of paths to entry points of the project.

#### `tsconfig`

Path to `tsconfig.json` of the project, which code will be documented.

### `astroTypedoc.getReflections`
Copy link
Member

Choose a reason for hiding this comment

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

It is not clear how I can use this method.


Returns [TypeDoc project reflection](https://typedoc.org/api/classes/Models.ProjectReflection.html)

Project reflection contains information about types and serves as the basis for creating documentation.

### `astroTypedoc.generateDocs(typedocProject, outputFolder)`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### `astroTypedoc.generateDocs(typedocProject, outputFolder)`
### `astroTypedoc.generateDocs(reflections, outputFolder)`


Generates documentation.

### `astroTypedoc.generateNavigationJSON(typedocProject, outputFolder)`

Generates JSON file which contains navigation tree for generated documentation.

Sample:

```json
[
{
"title": "Atom",
"url": "/docs/interfaces/interface.Atom"
}
]
```

## Testing

There are 3 subfolders is `test/` folder.
There are 3 subfolders in `test/` folder.

1. `types` - this is a stub TypeScript project, contains types, which are used for generating docs
2. `website-types` - a sample site which is generated from `types/` publicly exported types
Expand Down