Skip to content

Commit 375367a

Browse files
committed
docs: update with auto generated examples!
1 parent 03a71a5 commit 375367a

File tree

8 files changed

+106
-71
lines changed

8 files changed

+106
-71
lines changed

docs/.config/automd.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { defineGenerator, type Config } from "../../src";
2+
3+
export default <Config>{
4+
generators: {
5+
example: defineGenerator({
6+
name: "example",
7+
async generate({ args, transform }) {
8+
const { generator, ...generatorArgs } = args;
9+
10+
const argsString = Object.entries(generatorArgs)
11+
.map(([k, v]) => `${k}=${v}`)
12+
.join(" ");
13+
14+
const input = `<!-- automd:${generator} ${argsString} -->\n<!-- /automd -->`;
15+
const output = (await transform(input)).contents;
16+
return {
17+
contents: `## Example\n\n### Input\n\n${_mdCode(input)}\n\n### Output\n\n${_mdCode(output)}`,
18+
};
19+
},
20+
}),
21+
},
22+
};
23+
24+
function _mdCode(md: string) {
25+
return md
26+
.split("\n")
27+
.map((l) => ` ${l}`)
28+
.join("\n");
29+
}

docs/docs.config.jsonc renamed to docs/.config/docs.jsonc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"$schema": "https://cdn.jsdelivr.net/gh/unjs/docs/schema/config.json",
3-
"name": "automd",
4-
"description": "",
5-
"shortDescription": "automated markdown maintainer!",
3+
"name": "AutoMD",
4+
"description": "your automated markdown maintainer.",
5+
"shortDescription": "Markdown, Automated.",
66
"github": "unjs/automd",
77
"url": "https://automd.unjs.io",
88
"redirects": {

docs/1.guide/1.index.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ Automd scans for the annotation comments within the markdown document and update
44

55
The syntax is like this:
66

7-
```markdown
8-
<!-- automd:generator [...args] -->
9-
<!-- /automd -->
10-
```
7+
<!-- automd:generator [...args] -->
8+
<!-- /automd -->
119

1210
> [!NOTE]
1311
> This project is in the early stages and under development.

docs/2.generators/badges.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
The `badges` generator generates badges for the latest npm version, npm download statistics, code coverage, and bundle size.
44

5-
## Usage
5+
<!-- automd:example generator=badges color=yellow license name=defu codecov bundlephobia -->
66

7-
```md
8-
<!-- automd:badges color=yellow license name=defu codecov bundlephobia -->
9-
<!-- /automd -->
10-
```
7+
## Example
8+
9+
### Input
1110

12-
**Updated Result:**
11+
<!-- automd:badges color=yellow license=true name=defu codecov=true bundlephobia=true -->
12+
<!-- /automd -->
1313

14-
```md
15-
<!-- automd:badges color=yellow name=defu license codecov bundlephobia -->
14+
### Output
1615

17-
[![npm version](https://flat.badgen.net/npm/v/defu?color=yellow)](https://npmjs.com/package/defu)
18-
[![npm downloads](https://flat.badgen.net/npm/dm/defu?color=yellow)](https://npmjs.com/package/defu)
19-
[![bundle size](https://flat.badgen.net/bundlephobia/minzip/defu?color=yellow)](https://bundlephobia.com/package/defu)
20-
[![codecov](https://flat.badgen.net/codecov/c/github/unjs/automd?color=yellow)](https://codecov.io/gh/unjs/automd)
21-
[![license](https://flat.badgen.net/github/license/unjs/automd?color=yellow)](https://github.com/unjs/automd/blob/main/LICENSE)
16+
<!-- automd:badges color=yellow license=true name=defu codecov=true bundlephobia=true -->
17+
18+
[![npm version](https://flat.badgen.net/npm/v/defu?color=yellow)](https://npmjs.com/package/defu)
19+
[![npm downloads](https://flat.badgen.net/npm/dm/defu?color=yellow)](https://npmjs.com/package/defu)
20+
[![bundle size](https://flat.badgen.net/bundlephobia/minzip/defu?color=yellow)](https://bundlephobia.com/package/defu)
21+
22+
<!-- /automd -->
2223

2324
<!-- /automd -->
24-
```
2525

2626
## Arguments
2727

docs/2.generators/jsdocs.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@ The `jsdocs` generator can automatically read through your code and extract and
44

55
Internally it uses [untyped](https://untyped.unjs.io/) and [jiti](https://github.com/unjs/jiti) loader for JSDocs parsing and TypeScript support.
66

7-
## Usage
7+
<!-- automd:example generator=jsdocs src="../test/fixture/src/index" -->
88

9-
```md
10-
<!-- automd:jsdocs src="./src/index" -->
11-
<!-- /automd -->
12-
```
13-
14-
> [!NOTE]
15-
> Make sure you have some utility exports in `src/index.ts` annotated with JSDocs.
16-
17-
**Updated Result:**
18-
19-
````md
20-
<!-- automd:jsdocs src="./src/index" -->
9+
## Example
2110

22-
### `add(a, b)`
11+
### Input
2312

24-
Adds two numbers together.
13+
<!-- automd:jsdocs src=../test/fixture/src/index -->
14+
<!-- /automd -->
2515

26-
**Example:**
16+
### Output
2717

28-
```js
29-
add(1, 2); // 3
30-
```
18+
<!-- automd:jsdocs src=../test/fixture/src/index -->
19+
20+
### `add(a, b)`
21+
22+
Adds two numbers together.
23+
24+
**Example:**
25+
26+
```js
27+
add(1, 2); // 3
28+
```
29+
30+
31+
<!-- /automd -->
3132

3233
<!-- /automd -->
33-
````
3434

3535
## Arguments
3636

docs/2.generators/pm-install.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,40 @@
22

33
The `pm-install` or `pm-i` generator generates installation commands for several JavaScript package managers.
44

5-
## Usage
5+
<!-- automd:example generator=pm-install name=package-name dev -->
66

7-
```md
8-
<!-- automd:pm-install name=package-name dev -->
9-
<!-- /automd -->
10-
```
7+
## Example
8+
9+
### Input
1110

12-
**Updated Result:**
11+
<!-- automd:pm-install name=package-name dev=true -->
12+
<!-- /automd -->
1313

14-
<!-- automd:pm-install name=package-name dev -->
14+
### Output
1515

16+
<!-- automd:pm-install name=package-name dev=true -->
17+
1618
```sh
1719
# ✨ Auto-detect
18-
npx nypm i -D package-name
19-
20+
npx nypm i -D package-name@^0.2.0
21+
2022
# npm
21-
npm install -D package-name
22-
23+
npm install -D package-name@^0.2.0
24+
2325
# yarn
24-
yarn add -D package-name
25-
26+
yarn add -D package-name@^0.2.0
27+
2628
# pnpm
27-
pnpm install -D package-name
28-
29+
pnpm install -D package-name@^0.2.0
30+
2931
# bun
30-
bun install -D package-name
32+
bun install -D package-name@^0.2.0
3133
```
32-
34+
3335
<!-- /automd -->
3436

37+
<!-- /automd -->
38+
3539
## Arguments
3640

3741
- `name`: The package name (by default tries to read from the `name` field in `package.json`).

docs/2.generators/pm-x.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@
22

33
The `pm-x` generator generates commands for running/executing a package through JavaScript package managers.
44

5-
## Usage
5+
<!-- automd:example generator=pm-x name="package-name" args="[files] <flags>" -->
66

7-
```md
8-
<!-- automd:pm-x name="package-name" args="[files] <flags>" -->
9-
<!-- /automd -->
10-
```
7+
## Example
8+
9+
### Input
1110

12-
**Updated Result:**
11+
<!-- automd:pm-x name=package-name args="[files] <flags>"=true -->
12+
<!-- /automd -->
1313

14-
<!-- automd:pm-x name="package-name" args="[files] <flags>" -->
14+
### Output
1515

16+
<!-- automd:pm-x name=package-name args="[files] <flags>"=true -->
17+
1618
```sh
1719
# npm
18-
npx package-name@latest [files] <flags>
19-
20+
npx package-name@0.2.0 "[files]
21+
2022
# pnpm
21-
pnpm dlx package-name@latest [files] <flags>
22-
23+
pnpm dlx package-name@0.2.0 "[files]
24+
2325
# bun
24-
bunx package-name@latest [files] <flags>
26+
bunx package-name@0.2.0 "[files]
2527
```
26-
28+
2729
<!-- /automd -->
2830

31+
<!-- /automd -->
32+
2933
## Arguments
3034

3135
- `name`: The package name (by default tries to read from the `name` field in `package.json`).

docs/bun.lockb

792 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)