Skip to content

Commit

Permalink
docs: Render docs as GitBook (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsonevv authored Oct 16, 2024
1 parent 9623545 commit 503e122
Show file tree
Hide file tree
Showing 5 changed files with 566 additions and 191 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/typedoc-generate-gitbook-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy TypeDoc to GitBook

on:
push:
branches:
- develop

env:
NODE_VERSION: 18.x
ENTRY_FILE: "packages"
CONFIG_PATH: "tsconfig.base.json"
USES_PNPM: "true"

jobs:
deploy:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies
run: pnpm install --no-frozen-lockfile

- name: Build project
run: pnpm build

- name: Build documentation
run: pnpm docs:generate-markdown

- name: Deploy to GitBook
run: |
git clone --branch=git-book https://github.com/near/near-sdk-js.git book
rsync -av --delete markdown-docs/ book/
cd book
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add .
git commit -m "Update documentation [skip ci]"
git push https://frol:${{ secrets.MY_GITHUB_TOKEN }}@github.com/near/near-sdk-js.git git-book
25 changes: 25 additions & 0 deletions generate-docs-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { readFileSync, writeFileSync, unlinkSync } = require("fs");
const { execSync } = require("child_process");

// Load the base configuration from typedoc.json
const baseConfig = JSON.parse(readFileSync("./typedoc.json", "utf8"));

// Extend the base configuration for Markdown documentation
const markdownConfig = {
...baseConfig,
githubPages: false,
out: "markdown-docs",
plugin: ["typedoc-plugin-markdown"],
};

// Write the extended configuration to a temporary file
const configFilePath = "./typedoc-markdown.json";
writeFileSync(configFilePath, JSON.stringify(markdownConfig, null, 2));

// Run TypeDoc with the extended configuration
try {
execSync(`npx typedoc --options ${configFilePath}`, { stdio: "inherit" });
} finally {
// Clean up the temporary file
unlinkSync(configFilePath);
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"test": "turbo run test",
"lint": "turbo run lint",
"format": "turbo run format",
"docs:generate": "typedoc"
"docs:generate": "typedoc",
"docs:generate-markdown": "node generate-docs-markdown.js"
},
"devDependencies": {
"turbo": "1.10.16",
"typedoc": "0.25.4",
"typedoc": "0.26.6",
"typedoc-plugin-markdown": "4.2.6",
"typescript": "4.7.4"
}
}
}
Loading

0 comments on commit 503e122

Please sign in to comment.