import { name, description } from "../package.json"

# {name}

{description}

## Why?

This library is most useful for templating README.md files [like the one you're reading](/src/README.mdx).

# Install

<pre>
  <code className="language-bash">pnpm add {name}</code>
</pre>

<pre>
  <code className="language-bash">npm install {name}</code>
</pre>

## CLI

```bash
mdx-to-md [sourcePath] [outPath]
```

In the simplest use case, you can run the CLI and it will output the converted Markdown relative to the current working directory the script was run in:

```bash
pnpm mdx-to-md README.mdx
```

## Node

Start with MDX:

```mdx
import { name, description } from "./package.json"

# {name}

{description}

# Install

<pre>
  <code className="language-bash">pnpm add {name}</code>
</pre>
```

And convert it to Markdown:

```ts
import { writeFile } from "node:fs/promises"
import { resolve } from "node:path"
import { mdxToMd } from "mdx-to-md"

const mdxPath = resolve(process.cwd(), "README.mdx")
const markdown = await mdxToMd(mdxPath)
const banner = `This README was auto-generated using "pnpm build:readme"`
const readme = `<!--- ${banner} --> \n\n ${markdown}`

await writeFile("README.md", readme)

console.log("📝 Converted README.mdx -> README.md")
```

Which outputs:

```md
# mdx-to-md

Convert MDX to Markdown.

# Install

pnpm add mdx-to-md
```
