Skip to content

Commit

Permalink
chore: Updated code comments and cleaned-up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jan 15, 2024
1 parent 62f0eac commit dc5b90c
Show file tree
Hide file tree
Showing 30 changed files with 1,367 additions and 193 deletions.
1 change: 0 additions & 1 deletion docs/pages/quick-start.mdx
Expand Up @@ -31,7 +31,6 @@ The majority of [TypeDoc's options](https://typedoc.org/options/) are supported,

Some typical (and frequently asked about) TypeDoc options that might be useful are:

- Using [githubPages](https://typedoc.org/options/output/#githubpages) to remove the generated `.nojekyll` file.
- Using [hideGenerator](https://typedoc.org/options/output/#hidegenerator) to prevent outputting links in the footer.
- Using [disableSources](https://typedoc.org/options/output/#disablesources) to prevent outputting source references.
- Setting [readme](https://typedoc.org/options/input/#readme) to `none` to exclude the project readme from the docs.
3 changes: 3 additions & 0 deletions examples/docusaurus3/docusaurus.config.js
Expand Up @@ -52,6 +52,7 @@ const config = {
readme: 'none',
sidebar: { pretty: true },
outputFileStrategy: 'members',
cleanOutputDir: true,
},
],
[
Expand All @@ -61,6 +62,7 @@ const config = {
out: './docs/api-2',
...require(path.join(__dirname, '../../stubs/typedoc.cjs')),
entryPoints: '../../stubs/src/groups/**/*.ts',
cleanOutputDir: true,
},
],
[
Expand All @@ -73,6 +75,7 @@ const config = {
readme: 'none',
outputFileStrategy: 'modules',
entryModule: 'index',
cleanOutputDir: true,
},
],
[
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-typedoc/package.json
Expand Up @@ -23,7 +23,8 @@
"prepublishOnly": "npm run lint && npm run build",
"build": "rm -rf ./dist && tsc",
"build-and-test": "npm run build && npm run test",
"test": "jest"
"test": "jest",
"test:update": "npm test -- -u"
},
"author": "Thomas Grey",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-typedoc/src/options.ts
Expand Up @@ -7,7 +7,6 @@ const DEFAULT_PLUGIN_OPTIONS = {
hidePageHeader: true,
entryFileName: 'index.md',
theme: 'docusaurus',
githubPages: false,
sidebar: {
autoConfiguration: true,
pretty: false,
Expand Down
31 changes: 0 additions & 31 deletions packages/docusaurus-plugin-typedoc/src/plugin.ts
Expand Up @@ -56,10 +56,6 @@ async function generateTypedoc(context: any, opts: Partial<PluginOptions>) {

const outputDir = app.options.getValue('out');

if (options.cleanOutputDir) {
removeDir(outputDir);
}

if (context.siteConfig?.markdown?.format !== 'mdx') {
app.renderer.on(PageEvent.END, (event: PageEvent) => {
event.contents = event.contents?.replace(/\\</g, '<');
Expand Down Expand Up @@ -121,30 +117,3 @@ module.exports = typedocSidebar.items;`,
await app.generateDocs(project, outputDir);
}
}

export function writeFileSync(fileName: string, data: string) {
fs.mkdirSync(path.dirname(normalizePath(fileName)), { recursive: true });
fs.writeFileSync(normalizePath(fileName), data);
}

export function normalizePath(path: string) {
return path.replace(/\\/g, '/');
}

export function removeDir(path: string) {
if (fs.existsSync(path)) {
const files = fs.readdirSync(path);
if (files.length > 0) {
files.forEach(function (filename) {
if (fs.statSync(path + '/' + filename).isDirectory()) {
removeDir(path + '/' + filename);
} else {
fs.unlinkSync(path + '/' + filename);
}
});
fs.rmdirSync(path);
} else {
fs.rmdirSync(path);
}
}
}
Expand Up @@ -14,10 +14,6 @@ exports[`Docusaurus: Defaults should render 1`] = `
- [module-1](module-1/index.md)
- [module-2](module-2/index.md)
***
Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
"
`;

Expand All @@ -35,9 +31,5 @@ exports[`Docusaurus: Global members should render 2 1`] = `
- [module-1](module-1/index.md)
- [module-2](module-2/index.md)
***
Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
"
`;
Expand Up @@ -13,6 +13,7 @@ async function bootstrap(
entryPoints,
tsconfig: ['./test/stubs/tsconfig.json'],
readme: 'none',
hideGenerator: true,
};

const plugin = typedocPlugin(
Expand Down
1 change: 0 additions & 1 deletion packages/typedoc-github-wiki-theme/src/options/presets.ts
@@ -1,5 +1,4 @@
export default {
entryFileName: 'Home.md',
hidePageHeader: true,
githubPages: false,
};
1 change: 0 additions & 1 deletion packages/typedoc-gitlab-wiki-theme/src/options/presets.ts
@@ -1,5 +1,4 @@
export default {
entryFileName: 'home.md',
hidePageHeader: true,
githubPages: false,
};
3 changes: 1 addition & 2 deletions packages/typedoc-plugin-frontmatter/test/typedoc-base.json
Expand Up @@ -6,6 +6,5 @@
"plugin": ["typedoc-plugin-markdown", "typedoc-plugin-frontmatter"],
"hidePageHeader": true,
"hideBreadcrumbs": true,
"hideGenerator": true,
"githubPages": false
"hideGenerator": true
}
101 changes: 100 additions & 1 deletion packages/typedoc-plugin-markdown/CONTRIBUTING.md
@@ -1,3 +1,102 @@
# Contributing guidelines

Contributions and suggestions are welcome. Contributing guidelines coming soon.
> Please note this guide is work in progress!
Thank you showing interest in contributing to this plugin - contributions and suggestions are very welcome.

## Overview

This is a simple monorepo managed by [npm workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces) with `typedoc-plugin-markdown` the "core" package. This guide is for developing inside the `typedoc-plugin-markdown` core package.

This guide does not cover TypeDoc specifically so it might be useful to read the [TypeDoc development guide](https://typedoc.org/guides/development/) for an overview on TypeDoc's architecture.

## Getting started

1. Clone the repository:<br />`git clone git@github.com:tgreyuk/typedoc-plugin-markdown.git`

2. Checkout the `next` branch:<br />`git checkout next`

3. Install dependecnices from the repository root.<br />`npm install`

4. cd into the package:<br />`cd packages/typedoc-plugin-markdown`

5. Build and run tests:<br />`npm run build-and-test`

If the project builds and the tests run successfully you are ready to get going.

## High-level architecture

At a high level the codebase consists of an exposed TypeDoc plugin along side an assoicated theme.

To start getting familiar with the code browse the `src` directory:

```
├── src
│   ├── index.ts // exposed public api
│   ├── plugin // plugin code
│   ├── support
│   └── theme // theme code
```

At a highlevel:

- `index.ts` contains the public api and exports the required `load` funtion.
- The `plugin` folder contains functionality to setup the plugin and configure the renderer.
- The `support` folder contains agnostic support helpers used in the plugin.
- The `theme` folder contains the logic that sets up the custom Markdown theme.

Use the command to build the codebase and then run some example docs to the out folder.

```shell
npm run docs
```

Additional stub data can be created in the `../stubs` folder.

Please refer to the [API docs](./docs/api/README.md) for automated documentation generated by TypeDoc and this plugin.

## Testing

Test use the [Jest](https://jestjs.io/) with [ts-jest](https://kulshekhar.github.io/ts-jest/) as the test framework. To run all tests use the following command:

```shell
npm run test
```

Jest snapshots are used quite heavily to compare the output generated from templates. To update the snapshots run with the `update` flag.

## Linting

To run linting on the project use:

```shell
npm run lint
```

Both the code and some example generated markdown are linted using [eslint](https://eslint.org/) and [markdowmlint](https://github.com/DavidAnson/markdownlint) respectively.

## Submitting a PR

Please create a PR with a clear description of what the change is.

If the PR requires a new package release please also create a [changeset](https://github.com/changesets/changesets) which is the tool used for versioning and releasing packages.

Run the changeset command in the project root:

```shell
npx changeset
```

A one line changeset description will be enough but please ensure the correct semantic version is selected `patch` for a bug fix or `minor` for a new feature.

The resulting changeset file will something like this:

```markdown
---
'typedoc-plugin-markdown': patch
---

- A simple description for a patch fix. This message will also appear in the changelog.
```

Please also submit this file with the PR.
10 changes: 10 additions & 0 deletions packages/typedoc-plugin-markdown/docs/api/README.md
@@ -0,0 +1,10 @@
# typedoc-plugin-markdown

## Modules

- [plugin/bootstrap](plugin/bootstrap/README.md)
- [theme/theme](theme/theme/README.md)

***

Generated using [TypeDoc](https://typedoc.org) and [typedoc-plugin-markdown](https://typedoc-plugin-markdown.org).
@@ -0,0 +1,15 @@
[typedoc-plugin-markdown](../../README.md) / plugin/bootstrap

# plugin/bootstrap

Exposes the [load](functions/load.md) function that is called by TypeDoc to bootstrap the plugin, expose options and define the th.

## Index

### Functions

- [load](functions/load.md)

***

Generated using [TypeDoc](https://typedoc.org) and [typedoc-plugin-markdown](https://typedoc-plugin-markdown.org).
@@ -0,0 +1,25 @@
[typedoc-plugin-markdown](../../../README.md) / [plugin/bootstrap](../README.md) / load

# Function: load()

> **load**(`app`): `void`
The main plugin entrypoint containing all bootstrapping logic.

Here we expose additional TypeDoc options and make some adjustments to [Renderer]([object Object]).

## Parameters

**app**: [`Application`]( https://typedoc.org/api/classes/Application.html )

## Returns

`void`

## Source

[packages/typedoc-plugin-markdown/src/plugin/bootstrap.ts:24](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/62f0eacf/packages/typedoc-plugin-markdown/src/plugin/bootstrap.ts#L24)

***

Generated using [TypeDoc](https://typedoc.org) and [typedoc-plugin-markdown](https://typedoc-plugin-markdown.org).
13 changes: 13 additions & 0 deletions packages/typedoc-plugin-markdown/docs/api/theme/theme/README.md
@@ -0,0 +1,13 @@
[typedoc-plugin-markdown](../../README.md) / theme/theme

# theme/theme

## Index

### Classes

- [MarkdownTheme](classes/MarkdownTheme.md)

***

Generated using [TypeDoc](https://typedoc.org) and [typedoc-plugin-markdown](https://typedoc-plugin-markdown.org).

0 comments on commit dc5b90c

Please sign in to comment.