From 361cd5075889f40e96afa69b365fb28256294eca Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 21 Feb 2024 22:11:01 +0100 Subject: [PATCH] chore: set automd config for repo --- .config/automd.ts | 41 +++++++++++++++++++++++++++++++++++++ README.md | 2 +- docs/.config/automd.ts | 40 +----------------------------------- docs/2.generators/file.md | 6 +++--- docs/2.generators/jsdocs.md | 6 +++--- docs/src/index.ts | 12 ----------- package.json | 6 +++--- pnpm-lock.yaml | 3 +++ 8 files changed, 55 insertions(+), 61 deletions(-) create mode 100644 .config/automd.ts delete mode 100644 docs/src/index.ts diff --git a/.config/automd.ts b/.config/automd.ts new file mode 100644 index 0000000..39bc30a --- /dev/null +++ b/.config/automd.ts @@ -0,0 +1,41 @@ +import { defineGenerator, type Config } from "automd"; +import { kebabCase } from "scule"; + +export default { + 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 = `\n`; + 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"); +} diff --git a/README.md b/README.md index 7294ed2..17161a7 100644 --- a/README.md +++ b/README.md @@ -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)_ diff --git a/docs/.config/automd.ts b/docs/.config/automd.ts index 842b5a8..d5c034a 100644 --- a/docs/.config/automd.ts +++ b/docs/.config/automd.ts @@ -1,39 +1 @@ -import { defineGenerator, type Config } from "automd"; -import { kebabCase } from "scule"; - -export default { - 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 = `\n`; - 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"; diff --git a/docs/2.generators/file.md b/docs/2.generators/file.md index dd95433..f259e97 100644 --- a/docs/2.generators/file.md +++ b/docs/2.generators/file.md @@ -4,16 +4,16 @@ The `file` generator reads a file and inlines it's contents. ## Example - + ### Input - + ### Output - + ## The Lazy Coder's Guide to Programming diff --git a/docs/2.generators/jsdocs.md b/docs/2.generators/jsdocs.md index 0169fb7..fcdef74 100644 --- a/docs/2.generators/jsdocs.md +++ b/docs/2.generators/jsdocs.md @@ -6,16 +6,16 @@ Internally it uses [untyped](https://untyped.unjs.io/) and [jiti](https://github ## Example - + ### Input - + ### Output - + ### `add(a, b)` diff --git a/docs/src/index.ts b/docs/src/index.ts deleted file mode 100644 index 31a1c4d..0000000 --- a/docs/src/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Adds two numbers together. - * - * @example - * - * ```js - * add(1, 2); // 3 - * ``` - */ -export function add(a: number, b: number) { - return a + b; -} diff --git a/package.json b/package.json index c6c2474..477b5ec 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd4d17f..abc6444 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -61,6 +61,9 @@ devDependencies: '@vitest/coverage-v8': specifier: ^1.2.2 version: 1.2.2(vitest@1.2.2) + automd: + specifier: link:. + version: 'link:' changelogen: specifier: ^0.5.5 version: 0.5.5