Skip to content

Commit

Permalink
refactor: switch to mdbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 24, 2024
1 parent 980270e commit 5698d0d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"didyoumean2": "^6.0.1",
"globby": "^14.0.1",
"magic-string": "^0.30.7",
"mdbox": "^0.1.0",
"mlly": "^1.6.1",
"ofetch": "^1.3.3",
"omark": "^0.1.0",
"pathe": "^1.1.2",
"perfect-debounce": "^1.0.0",
"pkg-types": "^1.0.3",
Expand All @@ -65,4 +65,4 @@
"vitest": "^1.3.1"
},
"packageManager": "pnpm@8.15.3"
}
}
20 changes: 13 additions & 7 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/generators/badges.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { image, link } from "omark";
import { image, link } from "mdbox";
import { defineGenerator } from "../generator";
import { getPkg } from "../_utils";

Expand Down
14 changes: 9 additions & 5 deletions src/generators/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFile } from "node:fs/promises";
import { basename, extname } from "pathe";
import { codeBlock } from "omark";
import { md } from "mdbox";
import { defineGenerator } from "../generator";
import { resolvePath } from "../_utils";

Expand All @@ -11,10 +11,14 @@ export const file = defineGenerator({
let contents = await readFile(fullPath, "utf8");

if (args.code) {
contents = codeBlock(contents, args.lang || extname(fullPath).slice(1), {
// prettier-ignore
ext: args.name === false ? undefined : (typeof args.name === 'string' ? args.name : `[${basename(fullPath)}]`),
});
contents = md.codeBlock(
contents,
args.lang || extname(fullPath).slice(1),
{
// prettier-ignore
ext: args.name === false ? undefined : (typeof args.name === 'string' ? args.name : `[${basename(fullPath)}]`),
},
);
}

return {
Expand Down
8 changes: 4 additions & 4 deletions src/generators/jsimport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile } from "node:fs/promises";
import { codeBlock } from "omark";
import { md } from "mdbox";
import { findExportNames, resolvePath } from "mlly";
import { getPkg } from "../_utils";
import { defineGenerator } from "../generator";
Expand Down Expand Up @@ -48,22 +48,22 @@ export const jsimport = defineGenerator({
const code = formatMultiLine(
`import {${fmtImports}} from "${importPath}";`,
);
lines.push("**ESM** (Node.js, Bun)", codeBlock(code, "js"));
lines.push("**ESM** (Node.js, Bun)", md.codeBlock(code, "js"));
}

if (args.cjs) {
const code = formatMultiLine(
`const {${fmtImports}} = require("${importPath}");`,
);
lines.push("**CommonJS** (Legacy Node.js)", codeBlock(code, "js"));
lines.push("**CommonJS** (Legacy Node.js)", md.codeBlock(code, "js"));
}

if (args.cdn) {
const cdnBase = typeof args.cdn === "string" ? args.cdn : DEFAULT_CDN;
const code = formatMultiLine(
`import {${fmtImports}} from "${cdnBase}${importPath}";`,
);
lines.push("**CDN** (Deno, Bun and Browsers)", codeBlock(code, "js"));
lines.push("**CDN** (Deno, Bun and Browsers)", md.codeBlock(code, "js"));
}

return {
Expand Down
10 changes: 5 additions & 5 deletions src/generators/pm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { codeBlock } from "omark";
import { md } from "mdbox";
import { defineGenerator } from "../generator";
import { getPkg } from "../_utils";

Expand Down Expand Up @@ -46,12 +46,12 @@ export const pmInstall = defineGenerator({

if ((args.separate ?? false) === false) {
return {
contents: codeBlock(contents.join("\n\n"), "sh"),
contents: md.codeBlock(contents.join("\n\n"), "sh"),
};
}

return {
contents: contents.map((cmd) => codeBlock(cmd, "sh")).join("\n\n"),
contents: contents.map((cmd) => md.codeBlock(cmd, "sh")).join("\n\n"),
};
},
});
Expand Down Expand Up @@ -80,12 +80,12 @@ export const pmX = defineGenerator({

if ((args.separate ?? false) === false) {
return {
contents: codeBlock(contents.join("\n\n"), "sh"),
contents: md.codeBlock(contents.join("\n\n"), "sh"),
};
}

return {
contents: contents.map((cmd) => codeBlock(cmd, "sh")).join("\n\n"),
contents: contents.map((cmd) => md.codeBlock(cmd, "sh")).join("\n\n"),
};
},
});

0 comments on commit 5698d0d

Please sign in to comment.