Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: did you mean? #25

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"consola": "^3.2.3",
"defu": "^6.1.4",
"destr": "^2.0.2",
"didyoumean2": "^6.0.1",
"magic-string": "^0.30.7",
"omark": "^0.1.0",
"pkg-types": "^1.0.3",
Expand Down
3 changes: 3 additions & 0 deletions playground/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# automd playground

<!-- automd:bagdges -->
<!-- /automd -->

<!-- automd:badges color=yellow name=defu codecov bundlephobia -->

[![npm version](https://flat.badgen.net/npm/v/defu?color=yellow)](https://npmjs.com/package/defu)
Expand Down
32 changes: 32 additions & 0 deletions pnpm-lock.yaml

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

6 changes: 5 additions & 1 deletion src/automd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFile, writeFile } from "node:fs/promises";
import { existsSync } from "node:fs";
import MagicString from "magic-string";
import didYouMean from "didyoumean2";
import builtinGenerators from "./generators";
import { GenerateContext, GenerateResult } from "./generator";
import { findAutoMdBlocks, parseRawArgs } from "./_parse";
Expand Down Expand Up @@ -42,7 +43,10 @@ export async function automd(_config: Config = {}) {
const args = parseRawArgs(block.rawArgs);
const generator = generators[block.generator];
if (!generator) {
consola.warn(`Unknown generator: \`${block.generator}\``);
const suggestions = didYouMean(block.generator, Object.keys(generators));
consola.warn(
`Unknown generator:\`${block.generator}\`.${suggestions ? ` Did you mean "generator:\`${suggestions}\`"?` : ""}`,
);
continue;
}

Expand Down
Loading