Skip to content

Commit

Permalink
chore: set automd config for repo
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 21, 2024
1 parent ea0667a commit 361cd50
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 61 deletions.
41 changes: 41 additions & 0 deletions .config/automd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defineGenerator, type Config } from "automd";
import { kebabCase } from "scule";

export default <Config>{
input: ["README.md", "docs/**/*.md"],
ignore: ["test/fixture/**"],
generators: {
example: defineGenerator({
name: "example",
async generate({ args, transform }) {
const { generator, ...generatorArgs } = args;

const argsString = Object.entries(generatorArgs)
.map(([k, v]) => {
if (v === true) {
return k;
}
if (v === false) {
return k.startsWith("no-") ? k.slice(3) : `no-${k}`;
}
return `${kebabCase(k)}=${JSON.stringify(v)}`;
})
.join(" ")
.trim();

const input = `<!-- automd:${generator} ${argsString} -->\n<!-- /automd -->`;
const output = (await transform(input)).contents;
return {
contents: `### Input\n\n${_mdCode(input)}\n\n### Output\n\n${_mdCode(output)}`,
};
},
}),
},
};

function _mdCode(md: string) {
return md
.split("\n")
.map((l) => ` ${l}`)
.join("\n");
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/a

---

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

<!-- /automd -->
40 changes: 1 addition & 39 deletions docs/.config/automd.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
import { defineGenerator, type Config } from "automd";
import { kebabCase } from "scule";

export default <Config>{
generators: {
example: defineGenerator({
name: "example",
async generate({ args, transform }) {
const { generator, ...generatorArgs } = args;

const argsString = Object.entries(generatorArgs)
.map(([k, v]) => {
if (v === true) {
return k;
}
if (v === false) {
return k.startsWith("no-") ? k.slice(3) : `no-${k}`;
}
return `${kebabCase(k)}=${JSON.stringify(v)}`;
})
.join(" ")
.trim();

const input = `<!-- automd:${generator} ${argsString} -->\n<!-- /automd -->`;
const output = (await transform(input)).contents;
return {
contents: `### Input\n\n${_mdCode(input)}\n\n### Output\n\n${_mdCode(output)}`,
};
},
}),
},
};

function _mdCode(md: string) {
return md
.split("\n")
.map((l) => ` ${l}`)
.join("\n");
}
export { default } from "../../.config/automd.ts";
6 changes: 3 additions & 3 deletions docs/2.generators/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ The `file` generator reads a file and inlines it's contents.

## Example

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

### Input

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

### Output

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

## The Lazy Coder's Guide to Programming

Expand Down
6 changes: 3 additions & 3 deletions docs/2.generators/jsdocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Internally it uses [untyped](https://untyped.unjs.io/) and [jiti](https://github

## Example

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

### Input

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

### Output

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

### `add(a, b)`

Expand Down
12 changes: 0 additions & 12 deletions docs/src/index.ts

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"scripts": {
"automd": "jiti src/cli.ts",
"docs:dev": "cd docs && bun i && bun dev",
"docs:automd": "pnpm automd --dir docs --input '**/*.md' --watch",
"build": "pnpm automd && unbuild",
"dev": "vitest -u",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src",
Expand Down Expand Up @@ -61,7 +60,8 @@
"prettier": "^3.2.5",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vitest": "^1.2.2"
"vitest": "^1.2.2",
"automd": "link:."
},
"packageManager": "pnpm@8.15.1"
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 361cd50

Please sign in to comment.