@stephansama/auto-readme 0.2.0 → 0.2.2
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 +1 -0
- package/config/schema.cjs +122 -124
- package/config/schema.cjs.map +1 -1
- package/config/schema.d.cts +134 -131
- package/config/schema.d.ts +134 -131
- package/config/schema.js +96 -97
- package/config/schema.js.map +1 -1
- package/config/schema.json +1 -1
- package/config/schema.yaml +5 -0
- package/dist/index.cjs +604 -646
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +559 -616
- package/dist/index.js.map +1 -1
- package/package.json +21 -21
package/dist/index.cjs
CHANGED
|
@@ -1,726 +1,684 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
8
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
run: () => run
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var import_mdast_util_from_markdown2 = require("mdast-util-from-markdown");
|
|
37
|
-
var cp2 = __toESM(require("child_process"), 1);
|
|
38
|
-
var fsp3 = __toESM(require("fs/promises"), 1);
|
|
39
|
-
var import_ora = __toESM(require("ora"), 1);
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
40
22
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
let mdast_util_from_markdown = require("mdast-util-from-markdown");
|
|
25
|
+
mdast_util_from_markdown = __toESM(mdast_util_from_markdown);
|
|
26
|
+
let node_child_process = require("node:child_process");
|
|
27
|
+
node_child_process = __toESM(node_child_process);
|
|
28
|
+
let node_fs_promises = require("node:fs/promises");
|
|
29
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
30
|
+
let ora = require("ora");
|
|
31
|
+
ora = __toESM(ora);
|
|
32
|
+
let debug = require("debug");
|
|
33
|
+
debug = __toESM(debug);
|
|
34
|
+
let yargs = require("yargs");
|
|
35
|
+
yargs = __toESM(yargs);
|
|
36
|
+
let yargs_helpers = require("yargs/helpers");
|
|
37
|
+
yargs_helpers = __toESM(yargs_helpers);
|
|
38
|
+
let zod = require("zod");
|
|
39
|
+
zod = __toESM(zod);
|
|
40
|
+
let mdast_comment_marker = require("mdast-comment-marker");
|
|
41
|
+
mdast_comment_marker = __toESM(mdast_comment_marker);
|
|
42
|
+
let __iarna_toml = require("@iarna/toml");
|
|
43
|
+
__iarna_toml = __toESM(__iarna_toml);
|
|
44
|
+
let cosmiconfig = require("cosmiconfig");
|
|
45
|
+
cosmiconfig = __toESM(cosmiconfig);
|
|
46
|
+
let deepmerge = require("deepmerge");
|
|
47
|
+
deepmerge = __toESM(deepmerge);
|
|
48
|
+
let __manypkg_get_packages = require("@manypkg/get-packages");
|
|
49
|
+
__manypkg_get_packages = __toESM(__manypkg_get_packages);
|
|
50
|
+
let node_fs = require("node:fs");
|
|
51
|
+
node_fs = __toESM(node_fs);
|
|
52
|
+
let node_path = require("node:path");
|
|
53
|
+
node_path = __toESM(node_path);
|
|
54
|
+
let pkg_types = require("pkg-types");
|
|
55
|
+
pkg_types = __toESM(pkg_types);
|
|
56
|
+
let yaml = require("yaml");
|
|
57
|
+
yaml = __toESM(yaml);
|
|
58
|
+
let zod2md = require("zod2md");
|
|
59
|
+
zod2md = __toESM(zod2md);
|
|
60
|
+
let fast_glob = require("fast-glob");
|
|
61
|
+
fast_glob = __toESM(fast_glob);
|
|
62
|
+
let remark = require("remark");
|
|
63
|
+
remark = __toESM(remark);
|
|
64
|
+
let remark_code_import = require("remark-code-import");
|
|
65
|
+
remark_code_import = __toESM(remark_code_import);
|
|
66
|
+
let remark_collapse = require("remark-collapse");
|
|
67
|
+
remark_collapse = __toESM(remark_collapse);
|
|
68
|
+
let remark_toc = require("remark-toc");
|
|
69
|
+
remark_toc = __toESM(remark_toc);
|
|
70
|
+
let remark_usage = require("remark-usage");
|
|
71
|
+
remark_usage = __toESM(remark_usage);
|
|
72
|
+
let vfile = require("vfile");
|
|
73
|
+
vfile = __toESM(vfile);
|
|
74
|
+
let handlebars = require("handlebars");
|
|
75
|
+
handlebars = __toESM(handlebars);
|
|
76
|
+
let markdown_table = require("markdown-table");
|
|
77
|
+
markdown_table = __toESM(markdown_table);
|
|
78
|
+
let mdast_zone = require("mdast-zone");
|
|
79
|
+
mdast_zone = __toESM(mdast_zone);
|
|
46
80
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
//#region src/schema.js
|
|
82
|
+
const actionsSchema = zod.z.enum([
|
|
83
|
+
"ACTION",
|
|
84
|
+
"PKG",
|
|
85
|
+
"USAGE",
|
|
86
|
+
"WORKSPACE",
|
|
87
|
+
"ZOD"
|
|
88
|
+
]).describe("Comment action options");
|
|
89
|
+
const formatsSchema = zod.z.enum(["LIST", "TABLE"]).default("TABLE").optional();
|
|
90
|
+
const languageSchema = zod.z.enum(["JS", "RS"]).optional().default("JS");
|
|
91
|
+
const headingsSchema = zod.z.enum([
|
|
92
|
+
"default",
|
|
93
|
+
"description",
|
|
94
|
+
"devDependency",
|
|
95
|
+
"downloads",
|
|
96
|
+
"name",
|
|
97
|
+
"private",
|
|
98
|
+
"required",
|
|
99
|
+
"version"
|
|
61
100
|
]).describe("Table heading options");
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
101
|
+
const tableHeadingsSchema = zod.z.record(actionsSchema, headingsSchema.array().optional()).optional().describe("Table heading action configuration").default({
|
|
102
|
+
ACTION: [
|
|
103
|
+
"name",
|
|
104
|
+
"required",
|
|
105
|
+
"default",
|
|
106
|
+
"description"
|
|
107
|
+
],
|
|
108
|
+
PKG: [
|
|
109
|
+
"name",
|
|
110
|
+
"version",
|
|
111
|
+
"devDependency"
|
|
112
|
+
],
|
|
113
|
+
WORKSPACE: [
|
|
114
|
+
"name",
|
|
115
|
+
"version",
|
|
116
|
+
"downloads",
|
|
117
|
+
"description"
|
|
118
|
+
],
|
|
119
|
+
ZOD: []
|
|
67
120
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"https://img.shields.io/npm/v/{{uri_name}}?logo=npm&logoColor=red&color=211F1F&labelColor=211F1F"
|
|
83
|
-
)
|
|
121
|
+
const templatesSchema = zod.z.object({
|
|
122
|
+
downloadImage: zod.z.string().optional().default("https://img.shields.io/npm/dw/{{name}}?labelColor=211F1F"),
|
|
123
|
+
emojis: zod.z.record(headingsSchema, zod.z.string()).optional().describe("Table heading emojis used when enabled").default({
|
|
124
|
+
default: "⚙️",
|
|
125
|
+
description: "📝",
|
|
126
|
+
devDependency: "💻",
|
|
127
|
+
downloads: "📥",
|
|
128
|
+
name: "🏷️",
|
|
129
|
+
private: "🔒",
|
|
130
|
+
required: "",
|
|
131
|
+
version: ""
|
|
132
|
+
}),
|
|
133
|
+
registryUrl: zod.z.string().optional().default("https://www.npmjs.com/package/{{name}}"),
|
|
134
|
+
versionImage: zod.z.string().optional().default("https://img.shields.io/npm/v/{{uri_name}}?logo=npm&logoColor=red&color=211F1F&labelColor=211F1F")
|
|
84
135
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
tocHeading: import_zod.z.string().optional().default("Table of contents").meta({
|
|
124
|
-
description: "Markdown heading used to generate table of contents"
|
|
125
|
-
}),
|
|
126
|
-
usageFile: import_zod.z.string().optional().default("").meta({
|
|
127
|
-
description: "Workspace level usage file"
|
|
128
|
-
}),
|
|
129
|
-
usageHeading: import_zod.z.string().optional().default("Usage").meta({
|
|
130
|
-
description: "Markdown heading used to generate usage example"
|
|
131
|
-
}),
|
|
132
|
-
verbose: import_zod.z.boolean().default(false).meta({
|
|
133
|
-
alias: "v",
|
|
134
|
-
description: "whether or not to display verbose logging"
|
|
135
|
-
})
|
|
136
|
+
const defaultTemplates = templatesSchema.parse({});
|
|
137
|
+
const defaultTableHeadings = tableHeadingsSchema.parse(void 0);
|
|
138
|
+
const _configSchema = zod.z.object({
|
|
139
|
+
affectedRegexes: zod.z.string().array().optional().default([]),
|
|
140
|
+
collapseHeadings: zod.z.string().array().optional().default([]),
|
|
141
|
+
defaultLanguage: languageSchema.meta({
|
|
142
|
+
alias: "l",
|
|
143
|
+
description: "Default language to infer projects from"
|
|
144
|
+
}),
|
|
145
|
+
disableEmojis: zod.z.boolean().default(false).meta({
|
|
146
|
+
alias: "e",
|
|
147
|
+
description: "Whether or not to use emojis in markdown table headings"
|
|
148
|
+
}),
|
|
149
|
+
disableMarkdownHeadings: zod.z.boolean().default(false).meta({ description: "Whether or not to display markdown headings" }),
|
|
150
|
+
enablePrettier: zod.z.boolean().default(true).meta({ description: "Whether or not to use prettier to format the files" }),
|
|
151
|
+
enableToc: zod.z.boolean().default(false).meta({
|
|
152
|
+
alias: "t",
|
|
153
|
+
description: "generate table of contents for readmes"
|
|
154
|
+
}),
|
|
155
|
+
enableUsage: zod.z.boolean().optional().default(false).meta({ description: "Whether or not to enable usage plugin" }),
|
|
156
|
+
headings: tableHeadingsSchema.optional().default(defaultTableHeadings).describe("List of headings for different table outputs"),
|
|
157
|
+
onlyReadmes: zod.z.boolean().default(true).meta({
|
|
158
|
+
alias: "r",
|
|
159
|
+
description: "Whether or not to only traverse readmes"
|
|
160
|
+
}),
|
|
161
|
+
onlyShowPublicPackages: zod.z.boolean().default(false).meta({
|
|
162
|
+
alias: "p",
|
|
163
|
+
description: "Only show public packages in workspaces"
|
|
164
|
+
}),
|
|
165
|
+
removeScope: zod.z.string().optional().default("").meta({ description: "Remove common workspace scope" }),
|
|
166
|
+
templates: templatesSchema.optional().default(defaultTemplates).describe("Handlebars templates used to fuel list and table generation"),
|
|
167
|
+
tocHeading: zod.z.string().optional().default("Table of contents").meta({ description: "Markdown heading used to generate table of contents" }),
|
|
168
|
+
usageFile: zod.z.string().optional().default("").meta({ description: "Workspace level usage file" }),
|
|
169
|
+
usageHeading: zod.z.string().optional().default("Usage").meta({ description: "Markdown heading used to generate usage example" }),
|
|
170
|
+
verbose: zod.z.boolean().default(false).meta({
|
|
171
|
+
alias: "v",
|
|
172
|
+
description: "whether or not to display verbose logging"
|
|
173
|
+
})
|
|
136
174
|
});
|
|
137
|
-
|
|
175
|
+
const configSchema = _configSchema.optional();
|
|
176
|
+
/** @typedef {Partial<z.infer<typeof _configSchema>>} Config */
|
|
138
177
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/args.ts
|
|
180
|
+
const complexOptions = [
|
|
181
|
+
"affectedRegexes",
|
|
182
|
+
"collapseHeadings",
|
|
183
|
+
"headings",
|
|
184
|
+
"templates"
|
|
145
185
|
];
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
186
|
+
const args = {
|
|
187
|
+
...zodToYargs(),
|
|
188
|
+
changes: {
|
|
189
|
+
alias: "g",
|
|
190
|
+
default: false,
|
|
191
|
+
description: "Check only changed git files",
|
|
192
|
+
type: "boolean"
|
|
193
|
+
},
|
|
194
|
+
check: {
|
|
195
|
+
alias: "k",
|
|
196
|
+
default: false,
|
|
197
|
+
description: "Do not write to files. Only check for changes",
|
|
198
|
+
type: "boolean"
|
|
199
|
+
},
|
|
200
|
+
config: {
|
|
201
|
+
alias: "c",
|
|
202
|
+
description: "Path to config file",
|
|
203
|
+
type: "string"
|
|
204
|
+
}
|
|
161
205
|
};
|
|
162
206
|
async function parseArgs() {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
207
|
+
const yargsInstance = (0, yargs.default)((0, yargs_helpers.hideBin)(process.argv)).options(args).help("h").alias("h", "help").epilogue(`--> @stephansama open-source ${(/* @__PURE__ */ new Date()).getFullYear()}`);
|
|
208
|
+
const parsed = await yargsInstance.wrap(yargsInstance.terminalWidth()).parse();
|
|
209
|
+
if (parsed.verbose) debug.default.enable("autoreadme*");
|
|
210
|
+
return parsed;
|
|
167
211
|
}
|
|
168
212
|
function zodToYargs() {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return Object.fromEntries(entries);
|
|
213
|
+
const { shape } = configSchema.unwrap();
|
|
214
|
+
const entries = Object.entries(shape).map(([key, value]) => {
|
|
215
|
+
if (complexOptions.includes(key)) return [];
|
|
216
|
+
if (value.def.innerType instanceof zod.default.ZodObject) return [];
|
|
217
|
+
const meta = value.meta();
|
|
218
|
+
const { innerType } = value.def;
|
|
219
|
+
const isBoolean = innerType instanceof zod.default.ZodBoolean;
|
|
220
|
+
const isNumber = innerType instanceof zod.default.ZodNumber;
|
|
221
|
+
const yargType = innerType instanceof zod.default.ZodArray && "array" || isNumber && "number" || isBoolean && "boolean" || "string";
|
|
222
|
+
const options = {
|
|
223
|
+
default: value.def.defaultValue,
|
|
224
|
+
type: yargType
|
|
225
|
+
};
|
|
226
|
+
if (meta?.alias) options.alias = meta.alias;
|
|
227
|
+
if (meta?.description) options.description = meta.description;
|
|
228
|
+
return [key, options];
|
|
229
|
+
});
|
|
230
|
+
return Object.fromEntries(entries);
|
|
188
231
|
}
|
|
189
232
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var error = (0, import_debug2.default)("autoreadme:error");
|
|
196
|
-
var info = (0, import_debug2.default)("autoreadme:info");
|
|
197
|
-
var warn = (0, import_debug2.default)("autoreadme:warn");
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/log.ts
|
|
235
|
+
const error = (0, debug.default)("autoreadme:error");
|
|
236
|
+
const info = (0, debug.default)("autoreadme:info");
|
|
237
|
+
const warn = (0, debug.default)("autoreadme:warn");
|
|
198
238
|
function ERROR(...rest) {
|
|
199
|
-
|
|
200
|
-
|
|
239
|
+
const [first, ...remaining] = rest;
|
|
240
|
+
error(`${first} %O`, ...remaining);
|
|
201
241
|
}
|
|
202
242
|
function INFO(...rest) {
|
|
203
|
-
|
|
204
|
-
|
|
243
|
+
const [first, ...remaining] = rest;
|
|
244
|
+
info(`${first} %O`, ...remaining);
|
|
205
245
|
}
|
|
206
246
|
function WARN(...rest) {
|
|
207
|
-
|
|
208
|
-
|
|
247
|
+
const [first, ...remaining] = rest;
|
|
248
|
+
warn(`${first} %O`, ...remaining);
|
|
209
249
|
}
|
|
210
250
|
|
|
211
|
-
|
|
212
|
-
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/comment.ts
|
|
253
|
+
const SEPARATOR = "-";
|
|
213
254
|
function loadAstComments(root) {
|
|
214
|
-
|
|
255
|
+
return root.children.map((child) => child.type === "html" && getComment(child)).filter((f) => f !== false);
|
|
215
256
|
}
|
|
216
257
|
function parseComment(comment) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
258
|
+
const [type, ...parameters] = trimComment(comment).split(" ");
|
|
259
|
+
const [first, second, third] = type.split(SEPARATOR);
|
|
260
|
+
INFO("parsing inputs", {
|
|
261
|
+
first,
|
|
262
|
+
second,
|
|
263
|
+
third
|
|
264
|
+
});
|
|
265
|
+
const languageInput = third ? first : void 0;
|
|
266
|
+
const actionInput = third ? second : first;
|
|
267
|
+
const formatInput = third ? third : second;
|
|
268
|
+
const language = languageSchema.parse(languageInput);
|
|
269
|
+
const parsed = {
|
|
270
|
+
action: actionsSchema.parse(actionInput),
|
|
271
|
+
format: formatsSchema.parse(formatInput),
|
|
272
|
+
isStart: comment.includes("start"),
|
|
273
|
+
language,
|
|
274
|
+
parameters
|
|
275
|
+
};
|
|
276
|
+
INFO(`Parsed comment ${comment}`, parsed);
|
|
277
|
+
return parsed;
|
|
231
278
|
}
|
|
232
|
-
|
|
233
|
-
|
|
279
|
+
const startComment = "<!--";
|
|
280
|
+
const endComment = "-->";
|
|
234
281
|
function trimComment(comment) {
|
|
235
|
-
|
|
282
|
+
return comment.replace(startComment, "").replace(/start|end/, "").replace(endComment, "").trim();
|
|
236
283
|
}
|
|
237
284
|
function getComment(comment) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return parseComment(comment.value);
|
|
285
|
+
if (!isComment(comment.value)) return false;
|
|
286
|
+
if (!(0, mdast_comment_marker.commentMarker)(comment)) return false;
|
|
287
|
+
return parseComment(comment.value);
|
|
242
288
|
}
|
|
243
289
|
function isComment(comment) {
|
|
244
|
-
|
|
290
|
+
return comment.startsWith(startComment) && comment.endsWith(endComment);
|
|
245
291
|
}
|
|
246
292
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return configSchema.parse(
|
|
270
|
-
(0, import_deepmerge.default)(search?.config || {}, args2, {
|
|
271
|
-
arrayMerge: (_, sourceArray) => sourceArray
|
|
272
|
-
})
|
|
273
|
-
);
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/config.ts
|
|
295
|
+
const moduleName = "autoreadme";
|
|
296
|
+
const searchPlaces = getSearchPlaces();
|
|
297
|
+
const loaders = { [".toml"]: loadToml };
|
|
298
|
+
async function loadConfig(args$1) {
|
|
299
|
+
const opts$1 = {
|
|
300
|
+
loaders,
|
|
301
|
+
searchPlaces
|
|
302
|
+
};
|
|
303
|
+
if (args$1.config) opts$1.searchPlaces = [args$1.config];
|
|
304
|
+
const search = await (0, cosmiconfig.cosmiconfig)(moduleName, opts$1).search();
|
|
305
|
+
if (!search) {
|
|
306
|
+
WARN(`no config file found`, args$1.config ? " at location: " + args$1.config : "");
|
|
307
|
+
INFO("using default configuration");
|
|
308
|
+
} else {
|
|
309
|
+
INFO("found configuration file at: ", search.filepath);
|
|
310
|
+
INFO("loaded cosmiconfig", search.config);
|
|
311
|
+
}
|
|
312
|
+
args$1 = removeFalsy(args$1);
|
|
313
|
+
INFO("merging config with args", args$1);
|
|
314
|
+
return configSchema.parse((0, deepmerge.default)(search?.config || {}, args$1, { arrayMerge: (_, sourceArray) => sourceArray }));
|
|
274
315
|
}
|
|
275
316
|
function loadToml(_filepath, content) {
|
|
276
|
-
|
|
317
|
+
return __iarna_toml.default.parse(content);
|
|
277
318
|
}
|
|
278
319
|
function getSearchPlaces() {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
320
|
+
return [
|
|
321
|
+
...(0, cosmiconfig.getDefaultSearchPlaces)(moduleName),
|
|
322
|
+
`.${moduleName}rc.toml`,
|
|
323
|
+
`.config/.${moduleName}rc`,
|
|
324
|
+
`.config/${moduleName}rc.toml`,
|
|
325
|
+
`.config/.${moduleName}rc.toml`,
|
|
326
|
+
`.config/.${moduleName}rc.json`,
|
|
327
|
+
`.config/.${moduleName}rc.yaml`,
|
|
328
|
+
`.config/.${moduleName}rc.yml`
|
|
329
|
+
];
|
|
289
330
|
}
|
|
290
331
|
function removeFalsy(obj) {
|
|
291
|
-
|
|
292
|
-
Object.entries(obj).map(([k, v]) => !v ? false : [k, v]).filter((e) => Boolean(e))
|
|
293
|
-
);
|
|
332
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => !v ? false : [k, v]).filter((e) => Boolean(e)));
|
|
294
333
|
}
|
|
295
334
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
var cp = __toESM(require("child_process"), 1);
|
|
308
|
-
var fs = __toESM(require("fs"), 1);
|
|
309
|
-
var fsp = __toESM(require("fs/promises"), 1);
|
|
310
|
-
var path = __toESM(require("path"), 1);
|
|
311
|
-
var sh = String.raw;
|
|
312
|
-
var opts = { encoding: "utf8" };
|
|
313
|
-
var ignore = ["**/node_modules/**"];
|
|
314
|
-
var matches = [
|
|
315
|
-
/.*README\.md$/gi,
|
|
316
|
-
/.*Cargo\.toml$/gi,
|
|
317
|
-
/.*action\.ya?ml$/gi,
|
|
318
|
-
/.*package\.json$/gi,
|
|
319
|
-
/.*pnpm-workspace\.yaml$/gi
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/utils.ts
|
|
337
|
+
const sh = String.raw;
|
|
338
|
+
const opts = { encoding: "utf8" };
|
|
339
|
+
const ignore = ["**/node_modules/**"];
|
|
340
|
+
const matches = [
|
|
341
|
+
/.*README\.md$/gi,
|
|
342
|
+
/.*Cargo\.toml$/gi,
|
|
343
|
+
/.*action\.ya?ml$/gi,
|
|
344
|
+
/.*package\.json$/gi,
|
|
345
|
+
/.*pnpm-workspace\.yaml$/gi
|
|
320
346
|
];
|
|
321
347
|
async function fileExists(file) {
|
|
322
|
-
|
|
348
|
+
return await node_fs_promises.access(file).then(() => true).catch(() => false);
|
|
323
349
|
}
|
|
324
350
|
function findAffectedMarkdowns(root, config) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
const md = eligible.map((e) => findNearestReadme(root, path.resolve(e)));
|
|
338
|
-
const rootMd = path.join(root, "README.md");
|
|
339
|
-
const dedupe = [...new Set(md), rootMd].filter(
|
|
340
|
-
(s) => Boolean(s)
|
|
341
|
-
);
|
|
342
|
-
INFO("Found the following readmes", dedupe);
|
|
343
|
-
return dedupe;
|
|
351
|
+
const affected = node_child_process.execSync(sh`git diff --cached --name-only --diff-filter=MACT`, opts).trim().split("\n").filter(Boolean);
|
|
352
|
+
if (!affected.length) ERROR("no staged files found");
|
|
353
|
+
if (config.affectedRegexes?.length) INFO("adding the following expressions: ", config.affectedRegexes);
|
|
354
|
+
const allMatches = [...matches, ...config.affectedRegexes?.map((r) => new RegExp(r)) || []];
|
|
355
|
+
INFO("Checking affected files against regexes", affected, allMatches);
|
|
356
|
+
const eligible = affected.filter((a) => allMatches.some((m) => a.match(m)));
|
|
357
|
+
INFO("Found the following eligible affected files", eligible);
|
|
358
|
+
const md = eligible.map((e) => findNearestReadme(root, node_path.resolve(e)));
|
|
359
|
+
const rootMd = node_path.join(root, "README.md");
|
|
360
|
+
const dedupe = [...new Set(md), rootMd].filter((s) => Boolean(s));
|
|
361
|
+
INFO("Found the following readmes", dedupe);
|
|
362
|
+
return dedupe;
|
|
344
363
|
}
|
|
345
364
|
function findNearestReadme(gitRoot, inputFile, maxRotations = 15) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
return null;
|
|
365
|
+
let dir = node_path.dirname(inputFile);
|
|
366
|
+
let rotations = 0;
|
|
367
|
+
while (true) {
|
|
368
|
+
const option = node_path.join(dir, "README.md");
|
|
369
|
+
if (node_fs.existsSync(option)) return option;
|
|
370
|
+
const parent = node_path.dirname(dir);
|
|
371
|
+
if (parent === dir || dir === gitRoot || ++rotations > maxRotations) break;
|
|
372
|
+
dir = parent;
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
358
375
|
}
|
|
359
376
|
function getGitRoot() {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
INFO("found git root at location: ", root);
|
|
365
|
-
return root;
|
|
377
|
+
const root = node_child_process.execSync(sh`git rev-parse --show-toplevel`, opts).trim();
|
|
378
|
+
if (!root) throw new Error("must be ran within a git directory.");
|
|
379
|
+
INFO("found git root at location: ", root);
|
|
380
|
+
return root;
|
|
366
381
|
}
|
|
367
382
|
async function getMarkdownPaths(cwd, config) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
383
|
+
return (await (0, fast_glob.default)(`**/${config?.onlyReadmes ? "README" : "*"}.md`, {
|
|
384
|
+
cwd,
|
|
385
|
+
ignore
|
|
386
|
+
})).map((readme) => node_path.resolve(cwd, readme));
|
|
387
|
+
}
|
|
388
|
+
async function getPrettierPaths(paths) {
|
|
389
|
+
return await Promise.all(paths.map(async (file) => {
|
|
390
|
+
if (!(await node_fs_promises.lstat(file)).isSymbolicLink()) return file;
|
|
391
|
+
const symlink = await node_fs_promises.readlink(file);
|
|
392
|
+
return node_path.join(node_path.dirname(file), symlink);
|
|
393
|
+
}));
|
|
371
394
|
}
|
|
372
395
|
|
|
373
|
-
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/data.ts
|
|
374
398
|
function createFindParameter(parameterList) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
399
|
+
return function(parameterName) {
|
|
400
|
+
return parameterList?.find((p) => p.startsWith(parameterName))?.replace(parameterName + "=", "")?.replace(/"/gi, "")?.replace(/_/gi, " ");
|
|
401
|
+
};
|
|
378
402
|
}
|
|
379
403
|
async function loadActionData(actions, file, root) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
body,
|
|
438
|
-
parameters: action.parameters
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
default:
|
|
442
|
-
throw new Error("feature not yet implemented");
|
|
443
|
-
}
|
|
444
|
-
})
|
|
445
|
-
);
|
|
404
|
+
const startActions = actions.filter((action) => action.isStart);
|
|
405
|
+
return await Promise.all(startActions.map(async (action) => {
|
|
406
|
+
const find = createFindParameter(action.parameters);
|
|
407
|
+
switch (action.action) {
|
|
408
|
+
case "ACTION": {
|
|
409
|
+
const actionYaml = await loadActionYaml(node_path.dirname(file));
|
|
410
|
+
return {
|
|
411
|
+
action: action.action,
|
|
412
|
+
actionYaml,
|
|
413
|
+
parameters: action.parameters
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
case "PKG": {
|
|
417
|
+
const inputPath = find("path");
|
|
418
|
+
const pkgJson = await (0, pkg_types.readPackageJSON)(inputPath ? node_path.resolve(node_path.dirname(file), inputPath) : node_path.dirname(file));
|
|
419
|
+
return {
|
|
420
|
+
action: action.action,
|
|
421
|
+
parameters: action.parameters,
|
|
422
|
+
pkgJson
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
case "USAGE": return {
|
|
426
|
+
action: action.action,
|
|
427
|
+
parameters: action.parameters
|
|
428
|
+
};
|
|
429
|
+
case "WORKSPACE": {
|
|
430
|
+
const workspaces = await (0, __manypkg_get_packages.getPackages)(process.cwd());
|
|
431
|
+
const pnpmPath = node_path.resolve(root, "pnpm-workspace.yaml");
|
|
432
|
+
const isPnpm = node_fs.existsSync(pnpmPath);
|
|
433
|
+
return {
|
|
434
|
+
action: action.action,
|
|
435
|
+
isPnpm,
|
|
436
|
+
parameters: action.parameters,
|
|
437
|
+
root,
|
|
438
|
+
workspaces
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
case "ZOD": {
|
|
442
|
+
if (action.format === "LIST") throw new Error("cannot display zod in list format");
|
|
443
|
+
const inputPath = find("path");
|
|
444
|
+
if (!inputPath) {
|
|
445
|
+
const error$1 = `no path found for zod table at markdown file ${file}`;
|
|
446
|
+
throw new Error(error$1);
|
|
447
|
+
}
|
|
448
|
+
const body = await (0, zod2md.zod2md)({
|
|
449
|
+
entry: node_path.resolve(node_path.dirname(file), inputPath),
|
|
450
|
+
title: find("title") || "Zod Schema"
|
|
451
|
+
});
|
|
452
|
+
return {
|
|
453
|
+
action: action.action,
|
|
454
|
+
body,
|
|
455
|
+
parameters: action.parameters
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
default: throw new Error("feature not yet implemented");
|
|
459
|
+
}
|
|
460
|
+
}));
|
|
446
461
|
}
|
|
447
462
|
async function loadActionYaml(baseDir) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
return yaml.parse(actionFile);
|
|
463
|
+
const actionYmlPath = node_path.resolve(baseDir, "action.yml");
|
|
464
|
+
const actionYamlPath = node_path.resolve(baseDir, "action.yaml");
|
|
465
|
+
const actualPath = await fileExists(actionYamlPath) && actionYamlPath || await fileExists(actionYmlPath) && actionYmlPath;
|
|
466
|
+
if (!actualPath) {
|
|
467
|
+
const error$1 = `no yaml file found at locations: ${[actionYmlPath, actionYamlPath]}`;
|
|
468
|
+
throw new Error(error$1);
|
|
469
|
+
}
|
|
470
|
+
const actionFile = await node_fs_promises.readFile(actualPath, { encoding: "utf8" });
|
|
471
|
+
return yaml.parse(actionFile);
|
|
458
472
|
}
|
|
459
473
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
var import_remark = require("remark");
|
|
463
|
-
var import_remark_code_import = __toESM(require("remark-code-import"), 1);
|
|
464
|
-
var import_remark_collapse = __toESM(require("remark-collapse"), 1);
|
|
465
|
-
var import_remark_toc = __toESM(require("remark-toc"), 1);
|
|
466
|
-
var import_remark_usage = __toESM(require("remark-usage"), 1);
|
|
467
|
-
var import_vfile = require("vfile");
|
|
468
|
-
|
|
469
|
-
// src/plugin.ts
|
|
470
|
-
var import_handlebars = __toESM(require("handlebars"), 1);
|
|
471
|
-
var import_markdown_table = require("markdown-table");
|
|
472
|
-
var import_mdast_util_from_markdown = require("mdast-util-from-markdown");
|
|
473
|
-
var import_mdast_zone = require("mdast-zone");
|
|
474
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/plugin.ts
|
|
475
476
|
function createHeading(headings, disableEmojis = false, emojis = defaultTemplates.emojis) {
|
|
476
|
-
|
|
477
|
-
(h) => `${disableEmojis ? "" : emojis[h] + " "}${h?.at(0)?.toUpperCase() + h?.slice(1)}`
|
|
478
|
-
);
|
|
477
|
+
return headings.map((h) => `${disableEmojis ? "" : emojis[h] + " "}${h?.at(0)?.toUpperCase() + h?.slice(1)}`);
|
|
479
478
|
}
|
|
480
479
|
function wrapRequired(required, input) {
|
|
481
|
-
|
|
482
|
-
|
|
480
|
+
if (!required) return input;
|
|
481
|
+
return `<b>*${input}</b>`;
|
|
483
482
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
` + Object.entries(inputs).sort((a) => a[1].required ? -1 : 1).map(([key,
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
return `${isDev ? "\u2328\uFE0F" : "\u{1F465}"}`;
|
|
594
|
-
}
|
|
595
|
-
if (key === "name") {
|
|
596
|
-
return `[${name}](${url})`;
|
|
597
|
-
}
|
|
598
|
-
if (key === "version") {
|
|
599
|
-
if (["workspace", "catalog", "*"].some(
|
|
600
|
-
(type) => version.includes(type)
|
|
601
|
-
)) {
|
|
602
|
-
return `\`${version}\``;
|
|
603
|
-
}
|
|
604
|
-
return ` })})`;
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
const { dependencies = {}, devDependencies = {} } = first?.pkgJson || {};
|
|
610
|
-
const table = (0, import_markdown_table.markdownTable)([
|
|
611
|
-
createHeading(
|
|
612
|
-
headings,
|
|
613
|
-
config.disableEmojis,
|
|
614
|
-
config.templates?.emojis
|
|
615
|
-
),
|
|
616
|
-
...Object.entries(devDependencies).map(mapDependencies(true)),
|
|
617
|
-
...Object.entries(dependencies).map(mapDependencies(false))
|
|
618
|
-
]);
|
|
619
|
-
const heading = `### ${config.disableEmojis ? "" : "\u{1F4E6}"} packages`;
|
|
620
|
-
const body = [heading, "", table].join("\n");
|
|
621
|
-
const tableAst = (0, import_mdast_util_from_markdown.fromMarkdown)(body);
|
|
622
|
-
return [start, tableAst, end];
|
|
623
|
-
});
|
|
483
|
+
const autoReadmeRemarkPlugin = (config, data) => (tree) => {
|
|
484
|
+
(0, mdast_zone.zone)(tree, /.*ZOD.*/gi, function(start, _, end) {
|
|
485
|
+
const zod$1 = data.find((d) => d?.action === "ZOD");
|
|
486
|
+
if (!zod$1?.body) throw new Error("unable to load zod body");
|
|
487
|
+
return [
|
|
488
|
+
start,
|
|
489
|
+
(0, mdast_util_from_markdown.fromMarkdown)(zod$1.body),
|
|
490
|
+
end
|
|
491
|
+
];
|
|
492
|
+
});
|
|
493
|
+
(0, mdast_zone.zone)(tree, /.*ACTION.*/gi, function(start, _, end) {
|
|
494
|
+
const value = start.type === "html" && start.value;
|
|
495
|
+
const options = value && parseComment(value);
|
|
496
|
+
if (!options) throw new Error("not able to parse comment");
|
|
497
|
+
const inputs = data.find((d) => d?.action === "ACTION")?.actionYaml?.inputs || {};
|
|
498
|
+
const heading = `### ${config.disableEmojis ? "" : "🧰"} actions`;
|
|
499
|
+
if (options.format === "LIST") return [
|
|
500
|
+
start,
|
|
501
|
+
(0, mdast_util_from_markdown.fromMarkdown)(`${heading}\n` + Object.entries(inputs).sort((a) => a[1].required ? -1 : 1).map(([key, value$1]) => {
|
|
502
|
+
return `- ${wrapRequired(value$1.required, key)}: (default: ${value$1.default})\n\n${value$1.description}`;
|
|
503
|
+
}).join("\n")),
|
|
504
|
+
end
|
|
505
|
+
];
|
|
506
|
+
const headings = config.headings?.ACTION?.length && config.headings.ACTION || defaultTableHeadings.ACTION;
|
|
507
|
+
return [
|
|
508
|
+
start,
|
|
509
|
+
(0, mdast_util_from_markdown.fromMarkdown)([
|
|
510
|
+
heading,
|
|
511
|
+
"",
|
|
512
|
+
(0, markdown_table.markdownTable)([createHeading(headings, config.disableEmojis, config.templates?.emojis), ...Object.entries(inputs).map(([k, v]) => headings.map((heading$1) => v[heading$1] || k).map(String))])
|
|
513
|
+
].join("\n")),
|
|
514
|
+
end
|
|
515
|
+
];
|
|
516
|
+
});
|
|
517
|
+
(0, mdast_zone.zone)(tree, /.*WORKSPACE.*/gi, function(start, _, end) {
|
|
518
|
+
const value = start.type === "html" && start.value;
|
|
519
|
+
const comment = value && parseComment(value);
|
|
520
|
+
const workspace = data.find((d) => d?.action === "WORKSPACE");
|
|
521
|
+
const templates = loadTemplates(config.templates);
|
|
522
|
+
const packages = workspace?.workspaces?.packages || [];
|
|
523
|
+
const headings = config.headings?.WORKSPACE?.length && config.headings?.WORKSPACE || defaultTableHeadings.WORKSPACE;
|
|
524
|
+
if (comment && comment.format === "LIST") {}
|
|
525
|
+
const table = (0, markdown_table.markdownTable)([createHeading(headings, config.disableEmojis, config.templates?.emojis), ...packages.filter((pkg) => config.onlyShowPublicPackages ? !pkg.packageJson.private : true).map((pkg) => {
|
|
526
|
+
const { name } = pkg.packageJson;
|
|
527
|
+
return headings.map((heading) => {
|
|
528
|
+
if (heading === "name") return `[${config.removeScope ? name.replace(config.removeScope, "") : name}](${node_path.default.relative(process.cwd(), node_path.default.resolve(pkg.dir, "README.md"))})`;
|
|
529
|
+
if (heading === "version") return ` })})`;
|
|
530
|
+
if (heading === "downloads") return `})`;
|
|
531
|
+
if (heading === "description") return pkg.packageJson?.description;
|
|
532
|
+
return ``;
|
|
533
|
+
});
|
|
534
|
+
})]);
|
|
535
|
+
return [
|
|
536
|
+
start,
|
|
537
|
+
(0, mdast_util_from_markdown.fromMarkdown)([
|
|
538
|
+
`### ${config.disableEmojis ? "" : "🏭"} workspace`,
|
|
539
|
+
"",
|
|
540
|
+
table
|
|
541
|
+
].join("\n")),
|
|
542
|
+
end
|
|
543
|
+
];
|
|
544
|
+
});
|
|
545
|
+
(0, mdast_zone.zone)(tree, /.*PKG.*/gi, function(start, _, end) {
|
|
546
|
+
const value = start.type === "html" && start.value;
|
|
547
|
+
const comment = value && parseComment(value);
|
|
548
|
+
const first = data.find((d) => d?.action === "PKG");
|
|
549
|
+
const templates = loadTemplates(config.templates);
|
|
550
|
+
const headings = config.headings?.PKG?.length && config.headings?.PKG || defaultTableHeadings.PKG;
|
|
551
|
+
if (comment && comment.format === "LIST") return [
|
|
552
|
+
start,
|
|
553
|
+
(0, mdast_util_from_markdown.fromMarkdown)(""),
|
|
554
|
+
end
|
|
555
|
+
];
|
|
556
|
+
function mapDependencies(isDev) {
|
|
557
|
+
return function([name, version]) {
|
|
558
|
+
const url = templates.registryUrl({ name });
|
|
559
|
+
return headings.map((key) => {
|
|
560
|
+
if (key === "devDependency") {
|
|
561
|
+
if (config.disableEmojis) return `\`${isDev}\``;
|
|
562
|
+
return `${isDev ? "⌨️" : "👥"}`;
|
|
563
|
+
}
|
|
564
|
+
if (key === "name") return `[${name}](${url})`;
|
|
565
|
+
if (key === "version") {
|
|
566
|
+
if ([
|
|
567
|
+
"workspace",
|
|
568
|
+
"catalog",
|
|
569
|
+
"*"
|
|
570
|
+
].some((type) => version.includes(type))) return `\`${version}\``;
|
|
571
|
+
return ` })})`;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
const { dependencies = {}, devDependencies = {} } = first?.pkgJson || {};
|
|
577
|
+
const table = (0, markdown_table.markdownTable)([
|
|
578
|
+
createHeading(headings, config.disableEmojis, config.templates?.emojis),
|
|
579
|
+
...Object.entries(devDependencies).map(mapDependencies(true)),
|
|
580
|
+
...Object.entries(dependencies).map(mapDependencies(false))
|
|
581
|
+
]);
|
|
582
|
+
return [
|
|
583
|
+
start,
|
|
584
|
+
(0, mdast_util_from_markdown.fromMarkdown)([
|
|
585
|
+
`### ${config.disableEmojis ? "" : "📦"} packages`,
|
|
586
|
+
"",
|
|
587
|
+
table
|
|
588
|
+
].join("\n")),
|
|
589
|
+
end
|
|
590
|
+
];
|
|
591
|
+
});
|
|
624
592
|
};
|
|
625
593
|
function loadTemplates(templates) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
})
|
|
632
|
-
);
|
|
594
|
+
if (!templates) throw new Error("failed to load templates");
|
|
595
|
+
return Object.fromEntries(Object.entries(templates).map(([key, value]) => {
|
|
596
|
+
if (typeof value !== "string") return [];
|
|
597
|
+
return [key, handlebars.default.compile(value)];
|
|
598
|
+
}));
|
|
633
599
|
}
|
|
634
600
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
const vfile = new import_vfile.VFile({ path: path4.resolve(filepath), value: file });
|
|
673
|
-
const markdown = await pipeline.process(vfile);
|
|
674
|
-
return markdown.toString();
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region src/pipeline.ts
|
|
603
|
+
async function parse(file, filepath, root, config, data) {
|
|
604
|
+
const pipeline = (0, remark.remark)().use(autoReadmeRemarkPlugin, config, data).use(remark_code_import.default, {});
|
|
605
|
+
const usage = data.find((d) => d.action === "USAGE");
|
|
606
|
+
if (usage?.action === "USAGE" || config.enableUsage) {
|
|
607
|
+
const examplePath = createFindParameter(usage?.parameters || [])("path");
|
|
608
|
+
const dirname = node_path.dirname(filepath);
|
|
609
|
+
const resolvePath = examplePath && node_path.resolve(dirname, examplePath);
|
|
610
|
+
const relativeProjectPath = config.usageFile && node_path.relative(root, node_path.resolve(dirname, config.usageFile));
|
|
611
|
+
const example = examplePath && resolvePath && node_path.relative(root, resolvePath) || relativeProjectPath || void 0;
|
|
612
|
+
if (example && await fileExists(example)) {
|
|
613
|
+
INFO("generating usage section");
|
|
614
|
+
pipeline.use(remark_usage.default, {
|
|
615
|
+
example,
|
|
616
|
+
heading: config.usageHeading
|
|
617
|
+
});
|
|
618
|
+
} else WARN("not able to find example file for readme", filepath, example);
|
|
619
|
+
}
|
|
620
|
+
if (config.enableToc) {
|
|
621
|
+
INFO("generating table of contents section");
|
|
622
|
+
pipeline.use(remark_toc.default, { heading: config.tocHeading });
|
|
623
|
+
}
|
|
624
|
+
if (config.enableToc || config.collapseHeadings?.length) {
|
|
625
|
+
const headings = [...config.collapseHeadings?.length ? config.collapseHeadings : [], config.tocHeading];
|
|
626
|
+
pipeline.use(remark_collapse.default, { test: {
|
|
627
|
+
ignoreFinalDefinitions: true,
|
|
628
|
+
test: (value, _) => {
|
|
629
|
+
return headings.some((i) => value.trim() === i?.trim());
|
|
630
|
+
}
|
|
631
|
+
} });
|
|
632
|
+
}
|
|
633
|
+
const vfile$1 = new vfile.VFile({
|
|
634
|
+
path: node_path.resolve(filepath),
|
|
635
|
+
value: file
|
|
636
|
+
});
|
|
637
|
+
return (await pipeline.process(vfile$1)).toString();
|
|
675
638
|
}
|
|
676
639
|
|
|
677
|
-
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/index.ts
|
|
678
642
|
async function run() {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
if (isAffected) {
|
|
717
|
-
INFO("adding affected files to git stage");
|
|
718
|
-
cp2.execFileSync("git", ["add", ...paths], opts2);
|
|
719
|
-
}
|
|
720
|
-
if (spinner) spinner.stop();
|
|
643
|
+
const args$1 = await parseArgs();
|
|
644
|
+
const config = await loadConfig(args$1) || {};
|
|
645
|
+
INFO("Loaded the following configuration:", config);
|
|
646
|
+
const root = getGitRoot();
|
|
647
|
+
const isAffected = args$1.changes && "affected";
|
|
648
|
+
INFO(`Loading ${!isAffected ? "all " : "affected "}files`);
|
|
649
|
+
const paths = isAffected ? findAffectedMarkdowns(root, config) : await getMarkdownPaths(root, config);
|
|
650
|
+
INFO("Loaded the following files:", paths.join("\n"));
|
|
651
|
+
const type = args$1.onlyReadmes ? "readmes" : "all markdown files";
|
|
652
|
+
if (!paths.length) return ERROR(`no ${isAffected} readmes found to update`);
|
|
653
|
+
const spinner = !args$1.verbose && (0, ora.default)(`Updating ${type}`).start();
|
|
654
|
+
await Promise.all(paths.map(async (path$1) => {
|
|
655
|
+
const file = await node_fs_promises.readFile(path$1, { encoding: "utf8" });
|
|
656
|
+
const actions = (() => {
|
|
657
|
+
return loadAstComments((0, mdast_util_from_markdown.fromMarkdown)(file));
|
|
658
|
+
})();
|
|
659
|
+
if (!actions.length) {
|
|
660
|
+
WARN(`no action comments found in`, path$1);
|
|
661
|
+
if (!config.enableUsage || !config.enableToc) return ERROR("no action or plugins found");
|
|
662
|
+
else INFO("plugins enabled. continuing parsing", path$1);
|
|
663
|
+
}
|
|
664
|
+
const data = await loadActionData(actions, path$1, root);
|
|
665
|
+
INFO("Loaded comment action data", data);
|
|
666
|
+
const content = await parse(file, path$1, root, config, data);
|
|
667
|
+
await node_fs_promises.writeFile(path$1, content);
|
|
668
|
+
}));
|
|
669
|
+
const opts$1 = { stdio: "inherit" };
|
|
670
|
+
if (config.enablePrettier) {
|
|
671
|
+
INFO("formatting with prettier");
|
|
672
|
+
const prettierPaths = await getPrettierPaths(paths);
|
|
673
|
+
node_child_process.execFileSync("prettier", ["--write", ...prettierPaths], opts$1);
|
|
674
|
+
}
|
|
675
|
+
if (isAffected) {
|
|
676
|
+
INFO("adding affected files to git stage");
|
|
677
|
+
node_child_process.execFileSync("git", ["add", ...paths], opts$1);
|
|
678
|
+
}
|
|
679
|
+
if (spinner) spinner.stop();
|
|
721
680
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
});
|
|
681
|
+
|
|
682
|
+
//#endregion
|
|
683
|
+
exports.run = run;
|
|
726
684
|
//# sourceMappingURL=index.cjs.map
|