Skip to content

Commit 30f606f

Browse files
authored
Merge pull request #159 from hyperweb-io/anmol/docs
docs: add docs from docs repo to product repo, add gh-action to sync repos
2 parents 03e9204 + 75da9e2 commit 30f606f

File tree

6 files changed

+903
-0
lines changed

6 files changed

+903
-0
lines changed

.github/workflows/docs.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "docs/**"
9+
- ".github/workflows/docs.yaml"
10+
11+
env:
12+
# Repository specific variables
13+
REPO_NAME: ts-codegen
14+
DOCS_DEST_PATH: pages/ts-codegen
15+
16+
jobs:
17+
docs-deploy:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '20'
28+
enable-global-cache: true
29+
30+
- name: Clone docs repository
31+
run: git clone https://x-access-token:${{ secrets.GH_HYPERWEB_PAT }}@github.com/hyperweb-io/docs.hyperweb.io.git external-docs
32+
33+
- name: Sync the docs and build
34+
run: |
35+
rsync -av --delete ./docs/ ./external-docs/${{ env.DOCS_DEST_PATH }}/
36+
cd external-docs
37+
yarn install
38+
yarn export
39+
40+
- name: Git push
41+
run: |
42+
cd external-docs
43+
git config user.name 'GitHub Action'
44+
git config user.email '[email protected]'
45+
git add .
46+
if git diff --cached --quiet; then
47+
echo "No changes to commit."
48+
else
49+
git commit -m "Automated: Update ${{ env.REPO_NAME }} documentation"
50+
git push
51+
fi
52+

docs/_meta.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"index": "Introduction",
3+
"developing": "Developing"
4+
}

docs/developing/_meta.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"index": "Developing",
3+
"ast": "Working with ASTs"
4+
}

docs/developing/ast.mdx

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
## Working with ASTs
2+
3+
### 1 edit the fixture
4+
5+
edit `./scripts/fixture.ts`, for example:
6+
7+
```js
8+
// ./scripts/fixture.ts
9+
export interface InstantiateMsg {
10+
admin?: string | null;
11+
members: Member[];
12+
}
13+
```
14+
15+
### 2 run AST generator
16+
17+
```
18+
yarn test:ast
19+
```
20+
21+
### 3 look at the JSON produced
22+
23+
```
24+
code ./scripts/test-output.json
25+
```
26+
27+
We use the npm module `ast-stringify` to strip out unnecessary props, and generate a JSON for reference.
28+
29+
You will see a `File` and `Program`... only concern yourself with the `body[]`:
30+
31+
```json
32+
{
33+
"type": "File",
34+
"errors": [],
35+
"program": {
36+
"type": "Program",
37+
"sourceType": "module",
38+
"interpreter": null,
39+
"body": [
40+
{
41+
"type": "ExportNamedDeclaration",
42+
"exportKind": "type",
43+
"specifiers": [],
44+
"source": null,
45+
"declaration": {
46+
"type": "TSInterfaceDeclaration",
47+
"id": {
48+
"type": "Identifier",
49+
"name": "InstantiateMsg"
50+
},
51+
"body": {
52+
"type": "TSInterfaceBody",
53+
"body": [
54+
{
55+
"type": "TSPropertySignature",
56+
"key": {
57+
"type": "Identifier",
58+
"name": "admin"
59+
},
60+
"computed": false,
61+
"optional": true,
62+
"typeAnnotation": {
63+
"type": "TSTypeAnnotation",
64+
"typeAnnotation": {
65+
"type": "TSUnionType",
66+
"types": [
67+
{
68+
"type": "TSStringKeyword"
69+
},
70+
{
71+
"type": "TSNullKeyword"
72+
}
73+
]
74+
}
75+
}
76+
},
77+
{
78+
"type": "TSPropertySignature",
79+
"key": {
80+
"type": "Identifier",
81+
"name": "members"
82+
},
83+
"computed": false,
84+
"typeAnnotation": {
85+
"type": "TSTypeAnnotation",
86+
"typeAnnotation": {
87+
"type": "TSArrayType",
88+
"elementType": {
89+
"type": "TSTypeReference",
90+
"typeName": {
91+
"type": "Identifier",
92+
"name": "Member"
93+
}
94+
}
95+
}
96+
}
97+
}
98+
]
99+
}
100+
}
101+
}
102+
],
103+
"directives": []
104+
},
105+
"comments": []
106+
}
107+
```
108+
109+
### 4 code with `@babel/types` using the JSON as a reference
110+
111+
NOTE: 4 continued ideally you should be writing a test with your generator!
112+
113+
```js
114+
import * as t from '@babel/types';
115+
116+
export const createNewGenerator = () => {
117+
return t.exportNamedDeclaration(
118+
t.tsInterfaceDeclaration(
119+
t.identifier('InstantiateMsg'),
120+
null,
121+
[],
122+
t.tsInterfaceBody([
123+
// ... more code ...
124+
])
125+
)
126+
);
127+
};
128+
```

docs/developing/index.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Developing
2+
3+
## Initial setup
4+
5+
```
6+
yarn
7+
yarn bootstrap
8+
```
9+
10+
## Building
11+
12+
```
13+
yarn build
14+
```
15+
16+
## Tests
17+
18+
Then `cd` into a package and run the tests
19+
20+
```
21+
cd ./packages/wasm-ast-types
22+
yarn test:watch
23+
```
24+
25+
## Working with ASTs
26+
27+
See the [docs](/ts-codegen/developing/ast) in the `wasm-ast-types` package.

0 commit comments

Comments
 (0)