@powerlines/plugin-automd 0.1.340 → 0.1.342
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/README.md +14 -16
- package/dist/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.cjs} +1 -3
- package/dist/_virtual/_rolldown/runtime.mjs +3 -0
- package/dist/index.cjs +26 -27
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -6
- package/dist/index.mjs.map +1 -1
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts +1 -1
- package/dist/types/plugin.d.mts.map +1 -1
- package/dist/types/toc.d.cts.map +1 -1
- package/dist/types/toc.d.mts.map +1 -1
- package/package.json +20 -18
- package/dist/_virtual/rolldown_runtime.mjs +0 -32
- package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.cjs +0 -78
- package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -78
- package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs.map +0 -1
- package/dist/node_modules/.pnpm/acorn@8.16.0/node_modules/acorn/dist/acorn.cjs +0 -5089
- package/dist/node_modules/.pnpm/acorn@8.16.0/node_modules/acorn/dist/acorn.mjs +0 -5089
- package/dist/node_modules/.pnpm/acorn@8.16.0/node_modules/acorn/dist/acorn.mjs.map +0 -1
- package/dist/node_modules/.pnpm/automd@0.4.3_patch_hash_5b5d5334735dce5e1ae79d8924a5aa49e4139453056613d618786b961793a42b_magicast@0.5.2/node_modules/automd/dist/index.cjs +0 -654
- package/dist/node_modules/.pnpm/automd@0.4.3_patch_hash_5b5d5334735dce5e1ae79d8924a5aa49e4139453056613d618786b961793a42b_magicast@0.5.2/node_modules/automd/dist/index.mjs +0 -652
- package/dist/node_modules/.pnpm/automd@0.4.3_patch_hash_5b5d5334735dce5e1ae79d8924a5aa49e4139453056613d618786b961793a42b_magicast@0.5.2/node_modules/automd/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/_format.cjs +0 -23
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/_format.mjs +0 -23
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/_format.mjs.map +0 -1
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/json.cjs +0 -10
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/json.mjs +0 -11
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/json.mjs.map +0 -1
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/libs/jsonc-parser.cjs +0 -388
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/libs/jsonc-parser.mjs +0 -388
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/libs/jsonc-parser.mjs.map +0 -1
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/jsonc.cjs +0 -11
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/jsonc.mjs +0 -12
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/jsonc.mjs.map +0 -1
- package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.cjs +0 -46
- package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs +0 -46
- package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.cjs +0 -204
- package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs +0 -203
- package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.cjs +0 -1013
- package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs +0 -1008
- package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.cjs +0 -128
- package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.mjs +0 -124
- package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.mjs.map +0 -1
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.cjs +0 -41464
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.mjs +0 -41462
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.mjs.map +0 -1
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.cjs +0 -4387
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.mjs +0 -4385
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.mjs.map +0 -1
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.cjs +0 -26
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.mjs +0 -27
- package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.mjs.map +0 -1
- package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.cjs +0 -370
- package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.mjs +0 -368
- package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.cjs +0 -939
- package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +0 -940
- package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs.map +0 -1
- package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.cjs +0 -67
- package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.mjs +0 -65
- package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/mlly@1.8.1/node_modules/mlly/dist/index.cjs +0 -1350
- package/dist/node_modules/.pnpm/mlly@1.8.1/node_modules/mlly/dist/index.mjs +0 -1343
- package/dist/node_modules/.pnpm/mlly@1.8.1/node_modules/mlly/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs +0 -179
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs +0 -178
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs.map +0 -1
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.cjs +0 -20
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.mjs +0 -17
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.cjs +0 -3975
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.mjs +0 -3962
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.mjs.map +0 -1
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.cjs +0 -16
- package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs +0 -15
- 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 +0 -1
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.cjs +0 -36
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.mjs +0 -34
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.mjs.map +0 -1
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.cjs +0 -227
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs +0 -226
- package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs.map +0 -1
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.cjs +0 -139
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -134
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs.map +0 -1
- package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.cjs +0 -78
- package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs +0 -78
- package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.cjs +0 -72
- package/dist/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs +0 -70
- package/dist/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/ufo@1.6.3/node_modules/ufo/dist/index.cjs +0 -181
- package/dist/node_modules/.pnpm/ufo@1.6.3/node_modules/ufo/dist/index.mjs +0 -179
- package/dist/node_modules/.pnpm/ufo@1.6.3/node_modules/ufo/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.cjs +0 -12337
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.mjs +0 -12338
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.mjs.map +0 -1
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.cjs +0 -19
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.mjs +0 -19
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.mjs.map +0 -1
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.cjs +0 -71
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.mjs +0 -72
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.mjs.map +0 -1
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.cjs +0 -110
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.mjs +0 -101
- package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.mjs.map +0 -1
|
@@ -1,652 +0,0 @@
|
|
|
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.1/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=5b5d5334735dce5e1ae79d8924a5aa49e4139453056613d618786b961793a42b_magicast@0.5.2/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, config = {}) {
|
|
513
|
-
const blocks = [];
|
|
514
|
-
for (const match of md.matchAll(new RegExp(`^(?<open><!--\\s*(${config.prefix.join("|")}):(?<generator>.+?)\\s+(?<args>.*?)\\s*-->)(?<contents>.+?)(?<close>^<!--\\s*\\/(${config.prefix.join("|")})\\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, config = {}) {
|
|
535
|
-
return new RegExp(`^<!--\\s*(${config.prefix.join("|")}):`, "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.prefix = _config.prefix || [];
|
|
559
|
-
if (typeof _config.prefix === "string") _config.prefix = [_config.prefix];
|
|
560
|
-
if (!_config.prefix.includes("automd")) _config.prefix.push("automd");
|
|
561
|
-
if (!_config.prefix.includes("powerlines")) _config.prefix.push("powerlines");
|
|
562
|
-
_config.dir = resolve(_config.dir);
|
|
563
|
-
_config.input = (Array.isArray(_config.input) ? _config.input : [_config.input]).filter(Boolean);
|
|
564
|
-
return _config;
|
|
565
|
-
}
|
|
566
|
-
async function loadConfig(dir = ".", overrides) {
|
|
567
|
-
const { loadConfig: loadConfig$1 } = await import("c12");
|
|
568
|
-
dir = resolve(dir);
|
|
569
|
-
const { config } = await loadConfig$1({
|
|
570
|
-
cwd: dir,
|
|
571
|
-
name: "automd",
|
|
572
|
-
dotenv: true,
|
|
573
|
-
overrides,
|
|
574
|
-
defaults: {
|
|
575
|
-
ignore: [
|
|
576
|
-
"**/node_modules",
|
|
577
|
-
"**/dist",
|
|
578
|
-
"**/.*"
|
|
579
|
-
],
|
|
580
|
-
dir
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
return resolveConfig(config);
|
|
584
|
-
}
|
|
585
|
-
async function transform(contents, _config, url) {
|
|
586
|
-
const start = performance.now();
|
|
587
|
-
const config = resolveConfig(_config);
|
|
588
|
-
const editor = new MagicString(contents);
|
|
589
|
-
const updates = [];
|
|
590
|
-
const generators = {
|
|
591
|
-
...generators_default,
|
|
592
|
-
...config.generators
|
|
593
|
-
};
|
|
594
|
-
const blocks = findBlocks(contents, config);
|
|
595
|
-
for (const block of blocks) {
|
|
596
|
-
const result = await _transformBlock(block, config, generators, url);
|
|
597
|
-
if (result.unwrap) editor.overwrite(block._loc.start, block._loc.end, `${result.contents.trim()}`);
|
|
598
|
-
else editor.overwrite(block.loc.start, block.loc.end, `\n\n${result.contents.trim()}\n\n`);
|
|
599
|
-
updates.push({
|
|
600
|
-
block,
|
|
601
|
-
result
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
const hasChanged = editor.hasChanged();
|
|
605
|
-
const hasIssues = updates.some((u) => u.result.issues?.filter(Boolean).length);
|
|
606
|
-
const time = performance.now() - start;
|
|
607
|
-
return {
|
|
608
|
-
hasChanged,
|
|
609
|
-
hasIssues,
|
|
610
|
-
contents: hasChanged ? editor.toString() : contents,
|
|
611
|
-
updates,
|
|
612
|
-
time
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
async function _transformBlock(block, config, generators, url) {
|
|
616
|
-
const args = parseRawArgs(block.rawArgs);
|
|
617
|
-
const generator = generators[block.generator];
|
|
618
|
-
if (!generator) {
|
|
619
|
-
const suggestions = (await import("../../../../didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs").then((r) => r.default || r))(block.generator, Object.keys(generators));
|
|
620
|
-
const error = `Unknown generator:\`${block.generator}\`.${suggestions ? ` Did you mean "generator:\`${suggestions}\`"?` : ""}`;
|
|
621
|
-
return {
|
|
622
|
-
contents: `<!-- ⚠️ ${error} -->`,
|
|
623
|
-
issues: [error]
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
const context = {
|
|
627
|
-
args,
|
|
628
|
-
config,
|
|
629
|
-
block,
|
|
630
|
-
transform: (contents) => transform(contents, config, url),
|
|
631
|
-
url
|
|
632
|
-
};
|
|
633
|
-
try {
|
|
634
|
-
const result = await generator.generate(context);
|
|
635
|
-
if (!result.unwrap && containsAutomd(result.contents, config)) result.unwrap = true;
|
|
636
|
-
if (result.unwrap) {
|
|
637
|
-
const nestedRes = await context.transform(result.contents);
|
|
638
|
-
result.contents = nestedRes.contents;
|
|
639
|
-
if (nestedRes.hasIssues) result.issues = [...result.issues || [], ...nestedRes.updates.flatMap((u) => u.result.issues || [])].filter(Boolean);
|
|
640
|
-
}
|
|
641
|
-
return result;
|
|
642
|
-
} catch (error) {
|
|
643
|
-
return {
|
|
644
|
-
contents: `<!-- ⚠️ (${block.generator}) ${error.message || error} -->`,
|
|
645
|
-
issues: [error]
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
//#endregion
|
|
651
|
-
export { loadConfig, resolveConfig, transform };
|
|
652
|
-
//# sourceMappingURL=index.mjs.map
|