@powerlines/plugin-automd 0.1.253 → 0.1.255
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-BrXtsOCC.cjs → _virtual/rolldown_runtime.cjs} +2 -12
- package/dist/{chunk-CS8OKu3y.mjs → _virtual/rolldown_runtime.mjs} +1 -1
- package/dist/index.cjs +7 -9656
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -9646
- package/dist/index.mjs.map +1 -1
- package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.cjs +78 -0
- package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +78 -0
- package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs.map +1 -0
- package/dist/node_modules/.pnpm/acorn@8.15.0/node_modules/acorn/dist/acorn.cjs +5032 -0
- package/dist/node_modules/.pnpm/acorn@8.15.0/node_modules/acorn/dist/acorn.mjs +5032 -0
- package/dist/node_modules/.pnpm/acorn@8.15.0/node_modules/acorn/dist/acorn.mjs.map +1 -0
- package/dist/node_modules/.pnpm/automd@0.4.3_patch_hash_0fe864a2d6fa1461e144747e5f0fbc0a5fb51435ec6b3217ffb18ff2d7058778_magicast@0.5.1/node_modules/automd/dist/index.cjs +650 -0
- package/dist/node_modules/.pnpm/automd@0.4.3_patch_hash_0fe864a2d6fa1461e144747e5f0fbc0a5fb51435ec6b3217ffb18ff2d7058778_magicast@0.5.1/node_modules/automd/dist/index.mjs +648 -0
- package/dist/node_modules/.pnpm/automd@0.4.3_patch_hash_0fe864a2d6fa1461e144747e5f0fbc0a5fb51435ec6b3217ffb18ff2d7058778_magicast@0.5.1/node_modules/automd/dist/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DA7CpUDY.cjs +23 -0
- package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DA7CpUDY.mjs +23 -0
- package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DA7CpUDY.mjs.map +1 -0
- package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DnMsyigM.cjs +405 -0
- package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DnMsyigM.mjs +405 -0
- package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DnMsyigM.mjs.map +1 -0
- package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.cjs +46 -0
- package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs +46 -0
- package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.cjs +204 -0
- package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs +203 -0
- package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.cjs +1013 -0
- package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs +1008 -0
- package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.cjs +128 -0
- package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.mjs +124 -0
- package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.mjs.map +1 -0
- package/dist/{loader-DNEbMIIe.cjs → node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.cjs} +41337 -58245
- package/dist/{loader-BRhKFmUn.mjs → node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.mjs} +41334 -58245
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.mjs.map +1 -0
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.cjs +4387 -0
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.mjs +4385 -0
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.mjs.map +1 -0
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.cjs +26 -0
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.mjs +27 -0
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.mjs.map +1 -0
- package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.cjs +370 -0
- package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.mjs +368 -0
- package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.cjs +939 -0
- package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +940 -0
- package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs.map +1 -0
- package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.cjs +67 -0
- package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.mjs +65 -0
- package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/mlly@1.8.0/node_modules/mlly/dist/index.cjs +1292 -0
- package/dist/node_modules/.pnpm/mlly@1.8.0/node_modules/mlly/dist/index.mjs +1285 -0
- package/dist/node_modules/.pnpm/mlly@1.8.0/node_modules/mlly/dist/index.mjs.map +1 -0
- package/dist/{multipart-parser-C_EjwsED.cjs → node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs} +2 -1
- package/dist/{multipart-parser-Dtmz_axo.mjs → node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs} +3 -2
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs.map +1 -0
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.cjs +20 -0
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.mjs +17 -0
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.mjs.map +1 -0
- package/dist/{node-DapIDpAC.cjs → node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.cjs} +808 -857
- package/dist/{node-FGT1CWpL.mjs → node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.mjs} +794 -806
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.mjs.map +1 -0
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.cjs +16 -0
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs +15 -0
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs.map +1 -0
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.cjs +36 -0
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.mjs +34 -0
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.mjs.map +1 -0
- package/dist/{node-CsMhpAoX.cjs → node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.cjs} +24 -66
- package/dist/{node-D8lz5B3d.mjs → node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs} +20 -59
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs.map +1 -0
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.cjs +139 -0
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +134 -0
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs.map +1 -0
- package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.cjs +77 -0
- package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs +77 -0
- package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs.map +1 -0
- package/dist/{dist-PRh64A_O.mjs → node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.cjs} +4 -2
- package/dist/{dist-DVv98dZY.cjs → node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs} +2 -19
- package/dist/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs.map +1 -0
- package/dist/{dist-Jfd0GR_C.mjs → node_modules/.pnpm/ufo@1.6.3/node_modules/ufo/dist/index.cjs} +4 -46
- package/dist/{dist-8g8frrZv.cjs → node_modules/.pnpm/ufo@1.6.3/node_modules/ufo/dist/index.mjs} +2 -69
- package/dist/node_modules/.pnpm/ufo@1.6.3/node_modules/ufo/dist/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.cjs +12337 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.mjs +12338 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.mjs.map +1 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.cjs +19 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.mjs +19 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.mjs.map +1 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.cjs +71 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.mjs +72 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.mjs.map +1 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.cjs +110 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.mjs +101 -0
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.mjs.map +1 -0
- package/dist/types/index.cjs +0 -3
- package/dist/types/index.d.cts +2 -3
- package/dist/types/index.d.mts +2 -3
- package/dist/types/index.mjs +0 -4
- package/dist/types/plugin.cjs +0 -1
- package/dist/types/plugin.d.cts +52 -3
- package/dist/types/plugin.d.cts.map +1 -0
- package/dist/types/plugin.d.mts +52 -3
- package/dist/types/plugin.d.mts.map +1 -0
- package/dist/types/plugin.mjs +0 -2
- package/dist/types/toc.cjs +0 -1
- package/dist/types/toc.d.cts +35 -2
- package/dist/types/toc.d.cts.map +1 -0
- package/dist/types/toc.d.mts +35 -2
- package/dist/types/toc.d.mts.map +1 -0
- package/dist/types/toc.mjs +0 -2
- package/package.json +4 -4
- package/dist/dist-BavrV299.cjs +0 -682
- package/dist/dist-Jfd0GR_C.mjs.map +0 -1
- package/dist/dist-PRh64A_O.mjs.map +0 -1
- package/dist/dist-PXnBmevt.mjs +0 -681
- package/dist/dist-PXnBmevt.mjs.map +0 -1
- package/dist/index-B8OHl-c_.d.mts +0 -1
- package/dist/index-CmCelmEL.d.cts +0 -1
- package/dist/loader-BRhKFmUn.mjs.map +0 -1
- package/dist/multipart-parser-Dtmz_axo.mjs.map +0 -1
- package/dist/node-D8lz5B3d.mjs.map +0 -1
- package/dist/node-FGT1CWpL.mjs.map +0 -1
- package/dist/plugin-BVD0UMjp.d.cts +0 -52
- package/dist/plugin-BVD0UMjp.d.cts.map +0 -1
- package/dist/plugin-C6jB5e_j.d.mts +0 -52
- package/dist/plugin-C6jB5e_j.d.mts.map +0 -1
- package/dist/plugin-Ckx8qAq8.cjs +0 -0
- package/dist/plugin-jZ9N9Mz-.mjs +0 -1
- package/dist/toc-BN2Ji9Yo.d.mts +0 -35
- package/dist/toc-BN2Ji9Yo.d.mts.map +0 -1
- package/dist/toc-BQgoCyR1.cjs +0 -0
- package/dist/toc-BrayIFG6.d.cts +0 -35
- package/dist/toc-BrayIFG6.d.cts.map +0 -1
- package/dist/toc-CBjybXug.mjs +0 -1
- package/dist/types--fVOUYBq.mjs +0 -1
- package/dist/types-D208vOSb.cjs +0 -0
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
import { basename, extname, join, resolve } from "../../../../pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs";
|
|
2
|
+
import { fileURLToPath, findExportNames, resolvePath } from "../../../../mlly@1.8.0/node_modules/mlly/dist/index.mjs";
|
|
3
|
+
import { MagicString } from "../../../../magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs";
|
|
4
|
+
import { camelCase, titleCase } from "../../../../scule@1.3.0/node_modules/scule/dist/index.mjs";
|
|
5
|
+
import { readPackageJSON } from "../../../../pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs";
|
|
6
|
+
import { image, link, render } from "../../../../mdbox@0.1.1/node_modules/mdbox/dist/index.mjs";
|
|
7
|
+
import { destr } from "../../../../destr@2.0.5/node_modules/destr/dist/index.mjs";
|
|
8
|
+
import { promises } from "node:fs";
|
|
9
|
+
import { readFile, readdir, stat } from "node:fs/promises";
|
|
10
|
+
import { defu as defu$1 } from "defu";
|
|
11
|
+
|
|
12
|
+
//#region ../../node_modules/.pnpm/automd@0.4.3_patch_hash=0fe864a2d6fa1461e144747e5f0fbc0a5fb51435ec6b3217ffb18ff2d7058778_magicast@0.5.1/node_modules/automd/dist/index.mjs
|
|
13
|
+
function defineGenerator(generator) {
|
|
14
|
+
return generator;
|
|
15
|
+
}
|
|
16
|
+
function resolvePath$1(path, { url, dir }) {
|
|
17
|
+
if (path.startsWith("/")) return join(dir, path);
|
|
18
|
+
return url ? fileURLToPath(new URL(path, url)) : resolve(dir, path);
|
|
19
|
+
}
|
|
20
|
+
async function getPkg(dir, input = {}) {
|
|
21
|
+
const pkg = await readPackageJSON(dir).catch(() => void 0);
|
|
22
|
+
return defu$1({
|
|
23
|
+
name: input.name,
|
|
24
|
+
version: typeof input.version === "string" ? input.version : void 0,
|
|
25
|
+
github: input.github || input.gh
|
|
26
|
+
}, {
|
|
27
|
+
name: pkg?.name,
|
|
28
|
+
version: pkg?.version,
|
|
29
|
+
github: _getGitRepo(pkg?.repository)
|
|
30
|
+
}, {
|
|
31
|
+
name: process.env.npm_package_name,
|
|
32
|
+
version: process.env.npm_package_version
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function _getGitRepo(repo) {
|
|
36
|
+
const url = typeof repo === "string" ? repo : repo?.url;
|
|
37
|
+
if (!url || typeof url !== "string") return;
|
|
38
|
+
const match = /(?:https:\/\/github\.com\/|gh:|github:|)([\w-]+)\/([\w-]+)/.exec(url);
|
|
39
|
+
if (match && match[1] && match[2]) return `${match[1]}/${match[2]}`;
|
|
40
|
+
}
|
|
41
|
+
const jsdocs = defineGenerator({
|
|
42
|
+
name: "jsdocs",
|
|
43
|
+
async generate({ config, args, url }) {
|
|
44
|
+
const { loadSchema } = await import("../../../../untyped@2.0.0/node_modules/untyped/dist/loader/loader.mjs");
|
|
45
|
+
return { contents: _render(await loadSchema(resolvePath$1(args.src, {
|
|
46
|
+
url,
|
|
47
|
+
dir: config.dir
|
|
48
|
+
}), { jiti: {
|
|
49
|
+
fsCache: false,
|
|
50
|
+
moduleCache: false
|
|
51
|
+
} }), args, Number.parseInt(args.headingLevel) || 2).join("\n").replace(/\n{3,}/g, "\n\n") };
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
function _render(schema, opts, headingLevel) {
|
|
55
|
+
const sections = Object.create(null);
|
|
56
|
+
for (const [key, keySchema] of Object.entries(schema.properties || {})) {
|
|
57
|
+
const section = _renderSection(key, keySchema, opts, headingLevel + 1);
|
|
58
|
+
if (!section) continue;
|
|
59
|
+
sections[section.group] = sections[section.group] || [];
|
|
60
|
+
sections[section.group].push([section.heading, section.lines]);
|
|
61
|
+
}
|
|
62
|
+
const lines = [];
|
|
63
|
+
const sortedGroups = Object.keys(sections).sort((a, b) => {
|
|
64
|
+
if (a === "") return 1;
|
|
65
|
+
if (b === "") return -1;
|
|
66
|
+
return a.localeCompare(b);
|
|
67
|
+
});
|
|
68
|
+
for (const group of sortedGroups) {
|
|
69
|
+
if (group) lines.push(`\n${"#".repeat(headingLevel)} ${titleCase(group)}\n`);
|
|
70
|
+
const sortedSections = sections[group].sort((a, b) => a[0].localeCompare(b[0]));
|
|
71
|
+
for (const section of sortedSections) {
|
|
72
|
+
const heading = `\n${"#".repeat(headingLevel + 1)} ${section[0]}\n`;
|
|
73
|
+
lines.push(heading, ...section[1]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return lines;
|
|
77
|
+
}
|
|
78
|
+
function _renderSection(key, schema, opts, headingLevel) {
|
|
79
|
+
const tags = _parseTags(schema.tags);
|
|
80
|
+
if (tags.some((t) => t.tag === "@deprecated" || t.tag === "@internal")) return;
|
|
81
|
+
const group = tags.find((t) => t.tag === "@group")?.contents || opts.defaultGroup || "";
|
|
82
|
+
if (opts.group && (typeof opts.group === "string" ? group !== opts.group : !opts.group.includes(group))) return;
|
|
83
|
+
let heading = `\`${key}\``;
|
|
84
|
+
const lines = [];
|
|
85
|
+
if (schema.type === "function") heading = `\`${_generateFunctionSig(key, schema)}\``;
|
|
86
|
+
else if (schema.type !== "object") {
|
|
87
|
+
lines.push(`- **Type**: \`${schema.markdownType || schema.tsType || schema.type}\``);
|
|
88
|
+
if ("default" in schema) lines.push(`- **Default**: \`${JSON.stringify(schema.default)}\``);
|
|
89
|
+
lines.push("");
|
|
90
|
+
}
|
|
91
|
+
lines.push(..._renderBody(schema));
|
|
92
|
+
for (const tag of tags) if (tag.tag === "@example") {
|
|
93
|
+
const codeBlock = tag.contents.startsWith("`") ? tag.contents : `\`\`\`ts\n${tag.contents}\n\`\`\``;
|
|
94
|
+
lines.push("", "**Example:**", "", codeBlock);
|
|
95
|
+
}
|
|
96
|
+
if (schema.type === "object") lines.push(..._render(schema, opts, headingLevel));
|
|
97
|
+
return {
|
|
98
|
+
heading,
|
|
99
|
+
lines,
|
|
100
|
+
group
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function _renderBody(schema) {
|
|
104
|
+
const lines = [];
|
|
105
|
+
if (schema.title) lines.push(schema.title.trim());
|
|
106
|
+
if (schema.title && schema.description) lines.push("");
|
|
107
|
+
if (schema.description) lines.push(...schema.description.split("\n").map((line) => line.trim()).join("\n\n").split("\n"));
|
|
108
|
+
return lines;
|
|
109
|
+
}
|
|
110
|
+
function _parseTags(lines = []) {
|
|
111
|
+
const parsedTags = [];
|
|
112
|
+
let tag = "";
|
|
113
|
+
let contentLines = [];
|
|
114
|
+
for (const line of lines.join("\n").split("\n")) if (line.startsWith("@")) {
|
|
115
|
+
if (tag) parsedTags.push({
|
|
116
|
+
tag,
|
|
117
|
+
contents: contentLines.join("\n")
|
|
118
|
+
});
|
|
119
|
+
const [_tag, ...rest] = line.split(" ");
|
|
120
|
+
tag = _tag;
|
|
121
|
+
contentLines = rest;
|
|
122
|
+
} else contentLines.push(line);
|
|
123
|
+
if (tag) parsedTags.push({
|
|
124
|
+
tag,
|
|
125
|
+
contents: contentLines.join("\n")
|
|
126
|
+
});
|
|
127
|
+
return parsedTags;
|
|
128
|
+
}
|
|
129
|
+
function _generateFunctionSig(name, meta) {
|
|
130
|
+
return `${name}(${(meta.args || []).map((arg) => {
|
|
131
|
+
let str = arg.name;
|
|
132
|
+
if (arg.optional) str += "?";
|
|
133
|
+
const tsType = _simpleArgType(arg.tsType);
|
|
134
|
+
if (tsType) str += `: ${tsType}`;
|
|
135
|
+
return str;
|
|
136
|
+
}).join(", ")})`;
|
|
137
|
+
}
|
|
138
|
+
function _simpleArgType(tsType = "") {
|
|
139
|
+
return tsType.split(/\s*\|\s*/).filter((t) => t && t !== "object" && t.startsWith("{")).map((ot) => ot.split(/\s*[,;]\s*/g).map((p) => p.replaceAll(/\s*:\s*(string|boolean|number)/g, "")).join(", ")).join(" | ");
|
|
140
|
+
}
|
|
141
|
+
const badgeTypes = {
|
|
142
|
+
npmVersion: {
|
|
143
|
+
name: "npm version",
|
|
144
|
+
to: "https://npmjs.com/package/{name}"
|
|
145
|
+
},
|
|
146
|
+
npmDownloads: {
|
|
147
|
+
name: "npm downloads",
|
|
148
|
+
to: "https://npm.chart.dev/{name}"
|
|
149
|
+
},
|
|
150
|
+
bundlephobia: {
|
|
151
|
+
name: "bundle size",
|
|
152
|
+
to: "https://bundlephobia.com/package/{name}"
|
|
153
|
+
},
|
|
154
|
+
bundlejs: {
|
|
155
|
+
name: "bundle size",
|
|
156
|
+
to: "https://bundlejs.com/?q={name}"
|
|
157
|
+
},
|
|
158
|
+
packagephobia: {
|
|
159
|
+
name: "install size",
|
|
160
|
+
to: "https://packagephobia.com/result?p={name}"
|
|
161
|
+
},
|
|
162
|
+
codecov: {
|
|
163
|
+
name: "codecov",
|
|
164
|
+
to: "https://codecov.io/gh/{github}"
|
|
165
|
+
},
|
|
166
|
+
license: {
|
|
167
|
+
name: "license",
|
|
168
|
+
to: "https://github.com/{github}/blob/{licenseBranch}/LICENSE"
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const badgeProviders = {
|
|
172
|
+
shields: {
|
|
173
|
+
npmVersion: "https://img.shields.io/npm/v/{name}",
|
|
174
|
+
npmDownloads: "https://img.shields.io/npm/dm/{name}",
|
|
175
|
+
bundlephobia: "https://img.shields.io/bundlephobia/minzip/{name}",
|
|
176
|
+
packagephobia: "https://badgen.net/packagephobia/install/{name}",
|
|
177
|
+
bundlejs: "https://img.shields.io/bundlejs/size/{name}",
|
|
178
|
+
codecov: "https://img.shields.io/codecov/c/gh/{github}",
|
|
179
|
+
license: "https://img.shields.io/github/license/{github}"
|
|
180
|
+
},
|
|
181
|
+
badgen: {
|
|
182
|
+
npmVersion: "https://flat.badgen.net/npm/v/{name}",
|
|
183
|
+
npmDownloads: "https://flat.badgen.net/npm/dm/{name}",
|
|
184
|
+
bundlephobia: "https://flat.badgen.net/bundlephobia/minzip/{name}",
|
|
185
|
+
bundlejs: false,
|
|
186
|
+
packagephobia: "https://flat.badgen.net/packagephobia/install/{name}",
|
|
187
|
+
codecov: "https://flat.badgen.net/codecov/c/github/{github}",
|
|
188
|
+
license: "https://flat.badgen.net/github/license/{github}"
|
|
189
|
+
},
|
|
190
|
+
badgenClassic: {
|
|
191
|
+
npmVersion: "https://badgen.net/npm/v/{name}",
|
|
192
|
+
npmDownloads: "https://badgen.net/npm/dm/{name}",
|
|
193
|
+
bundlephobia: "https://badgen.net/bundlephobia/minzip/{name}",
|
|
194
|
+
bundlejs: false,
|
|
195
|
+
packagephobia: "https://badgen.net/packagephobia/install/{name}",
|
|
196
|
+
codecov: "https://badgen.net/codecov/c/github/{github}",
|
|
197
|
+
license: "https://badgen.net/github/license/{github}"
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const badges = defineGenerator({
|
|
201
|
+
name: "badges",
|
|
202
|
+
async generate({ config, args }) {
|
|
203
|
+
const pkg = await getPkg(config.dir, args);
|
|
204
|
+
const ctx = {
|
|
205
|
+
name: pkg.name,
|
|
206
|
+
github: pkg.github,
|
|
207
|
+
licenseBranch: "main",
|
|
208
|
+
...args
|
|
209
|
+
};
|
|
210
|
+
const fillStr = (str) => str.replace(/{(\w+)}/g, (_, key) => ctx[key] || "");
|
|
211
|
+
const provider = badgeProviders[args.provider] || badgeProviders.shields;
|
|
212
|
+
const providerParams = Object.entries({
|
|
213
|
+
color: args.color,
|
|
214
|
+
labelColor: args.labelColor,
|
|
215
|
+
...args.styleParams
|
|
216
|
+
}).filter(([, value]) => value).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
|
|
217
|
+
const badges$1 = {
|
|
218
|
+
npmVersion: {
|
|
219
|
+
enabled: ctx.name && args.npmVersion !== false,
|
|
220
|
+
...badgeTypes.npmVersion
|
|
221
|
+
},
|
|
222
|
+
npmDownloads: {
|
|
223
|
+
enabled: ctx.name && args.npmDownloads !== false,
|
|
224
|
+
...badgeTypes.npmDownloads
|
|
225
|
+
},
|
|
226
|
+
bundlephobia: {
|
|
227
|
+
enabled: args.bundlephobia && ctx.name,
|
|
228
|
+
...badgeTypes.bundlephobia
|
|
229
|
+
},
|
|
230
|
+
bundlejs: {
|
|
231
|
+
enabled: args.bundlejs && ctx.name,
|
|
232
|
+
...badgeTypes.bundlejs
|
|
233
|
+
},
|
|
234
|
+
packagephobia: {
|
|
235
|
+
enabled: args.packagephobia && ctx.name,
|
|
236
|
+
...badgeTypes.packagephobia
|
|
237
|
+
},
|
|
238
|
+
codecov: {
|
|
239
|
+
enabled: args.codecov && ctx.github,
|
|
240
|
+
...badgeTypes.codecov
|
|
241
|
+
},
|
|
242
|
+
license: {
|
|
243
|
+
enabled: args.license && ctx.github,
|
|
244
|
+
...badgeTypes.license
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const md = [];
|
|
248
|
+
for (const [badgeType, badge] of Object.entries(badges$1)) {
|
|
249
|
+
if (!badge.enabled || !provider[badgeType]) continue;
|
|
250
|
+
const to = fillStr(badge.to);
|
|
251
|
+
const imgURL = fillStr(provider[badgeType]) + (providerParams ? `?${providerParams}` : "");
|
|
252
|
+
md.push(link(to, image(imgURL, badge.name)));
|
|
253
|
+
}
|
|
254
|
+
return { contents: md.join("\n") };
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
const INSTALL_COMMANDS = [
|
|
258
|
+
["npm", "install"],
|
|
259
|
+
["yarn", "add"],
|
|
260
|
+
["pnpm", "add"],
|
|
261
|
+
["bun", "install"],
|
|
262
|
+
[
|
|
263
|
+
"deno",
|
|
264
|
+
"install",
|
|
265
|
+
" --dev",
|
|
266
|
+
"npm:"
|
|
267
|
+
]
|
|
268
|
+
];
|
|
269
|
+
const NYPM_COMMAND = ["npx nypm", "install"];
|
|
270
|
+
const RUN_COMMANDS = [
|
|
271
|
+
["npm", "npx "],
|
|
272
|
+
["pnpm", "pnpm dlx "],
|
|
273
|
+
["bun", "bunx "],
|
|
274
|
+
["deno", "deno run -A npm:"]
|
|
275
|
+
];
|
|
276
|
+
const pmInstall = defineGenerator({
|
|
277
|
+
name: "pm-install",
|
|
278
|
+
async generate({ config, args }) {
|
|
279
|
+
const { name, version } = await getPkg(config.dir, args);
|
|
280
|
+
if (!name) return { contents: "<!-- package name is unspecified -->" };
|
|
281
|
+
let versionSuffix = "";
|
|
282
|
+
if (args.version) versionSuffix = typeof args.version === "string" ? `@${args.version}` : `@^${version}`;
|
|
283
|
+
const contents = (args.auto === false ? INSTALL_COMMANDS : [NYPM_COMMAND, ...INSTALL_COMMANDS]).map(([cmd, install, dev = " -D", pkgPrefix = ""]) => `# ${cmd.includes("nypm") ? "✨ Auto-detect" : cmd}\n${cmd} ${install}${args.dev ? dev : args.global ? "g" : ""} ${pkgPrefix}${name}${versionSuffix}`);
|
|
284
|
+
if ((args.separate ?? false) === false) return { contents: render.codeBlock(contents.join("\n\n"), "sh") };
|
|
285
|
+
return { contents: contents.map((cmd) => render.codeBlock(cmd, "sh")).join("\n\n") };
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
const pmX = defineGenerator({
|
|
289
|
+
name: "pm-x",
|
|
290
|
+
async generate({ config, args }) {
|
|
291
|
+
const { name, version } = await getPkg(config.dir, args);
|
|
292
|
+
if (!name) return { contents: "<!-- package name is unspecified -->" };
|
|
293
|
+
let versionSuffix = "";
|
|
294
|
+
if (args.version) versionSuffix = typeof args.version === "string" ? `@${args.version}` : `@${version}`;
|
|
295
|
+
const contents = RUN_COMMANDS.map(([pm, cmd]) => `# ${pm}\n${cmd}${name}${versionSuffix}${args.args ? ` ${args.args}` : ""}`);
|
|
296
|
+
if ((args.separate ?? false) === false) return { contents: render.codeBlock(contents.join("\n\n"), "sh") };
|
|
297
|
+
return { contents: contents.map((cmd) => render.codeBlock(cmd, "sh")).join("\n\n") };
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
const fetch = defineGenerator({
|
|
301
|
+
name: "fetch",
|
|
302
|
+
async generate({ args }) {
|
|
303
|
+
const { $fetch } = await import("../../../../ofetch@1.5.1/node_modules/ofetch/dist/node.mjs");
|
|
304
|
+
let url = args.url;
|
|
305
|
+
if (!url) throw new Error("URL is required!");
|
|
306
|
+
if (url.startsWith("gh:")) url = `https://raw.githubusercontent.com/${url.slice(3)}`;
|
|
307
|
+
return { contents: await $fetch(url) };
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
const DEFAULT_CDN = "https://esm.sh/";
|
|
311
|
+
const jsimport = defineGenerator({
|
|
312
|
+
name: "jsimport",
|
|
313
|
+
async generate({ config, args }) {
|
|
314
|
+
const { name } = await getPkg(config.dir, args);
|
|
315
|
+
const importPath = name + (args.path || "");
|
|
316
|
+
const importNames = [].concat(args.import, args.imports).filter(Boolean).flatMap((i) => i.split(/\s*,\s*/));
|
|
317
|
+
if (args.src) {
|
|
318
|
+
const exportNames = findExportNames(await readFile(await resolvePath(args.src, { url: config.dir }), "utf8"));
|
|
319
|
+
if (exportNames && exportNames.length > 0) importNames.push(...exportNames);
|
|
320
|
+
}
|
|
321
|
+
const lines = [];
|
|
322
|
+
const fmtImports = importNames.length > 1 ? `\n${importNames.map((i) => " " + i + ",").join("\n")}\n` : importNames[0] && ` ${importNames[0]} ` || "";
|
|
323
|
+
const formatMultiLine = (str) => {
|
|
324
|
+
return str.length > (args.printWidth || 80) ? str : str.replace(/\n/g, "").replace(/,\s*}/, "}").replace(/(\w)}/, "$1 }").replace(/\s+/g, " ");
|
|
325
|
+
};
|
|
326
|
+
if (args.esm !== false) {
|
|
327
|
+
const code = formatMultiLine(`import {${fmtImports}} from "${importPath}";`);
|
|
328
|
+
lines.push("**ESM** (Node.js, Bun, Deno)", render.codeBlock(code, "js"));
|
|
329
|
+
}
|
|
330
|
+
if (args.cjs) {
|
|
331
|
+
const code = formatMultiLine(`const {${fmtImports}} = require("${importPath}");`);
|
|
332
|
+
lines.push("**CommonJS** (Legacy Node.js)", render.codeBlock(code, "js"));
|
|
333
|
+
}
|
|
334
|
+
if (args.cdn) {
|
|
335
|
+
const code = formatMultiLine(`import {${fmtImports}} from "${typeof args.cdn === "string" ? args.cdn : DEFAULT_CDN}${importPath}";`);
|
|
336
|
+
lines.push("**CDN** (Deno and Browsers)", render.codeBlock(code, "js"));
|
|
337
|
+
}
|
|
338
|
+
return { contents: lines.join("\n\n") };
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
const withAutomd = defineGenerator({
|
|
342
|
+
name: "with-automd",
|
|
343
|
+
generate({ args }) {
|
|
344
|
+
const lastUpdate = args.lastUpdate ? ` (last updated: ${typeof args.lastUpdate === "string" ? args.lastUpdate : (/* @__PURE__ */ new Date()).toDateString()})` : "";
|
|
345
|
+
const emoji = args.emoji === false ? "" : "🤖 ";
|
|
346
|
+
const lines = [];
|
|
347
|
+
if (args.separator !== false) lines.push("---", "");
|
|
348
|
+
lines.push(`_${emoji}auto updated with [automd](https://automd.unjs.io)${lastUpdate}_`);
|
|
349
|
+
return { contents: lines.join("\n") };
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
const file = defineGenerator({
|
|
353
|
+
name: "file",
|
|
354
|
+
async generate({ args, config, url }) {
|
|
355
|
+
const fullPath = resolvePath$1(args.src, {
|
|
356
|
+
url,
|
|
357
|
+
dir: config.dir
|
|
358
|
+
});
|
|
359
|
+
let contents = await readFile(fullPath, "utf8");
|
|
360
|
+
if (!args.noTrim) contents = contents.trim();
|
|
361
|
+
if (args.lines) {
|
|
362
|
+
const groups = /^(?<startLine>\d+)?:(?<endLine>\d+)?$/.exec(args.lines)?.groups;
|
|
363
|
+
if (!groups) throw new Error("invalid lines format");
|
|
364
|
+
const lines = contents.split("\n");
|
|
365
|
+
const startLine = Number(groups.startLine) || 1;
|
|
366
|
+
const endLine = Number(groups.endLine) || lines.length;
|
|
367
|
+
if (startLine < 1) throw new Error("first line's index can not be smaller than 1");
|
|
368
|
+
contents = lines.slice(startLine - 1, endLine).join("\n");
|
|
369
|
+
}
|
|
370
|
+
if (args.code) contents = render.codeBlock(contents, args.lang || extname(fullPath).slice(1), { ext: args.name === false ? void 0 : typeof args.name === "string" ? args.name : `[${basename(fullPath)}]` });
|
|
371
|
+
return { contents };
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
const PROVIDERS = {
|
|
375
|
+
CONTRIB_ROCKS: "contrib.rocks",
|
|
376
|
+
MARKUPGO: "markupgo"
|
|
377
|
+
};
|
|
378
|
+
const contributors = defineGenerator({
|
|
379
|
+
name: "contributors",
|
|
380
|
+
async generate({ config, args }) {
|
|
381
|
+
const { github } = await getPkg(config.dir, args);
|
|
382
|
+
const provider = args.provider || PROVIDERS.CONTRIB_ROCKS;
|
|
383
|
+
if (!github) throw new Error("`github` is required!");
|
|
384
|
+
const lines = [];
|
|
385
|
+
if (typeof args.license === "string") lines.push(`Published under the [${args.license.toUpperCase()}](https://github.com/${github}/blob/main/LICENSE) license.`);
|
|
386
|
+
let madeBy = `[community](https://github.com/${github}/graphs/contributors) 💛`;
|
|
387
|
+
if (typeof args.author === "string") {
|
|
388
|
+
const authors = args.author.split(",").map((author) => author.trim()).map((user) => `[@${user}](https://github.com/${user})`).join(", ");
|
|
389
|
+
if (authors.length > 0) madeBy = `${authors} and ${madeBy}`;
|
|
390
|
+
}
|
|
391
|
+
lines.push(`Made by ${madeBy}`);
|
|
392
|
+
if (provider === PROVIDERS.MARKUPGO) {
|
|
393
|
+
const params = [];
|
|
394
|
+
args = {
|
|
395
|
+
circleSize: "64",
|
|
396
|
+
center: "true",
|
|
397
|
+
...args
|
|
398
|
+
};
|
|
399
|
+
if (Number(args.max) >= 0) params.push(["count", args.max]);
|
|
400
|
+
if (Number(args.width)) params.push(["width", args.width]);
|
|
401
|
+
if (Number(args.circleSize)) params.push(["circleSize", args.circleSize]);
|
|
402
|
+
if (Number(args.circleRadius)) params.push(["circleRadius", args.circleRadius]);
|
|
403
|
+
if (Number(args.circleSpacing)) params.push(["circleSpacing", args.circleSpacing]);
|
|
404
|
+
if (args.center) params.push(["center", Boolean(args.center).toString()]);
|
|
405
|
+
if (!args.markupGoLogo) params.push(["removeLogo", "true"]);
|
|
406
|
+
if (args.anon) params.push(["anon", Boolean(args.anon).toString()]);
|
|
407
|
+
let paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&");
|
|
408
|
+
paramsStr = paramsStr ? `?${paramsStr}` : "";
|
|
409
|
+
lines.push(`<br><br>`, `<a href="https://github.com/${github}/graphs/contributors">`, `<img src="https://markupgo.com/github/${github}/contributors${paramsStr}" />`, `</a>`);
|
|
410
|
+
} else {
|
|
411
|
+
const params = [["repo", github]];
|
|
412
|
+
if (args.max) params.push(["max", args.max]);
|
|
413
|
+
if (args.anon) params.push(["anon", args.anon]);
|
|
414
|
+
const paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&");
|
|
415
|
+
lines.push(`<br><br>`, `<a href="https://github.com/${github}/graphs/contributors">`, `<img src="https://contrib.rocks/image?${paramsStr}" />`, `</a>`);
|
|
416
|
+
}
|
|
417
|
+
return { contents: lines.join("\n") };
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
const DEFAULT_IGNORE = [
|
|
421
|
+
"node_modules",
|
|
422
|
+
".git",
|
|
423
|
+
".DS_Store",
|
|
424
|
+
".nuxt",
|
|
425
|
+
".output",
|
|
426
|
+
".nitro",
|
|
427
|
+
"dist",
|
|
428
|
+
"coverage",
|
|
429
|
+
".cache",
|
|
430
|
+
".turbo"
|
|
431
|
+
];
|
|
432
|
+
async function parseGitignore(dir) {
|
|
433
|
+
try {
|
|
434
|
+
return (await readFile(join(dir, ".gitignore"), "utf8")).split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
435
|
+
} catch {
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function shouldIgnore(name, ignorePatterns, defaultIgnore) {
|
|
440
|
+
const allPatterns = [...defaultIgnore, ...ignorePatterns];
|
|
441
|
+
for (const pattern of allPatterns) {
|
|
442
|
+
if (name === pattern.replace(/^\//, "").replace(/\/$/, "")) return true;
|
|
443
|
+
if (pattern.startsWith("*") && name.endsWith(pattern.slice(1))) return true;
|
|
444
|
+
if (pattern.endsWith("*") && name.startsWith(pattern.slice(0, -1))) return true;
|
|
445
|
+
}
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
async function buildTree(dir, ignorePatterns, maxDepth, currentDepth = 0) {
|
|
449
|
+
if (maxDepth > 0 && currentDepth >= maxDepth) return [];
|
|
450
|
+
const entries = await readdir(dir);
|
|
451
|
+
const result = [];
|
|
452
|
+
for (const entry of entries) {
|
|
453
|
+
if (shouldIgnore(entry, ignorePatterns, DEFAULT_IGNORE)) continue;
|
|
454
|
+
const fullPath = join(dir, entry);
|
|
455
|
+
const isDirectory = (await stat(fullPath)).isDirectory();
|
|
456
|
+
const treeEntry = {
|
|
457
|
+
name: entry,
|
|
458
|
+
isDirectory
|
|
459
|
+
};
|
|
460
|
+
if (isDirectory) treeEntry.children = await buildTree(fullPath, ignorePatterns, maxDepth, currentDepth + 1);
|
|
461
|
+
result.push(treeEntry);
|
|
462
|
+
}
|
|
463
|
+
result.sort((a, b) => {
|
|
464
|
+
if (a.isDirectory !== b.isDirectory) return a.isDirectory ? -1 : 1;
|
|
465
|
+
return a.name.localeCompare(b.name);
|
|
466
|
+
});
|
|
467
|
+
return result;
|
|
468
|
+
}
|
|
469
|
+
function renderTree(entries, isLast = []) {
|
|
470
|
+
const lines = [];
|
|
471
|
+
for (let i = 0; i < entries.length; i++) {
|
|
472
|
+
const entry = entries[i];
|
|
473
|
+
const isLastEntry = i === entries.length - 1;
|
|
474
|
+
let linePrefix = "";
|
|
475
|
+
for (const element_ of isLast) linePrefix += element_ ? " " : "│ ";
|
|
476
|
+
const connector = isLastEntry ? "└── " : "├── ";
|
|
477
|
+
const suffix = entry.isDirectory ? "/" : "";
|
|
478
|
+
lines.push(`${linePrefix}${connector}${entry.name}${suffix}`);
|
|
479
|
+
if (entry.children && entry.children.length > 0) {
|
|
480
|
+
const childLines = renderTree(entry.children, [...isLast, isLastEntry]);
|
|
481
|
+
lines.push(...childLines);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return lines;
|
|
485
|
+
}
|
|
486
|
+
const dirTree = defineGenerator({
|
|
487
|
+
name: "dir-tree",
|
|
488
|
+
async generate({ args, config, url }) {
|
|
489
|
+
const srcPath = args.src || ".";
|
|
490
|
+
const fullPath = resolvePath$1(srcPath, {
|
|
491
|
+
url,
|
|
492
|
+
dir: config.dir
|
|
493
|
+
});
|
|
494
|
+
if (!(await stat(fullPath)).isDirectory()) throw new Error(`Path "${srcPath}" is not a directory`);
|
|
495
|
+
const userIgnore = args.ignore ? String(args.ignore).split(",").map((s) => s.trim()) : [];
|
|
496
|
+
return { contents: "```\n" + renderTree(await buildTree(fullPath, [...await parseGitignore(fullPath), ...userIgnore], args.maxDepth ? Number(args.maxDepth) : 0)).join("\n") + "\n```" };
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
var generators_default = {
|
|
500
|
+
jsdocs,
|
|
501
|
+
badges,
|
|
502
|
+
"pm-i": pmInstall,
|
|
503
|
+
"pm-install": pmInstall,
|
|
504
|
+
"pm-x": pmX,
|
|
505
|
+
fetch,
|
|
506
|
+
file,
|
|
507
|
+
jsimport,
|
|
508
|
+
"with-automd": withAutomd,
|
|
509
|
+
contributors,
|
|
510
|
+
"dir-tree": dirTree
|
|
511
|
+
};
|
|
512
|
+
function findBlocks(md) {
|
|
513
|
+
const blocks = [];
|
|
514
|
+
for (const match of md.matchAll(/^(?<open><!--\s*automd:(?<generator>.+?)\s+(?<args>.*?)\s*-->)(?<contents>.+?)(?<close>^<!--\s*\/automd\s*-->)/gimsu)) {
|
|
515
|
+
if (match.index === void 0 || !match.groups) continue;
|
|
516
|
+
const start = match.index + match.groups.open.length || 0;
|
|
517
|
+
const end = start + match.groups.contents.length;
|
|
518
|
+
blocks.push({
|
|
519
|
+
generator: match.groups.generator,
|
|
520
|
+
rawArgs: match.groups.args,
|
|
521
|
+
contents: match.groups.contents,
|
|
522
|
+
loc: {
|
|
523
|
+
start,
|
|
524
|
+
end
|
|
525
|
+
},
|
|
526
|
+
_loc: {
|
|
527
|
+
start: match.index,
|
|
528
|
+
end: match.index + match[0].length
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
return blocks;
|
|
533
|
+
}
|
|
534
|
+
function containsAutomd(md) {
|
|
535
|
+
return /^<!--\s*automd:/gimsu.test(md);
|
|
536
|
+
}
|
|
537
|
+
function parseRawArgs(rawArgs) {
|
|
538
|
+
const args = Object.create(null);
|
|
539
|
+
for (const part of rawArgs.split(/\s+/)) {
|
|
540
|
+
const [_key, value] = part.split("=");
|
|
541
|
+
const key = _key && camelCase(_key);
|
|
542
|
+
if (key && value) args[key] = destr(value);
|
|
543
|
+
else if (part.startsWith("no-")) args[part.slice(3)] = false;
|
|
544
|
+
else args[part] = true;
|
|
545
|
+
}
|
|
546
|
+
return args;
|
|
547
|
+
}
|
|
548
|
+
const RESOLVED_CONFIG_SYMBOL = Symbol("automdConfig");
|
|
549
|
+
function resolveConfig(config) {
|
|
550
|
+
if (config && RESOLVED_CONFIG_SYMBOL in config) return config;
|
|
551
|
+
const _config = {
|
|
552
|
+
dir: ".",
|
|
553
|
+
input: "README.md",
|
|
554
|
+
generators: {},
|
|
555
|
+
[RESOLVED_CONFIG_SYMBOL]: true,
|
|
556
|
+
...config
|
|
557
|
+
};
|
|
558
|
+
_config.dir = resolve(_config.dir);
|
|
559
|
+
_config.input = (Array.isArray(_config.input) ? _config.input : [_config.input]).filter(Boolean);
|
|
560
|
+
return _config;
|
|
561
|
+
}
|
|
562
|
+
async function loadConfig(dir = ".", overrides) {
|
|
563
|
+
const { loadConfig: loadConfig$1 } = await import("c12");
|
|
564
|
+
dir = resolve(dir);
|
|
565
|
+
const { config } = await loadConfig$1({
|
|
566
|
+
cwd: dir,
|
|
567
|
+
name: "automd",
|
|
568
|
+
dotenv: true,
|
|
569
|
+
overrides,
|
|
570
|
+
defaults: {
|
|
571
|
+
ignore: [
|
|
572
|
+
"**/node_modules",
|
|
573
|
+
"**/dist",
|
|
574
|
+
"**/.*"
|
|
575
|
+
],
|
|
576
|
+
dir
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
return resolveConfig(config);
|
|
580
|
+
}
|
|
581
|
+
async function transform(contents, _config, url) {
|
|
582
|
+
const start = performance.now();
|
|
583
|
+
const config = resolveConfig(_config);
|
|
584
|
+
const editor = new MagicString(contents);
|
|
585
|
+
const updates = [];
|
|
586
|
+
const generators = {
|
|
587
|
+
...generators_default,
|
|
588
|
+
...config.generators
|
|
589
|
+
};
|
|
590
|
+
const blocks = findBlocks(contents);
|
|
591
|
+
for (const block of blocks) {
|
|
592
|
+
const result = await _transformBlock(block, config, generators, url);
|
|
593
|
+
if (result.unwrap) editor.overwrite(block._loc.start, block._loc.end, `${result.contents.trim()}`);
|
|
594
|
+
else editor.overwrite(block.loc.start, block.loc.end, `\n\n${result.contents.trim()}\n\n`);
|
|
595
|
+
updates.push({
|
|
596
|
+
block,
|
|
597
|
+
result
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
const hasChanged = editor.hasChanged();
|
|
601
|
+
const hasIssues = updates.some((u) => u.result.issues?.filter(Boolean).length);
|
|
602
|
+
const time = performance.now() - start;
|
|
603
|
+
return {
|
|
604
|
+
hasChanged,
|
|
605
|
+
hasIssues,
|
|
606
|
+
contents: hasChanged ? editor.toString() : contents,
|
|
607
|
+
updates,
|
|
608
|
+
time
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
async function _transformBlock(block, config, generators, url) {
|
|
612
|
+
const args = parseRawArgs(block.rawArgs);
|
|
613
|
+
const generator = generators[block.generator];
|
|
614
|
+
if (!generator) {
|
|
615
|
+
const suggestions = (await import("../../../../didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs").then((r) => r.default || r))(block.generator, Object.keys(generators));
|
|
616
|
+
const error = `Unknown generator:\`${block.generator}\`.${suggestions ? ` Did you mean "generator:\`${suggestions}\`"?` : ""}`;
|
|
617
|
+
return {
|
|
618
|
+
contents: `<!-- ⚠️ ${error} -->`,
|
|
619
|
+
issues: [error]
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
const context = {
|
|
623
|
+
args,
|
|
624
|
+
config,
|
|
625
|
+
block,
|
|
626
|
+
transform: (contents) => transform(contents, config, url),
|
|
627
|
+
url
|
|
628
|
+
};
|
|
629
|
+
try {
|
|
630
|
+
const result = await generator.generate(context);
|
|
631
|
+
if (!result.unwrap && containsAutomd(result.contents)) result.unwrap = true;
|
|
632
|
+
if (result.unwrap) {
|
|
633
|
+
const nestedRes = await context.transform(result.contents);
|
|
634
|
+
result.contents = nestedRes.contents;
|
|
635
|
+
if (nestedRes.hasIssues) result.issues = [...result.issues || [], ...nestedRes.updates.flatMap((u) => u.result.issues || [])].filter(Boolean);
|
|
636
|
+
}
|
|
637
|
+
return result;
|
|
638
|
+
} catch (error) {
|
|
639
|
+
return {
|
|
640
|
+
contents: `<!-- ⚠️ (${block.generator}) ${error.message || error} -->`,
|
|
641
|
+
issues: [error]
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
//#endregion
|
|
647
|
+
export { loadConfig, resolveConfig, transform };
|
|
648
|
+
//# sourceMappingURL=index.mjs.map
|