Skip to content

Commit 560dd4e

Browse files
authored
feat: add TSDoc (#6)
1 parent c76ec48 commit 560dd4e

File tree

8 files changed

+426
-9
lines changed

8 files changed

+426
-9
lines changed

.config/typedoc.css

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
.tsd-typography h4,
2+
.tsd-typography .tsd-index-panel h3,
3+
.tsd-index-panel .tsd-typography h3,
4+
.tsd-typography h5,
5+
.tsd-typography h6 {
6+
margin: 1.2em 0 0.4em 0;
7+
}
8+
9+
code {
10+
padding: 4px 6px;
11+
border-radius: 4px;
12+
}
13+
14+
pre {
15+
border-radius: 4px;
16+
padding: 8px 12px;
17+
border: none;
18+
overflow-x: auto;
19+
}
20+
21+
.tsd-page-toolbar {
22+
border-bottom: none;
23+
background: color-mix(in srgb, var(--color-background-secondary), transparent 20%);
24+
box-shadow: 0px -148px 86px 86px #000000;
25+
}
26+
27+
.tsd-page-toolbar .tsd-toolbar-contents {
28+
padding: 8px 2rem;
29+
}
30+
31+
.tsd-page-toolbar:before {
32+
width: 100%;
33+
position: absolute;
34+
content: "";
35+
height: 100%;
36+
z-index: -1;
37+
backdrop-filter: blur(6px);
38+
}
39+
40+
@media (min-width: 1200px) {
41+
.page-menu,
42+
.site-menu {
43+
top: 82px;
44+
}
45+
}
46+
47+
.tsd-navigation a,
48+
.tsd-navigation summary > span,
49+
.tsd-page-navigation a {
50+
margin: 4px 0px;
51+
padding: 0.25rem 0.55rem 0.25rem 0.3rem;
52+
border-radius: 4px;
53+
}.tsd-navigation a:not(:has(> svg)),
54+
.tsd-navigation summary > span:not(:has(> svg)),
55+
.tsd-page-navigation a:not(:has(> svg)) {
56+
padding: 0.25rem 0.55rem 0.25rem 0.4rem;
57+
}
58+
59+
.tsd-navigation a:hover,
60+
.tsd-navigation summary > span:hover,
61+
.tsd-page-navigation a:hover {
62+
/*opacity: 0.8;*/
63+
text-decoration: none;
64+
background-color: color-mix(in srgb, currentColor 12%, transparent);
65+
}
66+
67+
.tsd-navigation a.current,
68+
.tsd-page-navigation a.current {
69+
border-radius: 4px;
70+
}
71+
.tsd-navigation a.current:hover,
72+
.tsd-page-navigation a.current:hover {
73+
border-radius: 4px;
74+
background-color: color-mix(in srgb, var(--color-active-menu-item), transparent 16%);
75+
}
76+
77+
pre {
78+
position: relative;
79+
}
80+
81+
pre > button {
82+
background-color: color-mix(in srgb, currentColor 12%, transparent);
83+
border: none;
84+
padding: 6px 12px;
85+
border-radius: 4px;
86+
cursor: pointer;
87+
backdrop-filter: blur(6px);
88+
max-height: calc(100% - 8px * 2);
89+
display: flex;
90+
flex-direction: row;
91+
align-items: center;
92+
box-sizing: border-box;
93+
top: 8px;
94+
right: 8px;
95+
}
96+
pre > button:hover {
97+
background-color: color-mix(in srgb, currentColor 18%, transparent);
98+
}
99+
100+
h3 > svg {
101+
vertical-align: middle;
102+
margin-inline-end: 6px;
103+
transform-origin: 48% 38%;
104+
}
105+
106+
h5 > svg {
107+
vertical-align: middle;
108+
margin-inline-end: 6px;
109+
transform-origin: 48% 38%;
110+
}
111+
112+
#tsd-search {
113+
border-radius: 4px;
114+
}
115+
116+
ul.tsd-hierarchy>li {
117+
margin: 12px 0px;
118+
list-style: disc;
119+
}
120+
121+
ul.tsd-hierarchy {
122+
padding-inline-start: 24px;
123+
}
124+
125+
code.tsd-tag {
126+
border: none;
127+
box-shadow: 0px 0px 8px -2px var(--color-accent);
128+
}
129+
130+
h1 code.tsd-tag:first-of-type {
131+
margin-left: 0.55em;
132+
}
133+
134+
.tsd-page-toolbar a.title:hover {
135+
text-decoration: none;
136+
background-color: color-mix(in srgb, currentColor 12%, transparent);
137+
padding: 4px 8px;
138+
margin: -4px -8px;
139+
border-radius: 4px;
140+
}
141+
142+
a.tsd-index-link {
143+
padding: 4px !important;
144+
}
145+
146+
a.tsd-index-link:hover {
147+
text-decoration: none;
148+
background-color: color-mix(in srgb, currentColor 12%, transparent);
149+
border-radius: 8px;
150+
}
151+
152+
h1:not(.tsd-anchor-link, .tsd-returns-title) > a:hover,
153+
h2:not(.tsd-anchor-link, .tsd-returns-title) > a:hover,
154+
h3:not(.tsd-anchor-link, .tsd-returns-title) > a:hover,
155+
h4:not(.tsd-anchor-link, .tsd-returns-title) > a:hover,
156+
h5:not(.tsd-anchor-link, .tsd-returns-title) > a:hover,
157+
h6:not(.tsd-anchor-link, .tsd-returns-title) > a:hover {
158+
text-decoration: none;
159+
color: var(--color-text);
160+
}
161+
162+
h1:not(.tsd-anchor-link, .tsd-returns-title) > a:hover:before,
163+
h2:not(.tsd-anchor-link, .tsd-returns-title) > a:hover:before,
164+
h3:not(.tsd-anchor-link, .tsd-returns-title) > a:hover:before,
165+
h4:not(.tsd-anchor-link, .tsd-returns-title) > a:hover:before,
166+
h5:not(.tsd-anchor-link, .tsd-returns-title) > a:hover:before,
167+
h6:not(.tsd-anchor-link, .tsd-returns-title) > a:hover:before {
168+
content: "";
169+
position: absolute;
170+
height: calc(1ex + (1lh - 1ex)/2);
171+
margin-top: calc(0.2 * 1ex);
172+
margin-left: -8px;
173+
width: 3px;
174+
background-color: currentColor;
175+
border-radius: 9999px;
176+
opacity: 0.4;
177+
pointer-events: none;
178+
}
179+
180+
#tsd-search.has-focus {
181+
background-color: color-mix(in srgb, var(--color-accent), transparent 60%);
182+
}
183+
184+
#tsd-search .field input {
185+
padding: 12px 16px;
186+
}
187+
188+
#tsd-search .results li {
189+
padding: 0px 16px;
190+
}
191+
192+
#tsd-search .results li {
193+
padding: 0px 16px;
194+
background-color: color-mix(in srgb, var(--color-background), transparent 20%);
195+
}
196+
197+
#tsd-search .results li:nth-child(even) {
198+
background-color: color-mix(in srgb, var(--color-background), transparent 20%);
199+
}
200+
201+
#tsd-search .results li.current,
202+
#tsd-search .results li:hover {
203+
background-color: color-mix(in srgb, var(--color-accent), transparent 20%);
204+
}
205+
206+
#tsd-search.has-focus .results {
207+
backdrop-filter: blur(6px);
208+
}
209+
210+
.container-main {
211+
margin-top: 16px;
212+
}

