Skip to content

Commit

Permalink
SDK API reference (#733)
Browse files Browse the repository at this point in the history
Refs: #699

Here we add the [`typedoc`](https://typedoc.org) tool in order to
generate a Markdown API reference from the TSDoc comments. The generated
API reference is stored in the `api-reference` directory of the SDK
module.

The API reference docs can be re-generated using:
```
yarn docs
```

The new CI job `typescript-docs` checks whether the API reference was
re-generated after source code changes. If there is a need to do that,
this job fails at the `Check docs up to date` step.

To facilitate work, a pre-commit hook `typescript-docs` was added. It
automatically runs `yarn docs` before each commit. If there are any
changes in the API reference, the pre-commit hook fails but the file
changes remain so it's enough to do Git commit again. To leverage the
new hook, it's enough to run this command in the `tbtc-v2` repository
root directory:
```
pre-commit install
```

By the way, we are also setting the `repository` section in the SDK
`package.json` (this was previously done by mistake in the `solidity`
directory).
  • Loading branch information
tomaszslabon authored Nov 3, 2023
2 parents 673f11c + beceee2 commit f78fe38
Show file tree
Hide file tree
Showing 57 changed files with 8,183 additions and 33 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,36 @@ jobs:

- name: Check formatting
run: yarn format

typescript-docs:
needs: typescript-detect-changes
if: |
github.event_name == 'push'
|| needs.typescript-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./typescript
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "yarn"
cache-dependency-path: typescript/yarn.lock

- name: Configure git to don't use unauthenticated protocol
run: git config --global url."https://".insteadOf git://

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

- name: Generate docs
run: yarn docs

- name: Check docs up to date
run: git diff --exit-code || exit 1
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ repos:
files: "^cross-chain/arbitrum/"
language: script
description: "Checks cross-chain/arbitrum directory code according to the formatting configuration"
- id: typescript-docs
name: "Generate typescript API reference docs"
entry: /usr/bin/env bash -c "cd typescript && yarn docs"
files: "^typescript/"
language: script
description: "Generates typescript API reference docs according to the typedoc configuration"
5 changes: 0 additions & 5 deletions solidity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,5 @@
},
"engines": {
"node": ">= 14.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/keep-network/tbtc-v2.git",
"directory": "typescript"
}
}
1 change: 1 addition & 0 deletions typescript/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
node_modules/
typechain/
api-reference/
1 change: 1 addition & 0 deletions typescript/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
external/
typechain/
api-reference/
14 changes: 14 additions & 0 deletions typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trustless tokenized Bitcoin to their users.
- [Build](#build)
- [Test](#test)
- [Format](#format)
- [Auto-generated API reference](#auto-generated-api-reference)
- [Documentation](#documentation)

## Quickstart
Expand Down Expand Up @@ -134,6 +135,19 @@ To format code automatically, invoke:
yarn format:fix
```

### Auto-generated API reference

There is an auto-generated API reference documentation that must be
re-generated in case of modifications in the source code. This can be
done automatically using a pre-commit hook or manually using:

```bash
yarn docs
```

Generated API reference in form of Markdown files is saved
to the [`api-reference`](./api-reference) directory.

## Documentation

This README provides just a basic guidance. Comprehensive documentation for
Expand Down
Loading

0 comments on commit f78fe38

Please sign in to comment.