@stephansama/auto-readme 0.2.1 → 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/config/schema.cjs +122 -127
- package/config/schema.cjs.map +1 -1
- package/config/schema.d.cts +134 -133
- package/config/schema.d.ts +134 -133
- package/config/schema.js +96 -100
- package/config/schema.js.map +1 -1
- package/dist/index.cjs +602 -661
- 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 +557 -631
- package/dist/index.js.map +1 -1
- package/package.json +21 -21
package/dist/index.cjs
CHANGED
|
@@ -1,743 +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
|
-
templates: templatesSchema.optional().default(defaultTemplates).describe(
|
|
124
|
-
"Handlebars templates used to fuel list and table generation"
|
|
125
|
-
),
|
|
126
|
-
tocHeading: import_zod.z.string().optional().default("Table of contents").meta({
|
|
127
|
-
description: "Markdown heading used to generate table of contents"
|
|
128
|
-
}),
|
|
129
|
-
usageFile: import_zod.z.string().optional().default("").meta({
|
|
130
|
-
description: "Workspace level usage file"
|
|
131
|
-
}),
|
|
132
|
-
usageHeading: import_zod.z.string().optional().default("Usage").meta({
|
|
133
|
-
description: "Markdown heading used to generate usage example"
|
|
134
|
-
}),
|
|
135
|
-
verbose: import_zod.z.boolean().default(false).meta({
|
|
136
|
-
alias: "v",
|
|
137
|
-
description: "whether or not to display verbose logging"
|
|
138
|
-
})
|
|
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
|
+
})
|
|
139
174
|
});
|
|
140
|
-
|
|
175
|
+
const configSchema = _configSchema.optional();
|
|
176
|
+
/** @typedef {Partial<z.infer<typeof _configSchema>>} Config */
|
|
141
177
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/args.ts
|
|
180
|
+
const complexOptions = [
|
|
181
|
+
"affectedRegexes",
|
|
182
|
+
"collapseHeadings",
|
|
183
|
+
"headings",
|
|
184
|
+
"templates"
|
|
148
185
|
];
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
+
}
|
|
164
205
|
};
|
|
165
206
|
async function parseArgs() {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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;
|
|
170
211
|
}
|
|
171
212
|
function zodToYargs() {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
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);
|
|
191
231
|
}
|
|
192
232
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var error = (0, import_debug2.default)("autoreadme:error");
|
|
199
|
-
var info = (0, import_debug2.default)("autoreadme:info");
|
|
200
|
-
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");
|
|
201
238
|
function ERROR(...rest) {
|
|
202
|
-
|
|
203
|
-
|
|
239
|
+
const [first, ...remaining] = rest;
|
|
240
|
+
error(`${first} %O`, ...remaining);
|
|
204
241
|
}
|
|
205
242
|
function INFO(...rest) {
|
|
206
|
-
|
|
207
|
-
|
|
243
|
+
const [first, ...remaining] = rest;
|
|
244
|
+
info(`${first} %O`, ...remaining);
|
|
208
245
|
}
|
|
209
246
|
function WARN(...rest) {
|
|
210
|
-
|
|
211
|
-
|
|
247
|
+
const [first, ...remaining] = rest;
|
|
248
|
+
warn(`${first} %O`, ...remaining);
|
|
212
249
|
}
|
|
213
250
|
|
|
214
|
-
|
|
215
|
-
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/comment.ts
|
|
253
|
+
const SEPARATOR = "-";
|
|
216
254
|
function loadAstComments(root) {
|
|
217
|
-
|
|
255
|
+
return root.children.map((child) => child.type === "html" && getComment(child)).filter((f) => f !== false);
|
|
218
256
|
}
|
|
219
257
|
function parseComment(comment) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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;
|
|
234
278
|
}
|
|
235
|
-
|
|
236
|
-
|
|
279
|
+
const startComment = "<!--";
|
|
280
|
+
const endComment = "-->";
|
|
237
281
|
function trimComment(comment) {
|
|
238
|
-
|
|
282
|
+
return comment.replace(startComment, "").replace(/start|end/, "").replace(endComment, "").trim();
|
|
239
283
|
}
|
|
240
284
|
function getComment(comment) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
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);
|
|
245
288
|
}
|
|
246
289
|
function isComment(comment) {
|
|
247
|
-
|
|
290
|
+
return comment.startsWith(startComment) && comment.endsWith(endComment);
|
|
248
291
|
}
|
|
249
292
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return configSchema.parse(
|
|
273
|
-
(0, import_deepmerge.default)(search?.config || {}, args2, {
|
|
274
|
-
arrayMerge: (_, sourceArray) => sourceArray
|
|
275
|
-
})
|
|
276
|
-
);
|
|
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 }));
|
|
277
315
|
}
|
|
278
316
|
function loadToml(_filepath, content) {
|
|
279
|
-
|
|
317
|
+
return __iarna_toml.default.parse(content);
|
|
280
318
|
}
|
|
281
319
|
function getSearchPlaces() {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
+
];
|
|
292
330
|
}
|
|
293
331
|
function removeFalsy(obj) {
|
|
294
|
-
|
|
295
|
-
Object.entries(obj).map(([k, v]) => !v ? false : [k, v]).filter((e) => Boolean(e))
|
|
296
|
-
);
|
|
332
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => !v ? false : [k, v]).filter((e) => Boolean(e)));
|
|
297
333
|
}
|
|
298
334
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
var cp = __toESM(require("child_process"), 1);
|
|
311
|
-
var fs = __toESM(require("fs"), 1);
|
|
312
|
-
var fsp = __toESM(require("fs/promises"), 1);
|
|
313
|
-
var path = __toESM(require("path"), 1);
|
|
314
|
-
var sh = String.raw;
|
|
315
|
-
var opts = { encoding: "utf8" };
|
|
316
|
-
var ignore = ["**/node_modules/**"];
|
|
317
|
-
var matches = [
|
|
318
|
-
/.*README\.md$/gi,
|
|
319
|
-
/.*Cargo\.toml$/gi,
|
|
320
|
-
/.*action\.ya?ml$/gi,
|
|
321
|
-
/.*package\.json$/gi,
|
|
322
|
-
/.*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
|
|
323
346
|
];
|
|
324
347
|
async function fileExists(file) {
|
|
325
|
-
|
|
348
|
+
return await node_fs_promises.access(file).then(() => true).catch(() => false);
|
|
326
349
|
}
|
|
327
350
|
function findAffectedMarkdowns(root, config) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const md = eligible.map((e) => findNearestReadme(root, path.resolve(e)));
|
|
341
|
-
const rootMd = path.join(root, "README.md");
|
|
342
|
-
const dedupe = [...new Set(md), rootMd].filter(
|
|
343
|
-
(s) => Boolean(s)
|
|
344
|
-
);
|
|
345
|
-
INFO("Found the following readmes", dedupe);
|
|
346
|
-
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;
|
|
347
363
|
}
|
|
348
364
|
function findNearestReadme(gitRoot, inputFile, maxRotations = 15) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
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;
|
|
361
375
|
}
|
|
362
376
|
function getGitRoot() {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
INFO("found git root at location: ", root);
|
|
368
|
-
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;
|
|
369
381
|
}
|
|
370
382
|
async function getMarkdownPaths(cwd, config) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
383
|
+
return (await (0, fast_glob.default)(`**/${config?.onlyReadmes ? "README" : "*"}.md`, {
|
|
384
|
+
cwd,
|
|
385
|
+
ignore
|
|
386
|
+
})).map((readme) => node_path.resolve(cwd, readme));
|
|
374
387
|
}
|
|
375
388
|
async function getPrettierPaths(paths) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const symlink = await fsp.readlink(file);
|
|
382
|
-
return path.join(path.dirname(file), symlink);
|
|
383
|
-
})
|
|
384
|
-
);
|
|
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
|
+
}));
|
|
385
394
|
}
|
|
386
395
|
|
|
387
|
-
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/data.ts
|
|
388
398
|
function createFindParameter(parameterList) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
399
|
+
return function(parameterName) {
|
|
400
|
+
return parameterList?.find((p) => p.startsWith(parameterName))?.replace(parameterName + "=", "")?.replace(/"/gi, "")?.replace(/_/gi, " ");
|
|
401
|
+
};
|
|
392
402
|
}
|
|
393
403
|
async function loadActionData(actions, file, root) {
|
|
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
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
body,
|
|
452
|
-
parameters: action.parameters
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
default:
|
|
456
|
-
throw new Error("feature not yet implemented");
|
|
457
|
-
}
|
|
458
|
-
})
|
|
459
|
-
);
|
|
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
|
+
}));
|
|
460
461
|
}
|
|
461
462
|
async function loadActionYaml(baseDir) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
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);
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
var import_remark = require("remark");
|
|
477
|
-
var import_remark_code_import = __toESM(require("remark-code-import"), 1);
|
|
478
|
-
var import_remark_collapse = __toESM(require("remark-collapse"), 1);
|
|
479
|
-
var import_remark_toc = __toESM(require("remark-toc"), 1);
|
|
480
|
-
var import_remark_usage = __toESM(require("remark-usage"), 1);
|
|
481
|
-
var import_vfile = require("vfile");
|
|
482
|
-
|
|
483
|
-
// src/plugin.ts
|
|
484
|
-
var import_handlebars = __toESM(require("handlebars"), 1);
|
|
485
|
-
var import_markdown_table = require("markdown-table");
|
|
486
|
-
var import_mdast_util_from_markdown = require("mdast-util-from-markdown");
|
|
487
|
-
var import_mdast_zone = require("mdast-zone");
|
|
488
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/plugin.ts
|
|
489
476
|
function createHeading(headings, disableEmojis = false, emojis = defaultTemplates.emojis) {
|
|
490
|
-
|
|
491
|
-
(h) => `${disableEmojis ? "" : emojis[h] + " "}${h?.at(0)?.toUpperCase() + h?.slice(1)}`
|
|
492
|
-
);
|
|
477
|
+
return headings.map((h) => `${disableEmojis ? "" : emojis[h] + " "}${h?.at(0)?.toUpperCase() + h?.slice(1)}`);
|
|
493
478
|
}
|
|
494
479
|
function wrapRequired(required, input) {
|
|
495
|
-
|
|
496
|
-
|
|
480
|
+
if (!required) return input;
|
|
481
|
+
return `<b>*${input}</b>`;
|
|
497
482
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
` + Object.entries(inputs).sort((a) => a[1].required ? -1 : 1).map(([key,
|
|
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
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
return `${isDev ? "\u2328\uFE0F" : "\u{1F465}"}`;
|
|
608
|
-
}
|
|
609
|
-
if (key === "name") {
|
|
610
|
-
return `[${name}](${url})`;
|
|
611
|
-
}
|
|
612
|
-
if (key === "version") {
|
|
613
|
-
if (["workspace", "catalog", "*"].some(
|
|
614
|
-
(type) => version.includes(type)
|
|
615
|
-
)) {
|
|
616
|
-
return `\`${version}\``;
|
|
617
|
-
}
|
|
618
|
-
return ` })})`;
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
const { dependencies = {}, devDependencies = {} } = first?.pkgJson || {};
|
|
624
|
-
const table = (0, import_markdown_table.markdownTable)([
|
|
625
|
-
createHeading(
|
|
626
|
-
headings,
|
|
627
|
-
config.disableEmojis,
|
|
628
|
-
config.templates?.emojis
|
|
629
|
-
),
|
|
630
|
-
...Object.entries(devDependencies).map(mapDependencies(true)),
|
|
631
|
-
...Object.entries(dependencies).map(mapDependencies(false))
|
|
632
|
-
]);
|
|
633
|
-
const heading = `### ${config.disableEmojis ? "" : "\u{1F4E6}"} packages`;
|
|
634
|
-
const body = [heading, "", table].join("\n");
|
|
635
|
-
const tableAst = (0, import_mdast_util_from_markdown.fromMarkdown)(body);
|
|
636
|
-
return [start, tableAst, end];
|
|
637
|
-
});
|
|
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
|
+
});
|
|
638
592
|
};
|
|
639
593
|
function loadTemplates(templates) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
})
|
|
646
|
-
);
|
|
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
|
+
}));
|
|
647
599
|
}
|
|
648
600
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
const vfile = new import_vfile.VFile({ path: path4.resolve(filepath), value: file });
|
|
687
|
-
const markdown = await pipeline.process(vfile);
|
|
688
|
-
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();
|
|
689
638
|
}
|
|
690
639
|
|
|
691
|
-
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/index.ts
|
|
692
642
|
async function run() {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
const prettierPaths = await getPrettierPaths(paths);
|
|
731
|
-
cp2.execFileSync("prettier", ["--write", ...prettierPaths], opts2);
|
|
732
|
-
}
|
|
733
|
-
if (isAffected) {
|
|
734
|
-
INFO("adding affected files to git stage");
|
|
735
|
-
cp2.execFileSync("git", ["add", ...paths], opts2);
|
|
736
|
-
}
|
|
737
|
-
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();
|
|
738
680
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
});
|
|
681
|
+
|
|
682
|
+
//#endregion
|
|
683
|
+
exports.run = run;
|
|
743
684
|
//# sourceMappingURL=index.cjs.map
|