.config/typedoc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://typedoc.org/schema.json",
3+
"entryPoints": ["../src/index.ts"],
4+
"out": "../docs",
5+
"tsconfig": "../tsconfig.json",
6+
"customCss": "./typedoc.css",
7+
"readme": "../README.md",
8+
"excludeExternals": true,
9+
"excludeInternal": true,
10+
"excludePrivate": true,
11+
"githubPages": true,
12+
"hideGenerator": true,
13+
"jsDocCompatibility": true,
14+
"htmlLang": "en"
15+
}

.github/workflows/build.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ jobs:
1717
run: npm ci --ignore-scripts
1818
- name: Build
1919
run: npm run build
20+
- name: Generate docs
21+
run: npm run generate-docs
2022
- name: Download latest llama.cpp release
2123
run: node ./dist/cli/cli.js download --release latest --skipBuild
2224
- name: Upload build artifact
2325
uses: actions/upload-artifact@v3
2426
with:
2527
name: "build"
2628
path: "dist"
29+
- name: Upload build artifact
30+
uses: actions/upload-artifact@v3
31+
with:
32+
name: "docs"
33+
path: "docs"
2734
- name: Upload llama.cpp artifact
2835
uses: actions/upload-artifact@v3
2936
with:
@@ -191,7 +198,12 @@ jobs:
191198
if: github.ref == 'refs/heads/master'
192199
runs-on: ubuntu-latest
193200
concurrency: release-${{ github.ref }}
201+
environment:
202+
name: npm
203+
url: ${{ steps.set-npm-url.outputs.npm-url }}
194204
permissions:
205+
pages: write
206+
id-token: write
195207
contents: write
196208
issues: write
197209
pull-requests: write
@@ -213,6 +225,7 @@ jobs:
213225
mkdir -p llamaBins
214226
mv artifacts/bins-*/* llamaBins/
215227
mv artifacts/build dist/
228+
mv artifacts/docs docs/
216229
217230
echo "Built binaries:"
218231
ls llamaBins
@@ -221,4 +234,20 @@ jobs:
221234
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
222235
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
223236
run: npx semantic-release
224-
237+
- name: Set npm package url to GITHUB_OUTPUT
238+
id: set-npm-url
239+
run: |
240+
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
241+
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
242+
fi
243+
- name: Upload docs to GitHub Pages
244+
if: steps.set-npm-url.outputs.npm-url != ''
245+
uses: actions/upload-pages-artifact@v2
246+
with:
247+
name: pages-docs
248+
path: docs
249+
- name: Deploy docs to GitHub Pages
250+
if: steps.set-npm-url.outputs.npm-url != ''
251+
uses: actions/deploy-pages@v2
252+
with:
253+
artifact_name: pages-docs

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules
44
.DS_Store
55

66
/dist
7+
/docs
78

89
/.env
910
/.eslintcache

.releaserc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
}],
1313
"@semantic-release/release-notes-generator",
1414
"@semantic-release/npm",
15-
"@semantic-release/github"
15+
"@semantic-release/github",
16+
["@semantic-release/exec", {
17+
"publishCmd": "echo \"${nextRelease.version}\" > .semanticRelease.npmPackage.deployedVersion.txt"
18+
}]
1619
]
1720
}

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ If binaries are not available for your platform, it'll fallback to download the
1818
To disable this behavior set the environment variable `NODE_LLAMA_CPP_SKIP_DOWNLOAD` to `true`.
1919

2020
## Documentation
21+
### [API reference](https://withcatai.github.io/node-llama-cpp/modules.html)
22+
2123
### Usage
2224
#### As a chatbot
2325
```typescript
@@ -129,7 +131,7 @@ console.log("AI: " + a1);
129131
```
130132

131133
### CLI
132-
```txt
134+
```
133135
Usage: node-llama-cpp <command> [options]
134136
135137
Commands:
@@ -140,11 +142,11 @@ Commands:
140142
141143
Options:
142144
-h, --help Show help [boolean]
143-
-v, --version Show version number [boolean] [boolean]
145+
-v, --version Show version number [boolean]
144146
```
145147

146148
#### `download` command
147-
```txt
149+
```
148150
node-llama-cpp download
149151
150152
Download a release of llama.cpp and compile it
@@ -162,7 +164,7 @@ Options:
162164
```
163165

164166
#### `build` command
165-
```txt
167+
```
166168
node-llama-cpp build
167169
168170
Compile the currently downloaded llama.cpp
@@ -175,7 +177,7 @@ Options:
175177
```
176178

177179
#### `clear` command
178-
```txt
180+
```
179181
node-llama-cpp clear [type]
180182
181183
Clear files created by llama-cli
@@ -187,7 +189,7 @@ Options:
187189
```
188190

189191
#### `chat` command
190-
```txt
192+
```
191193
node-llama-cpp chat
192194
193195
Chat with a LLama model

0 commit comments

Comments
 (0)