Skip to content

Commit 361cd50

Browse files
committed
chore: set automd config for repo
1 parent ea0667a commit 361cd50

File tree

8 files changed

+55
-61
lines changed

8 files changed

+55
-61
lines changed

.config/automd.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { defineGenerator, type Config } from "automd";
2+
import { kebabCase } from "scule";
3+
4+
export default <Config>{
5+
input: ["README.md", "docs/**/*.md"],
6+
ignore: ["test/fixture/**"],
7+
generators: {
8+
example: defineGenerator({
9+
name: "example",
10+
async generate({ args, transform }) {
11+
const { generator, ...generatorArgs } = args;
12+
13+
const argsString = Object.entries(generatorArgs)
14+
.map(([k, v]) => {
15+
if (v === true) {
16+
return k;
17+
}
18+
if (v === false) {
19+
return k.startsWith("no-") ? k.slice(3) : `no-${k}`;
20+
}
21+
return `${kebabCase(k)}=${JSON.stringify(v)}`;
22+
})
23+
.join(" ")
24+
.trim();
25+
26+
const input = `<!-- automd:${generator} ${argsString} -->\n<!-- /automd -->`;
27+
const output = (await transform(input)).contents;
28+
return {
29+
contents: `### Input\n\n${_mdCode(input)}\n\n### Output\n\n${_mdCode(output)}`,
30+
};
31+
},
32+
}),
33+
},
34+
};
35+
36+
function _mdCode(md: string) {
37+
return md
38+
.split("\n")
39+
.map((l) => ` ${l}`)
40+
.join("\n");
41+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/a
4646

4747
---
4848

49-
_🤖 auto updated with [automd](https://automd.unjs.io) (last updated: Tue Feb 20 2024)_
49+
_🤖 auto updated with [automd](https://automd.unjs.io)_
5050

5151
<!-- /automd -->

docs/.config/automd.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1 @@
1-
import { defineGenerator, type Config } from "automd";
2-
import { kebabCase } from "scule";
3-
4-
export default <Config>{
5-
generators: {
6-
example: defineGenerator({
7-
name: "example",
8-
async generate({ args, transform }) {
9-
const { generator, ...generatorArgs } = args;
10-
11-
const argsString = Object.entries(generatorArgs)
12-
.map(([k, v]) => {
13-
if (v === true) {
14-
return k;
15-
}
16-
if (v === false) {
17-
return k.startsWith("no-") ? k.slice(3) : `no-${k}`;
18-
}
19-
return `${kebabCase(k)}=${JSON.stringify(v)}`;
20-
})
21-
.join(" ")
22-
.trim();
23-
24-
const input = `<!-- automd:${generator} ${argsString} -->\n<!-- /automd -->`;
25-
const output = (await transform(input)).contents;
26-
return {
27-
contents: `### Input\n\n${_mdCode(input)}\n\n### Output\n\n${_mdCode(output)}`,
28-
};
29-
},
30-
}),
31-
},
32-
};
33-
34-
function _mdCode(md: string) {
35-
return md
36-
.split("\n")
37-
.map((l) => ` ${l}`)
38-
.join("\n");
39-
}
1+
export { default } from "../../.config/automd.ts";

docs/2.generators/file.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ The `file` generator reads a file and inlines it's contents.
44

55
## Example
66

7-
<!-- automd:example generator=file src="../test/fixture/TEST.md" -->
7+
<!-- automd:example generator=file src="test/fixture/TEST.md" -->
88

99
### Input
1010

11-
<!-- automd:file src="../test/fixture/TEST.md" -->
11+
<!-- automd:file src="test/fixture/TEST.md" -->
1212
<!-- /automd -->
1313

1414
### Output
1515

16-
<!-- automd:file src="../test/fixture/TEST.md" -->
16+
<!-- automd:file src="test/fixture/TEST.md" -->
1717

1818
## The Lazy Coder's Guide to Programming
1919

docs/2.generators/jsdocs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Internally it uses [untyped](https://untyped.unjs.io/) and [jiti](https://github
66

77
## Example
88

9-
<!-- automd:example generator=jsdocs src="../test/fixture/src/index" -->
9+
<!-- automd:example generator=jsdocs src="test/fixture/src/index" -->
1010

1111
### Input
1212

13-
<!-- automd:jsdocs src="../test/fixture/src/index" -->
13+
<!-- automd:jsdocs src="test/fixture/src/index" -->
1414
<!-- /automd -->
1515

1616
### Output
1717

18-
<!-- automd:jsdocs src="../test/fixture/src/index" -->
18+
<!-- automd:jsdocs src="test/fixture/src/index" -->
1919

2020
### `add(a, b)`
2121

docs/src/index.ts

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"scripts": {
2424
"automd": "jiti src/cli.ts",
2525
"docs:dev": "cd docs && bun i && bun dev",
26-
"docs:automd": "pnpm automd --dir docs --input '**/*.md' --watch",
2726
"build": "pnpm automd && unbuild",
2827
"dev": "vitest -u",
2928
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src",
@@ -61,7 +60,8 @@
6160
"prettier": "^3.2.5",
6261
"typescript": "^5.3.3",
6362
"unbuild": "^2.0.0",
64-
"vitest": "^1.2.2"
63+
"vitest": "^1.2.2",
64+
"automd": "link:."
6565
},
6666
"packageManager": "pnpm@8.15.1"
67-
}
67+
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)