Skip to content

Commit 503e122

Browse files
authored
docs: Render docs as GitBook (#413)
1 parent 9623545 commit 503e122

File tree

5 files changed

+566
-191
lines changed

5 files changed

+566
-191
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Deploy TypeDoc to GitBook
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
env:
9+
NODE_VERSION: 18.x
10+
ENTRY_FILE: "packages"
11+
CONFIG_PATH: "tsconfig.base.json"
12+
USES_PNPM: "true"
13+
14+
jobs:
15+
deploy:
16+
concurrency: ci-${{ github.ref }}
17+
runs-on: ubuntu-latest
18+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
19+
permissions:
20+
contents: write
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-node@v3
25+
with:
26+
node-version: ${{ env.NODE_VERSION }}
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@v4
30+
with:
31+
version: 9
32+
33+
- name: Install dependencies
34+
run: pnpm install --no-frozen-lockfile
35+
36+
- name: Build project
37+
run: pnpm build
38+
39+
- name: Build documentation
40+
run: pnpm docs:generate-markdown
41+
42+
- name: Deploy to GitBook
43+
run: |
44+
git clone --branch=git-book https://github.com/near/near-sdk-js.git book
45+
rsync -av --delete markdown-docs/ book/
46+
cd book
47+
git config user.name "GitHub Actions"
48+
git config user.email "[email protected]"
49+
git add .
50+
git commit -m "Update documentation [skip ci]"
51+
git push https://frol:${{ secrets.MY_GITHUB_TOKEN }}@github.com/near/near-sdk-js.git git-book

generate-docs-markdown.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { readFileSync, writeFileSync, unlinkSync } = require("fs");
2+
const { execSync } = require("child_process");
3+
4+
// Load the base configuration from typedoc.json
5+
const baseConfig = JSON.parse(readFileSync("./typedoc.json", "utf8"));
6+
7+
// Extend the base configuration for Markdown documentation
8+
const markdownConfig = {
9+
...baseConfig,
10+
githubPages: false,
11+
out: "markdown-docs",
12+
plugin: ["typedoc-plugin-markdown"],
13+
};
14+
15+
// Write the extended configuration to a temporary file
16+
const configFilePath = "./typedoc-markdown.json";
17+
writeFileSync(configFilePath, JSON.stringify(markdownConfig, null, 2));
18+
19+
// Run TypeDoc with the extended configuration
20+
try {
21+
execSync(`npx typedoc --options ${configFilePath}`, { stdio: "inherit" });
22+
} finally {
23+
// Clean up the temporary file
24+
unlinkSync(configFilePath);
25+
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
"test": "turbo run test",
1111
"lint": "turbo run lint",
1212
"format": "turbo run format",
13-
"docs:generate": "typedoc"
13+
"docs:generate": "typedoc",
14+
"docs:generate-markdown": "node generate-docs-markdown.js"
1415
},
1516
"devDependencies": {
1617
"turbo": "1.10.16",
17-
"typedoc": "0.25.4",
18+
"typedoc": "0.26.6",
19+
"typedoc-plugin-markdown": "4.2.6",
1820
"typescript": "4.7.4"
1921
}
20-
}
22+
}

0 commit comments

Comments
 (0)