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

website: add "API Reference" generation #406

Merged
merged 15 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
"version": "5.1.250801",
"commands": [
"dotnet-format"
]
],
"rollForward": false
},
"docfx": {
"version": "2.78.2",
"commands": [
"docfx"
],
"rollForward": false
}
}
}
11 changes: 11 additions & 0 deletions .github/workflows/deploy-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
paths:
- 'docs/**'
- 'Consul/**'
pull_request:
paths:
- 'docs/**'
Expand Down Expand Up @@ -77,6 +78,16 @@ jobs:
run: yarn install
working-directory: ./docs

- name: Setup .NET
uses: actions/setup-dotnet@v4

- name: Restore tool
run: dotnet tool restore

- name: Generate API reference using DocFX
run: yarn run api:generate
working-directory: ./docs

- name: Build
run: yarn run build
working-directory: ./docs
Expand Down
22 changes: 22 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ yarn start
This command starts a local development server and opens up a browser window. Most changes are reflected live without
having to restart the server.

### Generating the "API Reference" section

You can generate an API Reference section automatically based on the source code
using [DocFX](https://dotnet.github.io/docfx/) by running the following commands:

```shell
# restore the DocFX tool
dotnet tool restore

# generate markdown files using DocFX
yarn run generate-api-folder

# transform the generated markdown files
yarn run transform-api-folder

# or using one command that does both
yarn run api:generate

# to clean the generated files
yarn run api:clean
```

## Build

```shell
Expand Down
17 changes: 17 additions & 0 deletions docs/docfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"metadata": [
{
"src": [
{
"src": "../Consul",
"files": [
"**/*.csproj"
]
}
],
"dest": "api",
"output": ".",
"outputFormat": "markdown"
}
]
}
23 changes: 22 additions & 1 deletion docs/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const fs = require('node:fs');
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');

Expand All @@ -12,6 +13,7 @@ const consulDotNetVersion = clean_version(process.env.CONSUL_DOT_NET_VERSION ||
const consulAPIVersion = clean_version(extract_consul_version(consulDotNetVersion));
const url = process.env.URL || `https://consuldot.net`;
const baseUrl = process.env.BASE_URL || `/`;
const shouldIncludeApiReference = fs.existsSync('./api');

function clean_version(version) {
if (version) {
Expand Down Expand Up @@ -83,6 +85,18 @@ const config = {
],
],

plugins: [
shouldIncludeApiReference && [
'@docusaurus/plugin-content-docs',
{
id: 'api',
path: 'api',
routeBasePath: 'api',
sidebarPath: require.resolve('./sidebars.js'),
},
],
],

themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
Expand All @@ -101,6 +115,13 @@ const config = {
label: 'Docs',
position: 'left',
},
shouldIncludeApiReference && {
docsPluginId: 'api',
docId: 'Consul/README',
type: 'doc',
label: 'API Reference',
position: 'left',
},
{
to: '/docs/category/contributing',
label: 'Contribute',
Expand All @@ -126,7 +147,7 @@ const config = {
className: 'header-twitter-link',
'aria-label': 'Twitter',
},
],
].filter(Boolean),
},
footer: {
links: [
Expand Down
5 changes: 5 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"generate-api-folder": "dotnet tool run docfx metadata docfx.json",
"transform-api-folder": "node src/scripts/transformApiFolder.js --path=api",
"api:generate": "yarn generate-api-folder && yarn transform-api-folder",
"api:clean": "rimraf api",
"typecheck": "tsc"
},
"dependencies": {
Expand All @@ -28,6 +32,7 @@
"@docusaurus/module-type-aliases": "^2.3.1",
"@tsconfig/docusaurus": "^1.0.5",
"dotenv": "^16.0.3",
"js-yaml": "^4.1.0",
"typescript": "^4.7.4"
},
"browserslist": {
Expand Down
Loading
Loading