Skip to content

Commit 2532fff

Browse files
authored
docs: move docs closer to code (#40)
1 parent ec45a21 commit 2532fff

File tree

7 files changed

+101
-122
lines changed

7 files changed

+101
-122
lines changed

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
dist/
22
src/content/tmp/
3+
src/content/docs/cli/
34
src/content/docs/core/api/
5+
src/content/docs/plugins/vite/
46
src/content/docs/changelog.md

docs/src/content/docs/_sidebar.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@
1313
"items": [
1414
{
1515
"label": "Vite",
16-
"link": "/plugins/vite"
16+
"collapsed": true,
17+
"autogenerate": {
18+
"collapsed": true,
19+
"directory": "plugins/vite"
20+
}
1721
}
1822
]
1923
},
2024
{
2125
"label": "CLI",
22-
"link": "/cli"
26+
"collapsed": true,
27+
"autogenerate": {
28+
"collapsed": true,
29+
"directory": "cli"
30+
}
2331
},
2432
{
2533
"label": "Library",

docs/src/content/docs/cli.md

Lines changed: 0 additions & 47 deletions
This file was deleted.

docs/src/content/docs/plugins/vite.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

docs/typedoc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"$schema": "https://typedoc-plugin-markdown.org/schema.json",
3-
"entryPoints": ["../src/core/index.ts"],
3+
"entryPoints": [
4+
"../src/core/index.ts",
5+
"../src/cli/icp-bindgen.ts",
6+
"../src/plugins/vite.ts"
7+
],
48
"tsconfig": "../tsconfig.json",
59
"readme": "none",
610
"out": "src/content/tmp",

src/cli/icp-bindgen.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
#!/usr/bin/env node
22

3+
/**
4+
* The CLI is used to generate bindings for a `.did` file.
5+
*
6+
* ## Installation
7+
*
8+
* As a dev dependency for your project:
9+
*
10+
* ```bash
11+
* npm install -D @icp-sdk/bindgen
12+
* ```
13+
*
14+
* Or as a global command:
15+
*
16+
* ```bash
17+
* npm install -g @icp-sdk/bindgen
18+
* ```
19+
*
20+
* ## Usage
21+
*
22+
* Suppose you have a `./canisters/hello_world.did` file, and you want to output the generated bindings for your Vite app in the `src/bindings/` folder.
23+
*
24+
* You can generate the bindings with the following command:
25+
*
26+
* ```bash
27+
* icp-bindgen --did-file ./canisters/hello_world.did --out-dir ./src/bindings
28+
* ```
29+
*
30+
* For an explanation of the generated files, see the [Bindings Structure](https://js.icp.build/bindgen/latest/structure/) page.
31+
*
32+
* ### Usage without installation
33+
*
34+
* ```bash
35+
* npx @icp-sdk/bindgen --did-file ./canisters/hello_world.did --out-dir ./src/bindings
36+
* ```
37+
*
38+
* ### Options
39+
*
40+
* - `--did-file <path>`: Path to the `.did` file to generate bindings from
41+
* - `--out-dir <dir>`: Directory where the bindings will be written
42+
* - `--actor-interface-file`: If set, generates a `<service-name>.d.ts` file that contains the same types of the `<service-name>.ts` file. Has no effect if `--actor-disabled` is set. (default: `false`)
43+
* - `--actor-disabled`: If set, skips generating the actor file (`<service-name>.ts`). (default: `false`)
44+
* - `--force`: If set, overwrite existing files instead of aborting. (default: `false`)
45+
*
46+
* > **Note**: The CLI does not support additional features yet.
47+
*
48+
* @module cli
49+
*/
50+
351
import { Command } from 'commander';
452
import { BIN_NAME, PACKAGE_VERSION } from '../core/constants.ts';
553
import { generate } from '../core/generate/index.ts';

src/plugins/vite.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
/**
2+
* The Vite plugin is used to generate bindings for a `.did` file during the build process.
3+
*
4+
* ## Installation
5+
*
6+
* ```bash
7+
* npm install -D @icp-sdk/bindgen
8+
* ```
9+
*
10+
* ## Usage
11+
*
12+
* Suppose you have a `./canisters/hello_world.did` file, and you want to output the generated bindings for your Vite app in the `src/bindings/` folder.
13+
* Here's how the plugin configuration would look like:
14+
*
15+
* ```ts title="vite.config.ts"
16+
* import { defineConfig } from "vite";
17+
* import { icpBindgen } from '@icp-sdk/bindgen/plugins/vite';
18+
*
19+
* export default defineConfig({
20+
* plugins: [
21+
* // ... other plugins
22+
* icpBindgen({
23+
* didFile: './canisters/hello_world.did',
24+
* outDir: './src/bindings',
25+
* }),
26+
* ],
27+
* });
28+
* ```
29+
*
30+
* For an explanation of the generated files, see the [Bindings Structure](https://js.icp.build/bindgen/latest/structure/) page.
31+
*
32+
* @module plugins/vite
33+
*/
34+
135
import { resolve } from 'node:path';
236
import type { Plugin, ViteDevServer } from 'vite';
337
import {
@@ -51,6 +85,8 @@ export interface Options extends Omit<GenerateOptions, 'output'> {
5185
* ],
5286
* });
5387
* ```
88+
*
89+
* @ignore
5490
*/
5591
export function icpBindgen(options: Options): Plugin {
5692
return {

0 commit comments

Comments
 (0)