@stephansama/auto-readme 0.2.7 → 0.2.9
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/cli.mjs +2 -3
- package/config/schema.cjs +16 -19
- package/config/{schema.js → schema.mjs} +13 -16
- package/dist/index.cjs +130 -164
- package/dist/{index.js → index.mjs} +107 -128
- package/package.json +21 -24
- /package/config/{schema.d.ts → schema.d.mts} +0 -0
- /package/dist/{index.d.ts → index.d.mts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -19,65 +20,49 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
20
|
value: mod,
|
|
20
21
|
enumerable: true
|
|
21
22
|
}) : target, mod));
|
|
22
|
-
|
|
23
23
|
//#endregion
|
|
24
24
|
let mdast_util_from_markdown = require("mdast-util-from-markdown");
|
|
25
|
-
mdast_util_from_markdown = __toESM(mdast_util_from_markdown);
|
|
26
25
|
let node_child_process = require("node:child_process");
|
|
27
|
-
node_child_process = __toESM(node_child_process);
|
|
26
|
+
node_child_process = __toESM(node_child_process, 1);
|
|
28
27
|
let node_fs_promises = require("node:fs/promises");
|
|
29
|
-
node_fs_promises = __toESM(node_fs_promises);
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
let debug = require("debug");
|
|
33
|
-
debug = __toESM(debug);
|
|
28
|
+
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
29
|
+
let picospinner = require("picospinner");
|
|
30
|
+
let obug = require("obug");
|
|
34
31
|
let yargs = require("yargs");
|
|
35
|
-
yargs = __toESM(yargs);
|
|
32
|
+
yargs = __toESM(yargs, 1);
|
|
36
33
|
let yargs_helpers = require("yargs/helpers");
|
|
37
|
-
yargs_helpers = __toESM(yargs_helpers);
|
|
38
34
|
let zod = require("zod");
|
|
39
|
-
zod = __toESM(zod);
|
|
35
|
+
zod = __toESM(zod, 1);
|
|
40
36
|
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
37
|
let cosmiconfig = require("cosmiconfig");
|
|
45
|
-
cosmiconfig = __toESM(cosmiconfig);
|
|
46
38
|
let deepmerge = require("deepmerge");
|
|
47
|
-
deepmerge = __toESM(deepmerge);
|
|
48
|
-
let
|
|
49
|
-
|
|
39
|
+
deepmerge = __toESM(deepmerge, 1);
|
|
40
|
+
let smol_toml = require("smol-toml");
|
|
41
|
+
smol_toml = __toESM(smol_toml, 1);
|
|
42
|
+
let _manypkg_get_packages = require("@manypkg/get-packages");
|
|
50
43
|
let node_fs = require("node:fs");
|
|
51
|
-
node_fs = __toESM(node_fs);
|
|
44
|
+
node_fs = __toESM(node_fs, 1);
|
|
52
45
|
let node_path = require("node:path");
|
|
53
|
-
node_path = __toESM(node_path);
|
|
46
|
+
node_path = __toESM(node_path, 1);
|
|
54
47
|
let pkg_types = require("pkg-types");
|
|
55
|
-
pkg_types = __toESM(pkg_types);
|
|
56
48
|
let yaml = require("yaml");
|
|
57
|
-
yaml = __toESM(yaml);
|
|
49
|
+
yaml = __toESM(yaml, 1);
|
|
58
50
|
let zod2md = require("zod2md");
|
|
59
|
-
|
|
60
|
-
let fast_glob = require("fast-glob");
|
|
61
|
-
fast_glob = __toESM(fast_glob);
|
|
51
|
+
let tinyglobby = require("tinyglobby");
|
|
62
52
|
let remark = require("remark");
|
|
63
|
-
remark = __toESM(remark);
|
|
64
53
|
let remark_code_import = require("remark-code-import");
|
|
65
|
-
remark_code_import = __toESM(remark_code_import);
|
|
54
|
+
remark_code_import = __toESM(remark_code_import, 1);
|
|
66
55
|
let remark_collapse = require("remark-collapse");
|
|
67
|
-
remark_collapse = __toESM(remark_collapse);
|
|
56
|
+
remark_collapse = __toESM(remark_collapse, 1);
|
|
68
57
|
let remark_toc = require("remark-toc");
|
|
69
|
-
remark_toc = __toESM(remark_toc);
|
|
58
|
+
remark_toc = __toESM(remark_toc, 1);
|
|
70
59
|
let remark_usage = require("remark-usage");
|
|
71
|
-
remark_usage = __toESM(remark_usage);
|
|
60
|
+
remark_usage = __toESM(remark_usage, 1);
|
|
72
61
|
let vfile = require("vfile");
|
|
73
|
-
vfile = __toESM(vfile);
|
|
74
62
|
let handlebars = require("handlebars");
|
|
75
|
-
handlebars = __toESM(handlebars);
|
|
63
|
+
handlebars = __toESM(handlebars, 1);
|
|
76
64
|
let markdown_table = require("markdown-table");
|
|
77
|
-
markdown_table = __toESM(markdown_table);
|
|
78
65
|
let mdast_zone = require("mdast-zone");
|
|
79
|
-
mdast_zone = __toESM(mdast_zone);
|
|
80
|
-
|
|
81
66
|
//#region src/schema.ts
|
|
82
67
|
const actionsSchema = zod.enum([
|
|
83
68
|
"ACTION",
|
|
@@ -120,8 +105,8 @@ const tableHeadingsSchema = zod.record(actionsSchema, headingsSchema.array().opt
|
|
|
120
105
|
ZOD: []
|
|
121
106
|
}).meta({ description: "Table heading action configuration" });
|
|
122
107
|
const templatesSchema = zod.object({
|
|
123
|
-
downloadImage: zod.string().default("https://img.shields.io/npm/dw/{{name}}?labelColor=211F1F"),
|
|
124
|
-
emojis: zod.record(headingsSchema, zod.string()).default({
|
|
108
|
+
downloadImage: zod.string().trim().default("https://img.shields.io/npm/dw/{{name}}?labelColor=211F1F"),
|
|
109
|
+
emojis: zod.record(headingsSchema, zod.string().trim()).default({
|
|
125
110
|
default: "⚙️",
|
|
126
111
|
description: "📝",
|
|
127
112
|
devDependency: "💻",
|
|
@@ -131,14 +116,14 @@ const templatesSchema = zod.object({
|
|
|
131
116
|
required: "",
|
|
132
117
|
version: ""
|
|
133
118
|
}).meta({ description: "Table heading emojis used when enabled" }),
|
|
134
|
-
registryUrl: zod.string().default("https://www.npmjs.com/package/{{name}}"),
|
|
135
|
-
versionImage: zod.string().default("https://img.shields.io/npm/v/{{uri_name}}?logo=npm&logoColor=red&color=211F1F&labelColor=211F1F")
|
|
119
|
+
registryUrl: zod.string().trim().default("https://www.npmjs.com/package/{{name}}"),
|
|
120
|
+
versionImage: zod.string().trim().default("https://img.shields.io/npm/v/{{uri_name}}?logo=npm&logoColor=red&color=211F1F&labelColor=211F1F")
|
|
136
121
|
});
|
|
137
122
|
const defaultTemplates = templatesSchema.parse({});
|
|
138
123
|
const defaultTableHeadings = tableHeadingsSchema.parse(void 0);
|
|
139
|
-
const
|
|
140
|
-
affectedRegexes: zod.array(zod.string()),
|
|
141
|
-
collapseHeadings: zod.array(zod.string()),
|
|
124
|
+
const configSchema = zod.object({
|
|
125
|
+
affectedRegexes: zod.array(zod.string().trim()),
|
|
126
|
+
collapseHeadings: zod.array(zod.string().trim()),
|
|
142
127
|
defaultLanguage: languageSchema.meta({
|
|
143
128
|
alias: "l",
|
|
144
129
|
description: "Default language to infer projects from"
|
|
@@ -163,27 +148,25 @@ const _configSchema = zod.object({
|
|
|
163
148
|
alias: "p",
|
|
164
149
|
description: "Only show public packages in workspaces"
|
|
165
150
|
}),
|
|
166
|
-
removeScope: zod.string().default("").meta({ description: "Remove common workspace scope" }),
|
|
151
|
+
removeScope: zod.string().trim().default("").meta({ description: "Remove common workspace scope" }),
|
|
167
152
|
templates: templatesSchema.optional().default(defaultTemplates).describe("Handlebars templates used to fuel list and table generation"),
|
|
168
|
-
tocHeading: zod.string().default("Table of contents").meta({ description: "Markdown heading used to generate table of contents" }),
|
|
169
|
-
usageFile: zod.string().default("").meta({ description: "Workspace level usage file" }),
|
|
170
|
-
usageHeading: zod.string().default("Usage").meta({ description: "Markdown heading used to generate usage example" }),
|
|
153
|
+
tocHeading: zod.string().trim().default("Table of contents").meta({ description: "Markdown heading used to generate table of contents" }),
|
|
154
|
+
usageFile: zod.string().trim().default("").meta({ description: "Workspace level usage file" }),
|
|
155
|
+
usageHeading: zod.string().trim().default("Usage").meta({ description: "Markdown heading used to generate usage example" }),
|
|
171
156
|
verbose: zod.boolean().default(false).meta({
|
|
172
157
|
alias: "v",
|
|
173
158
|
description: "whether or not to display verbose logging"
|
|
174
159
|
})
|
|
175
|
-
});
|
|
176
|
-
const configSchema = _configSchema.optional();
|
|
177
|
-
|
|
160
|
+
}).optional();
|
|
178
161
|
//#endregion
|
|
179
|
-
//#region src/
|
|
162
|
+
//#region src/arguments.ts
|
|
180
163
|
const complexOptions = [
|
|
181
164
|
"affectedRegexes",
|
|
182
165
|
"collapseHeadings",
|
|
183
166
|
"headings",
|
|
184
167
|
"templates"
|
|
185
168
|
];
|
|
186
|
-
const
|
|
169
|
+
const arguments_ = {
|
|
187
170
|
...zodToYargs(),
|
|
188
171
|
changes: {
|
|
189
172
|
alias: "g",
|
|
@@ -203,10 +186,10 @@ const args = {
|
|
|
203
186
|
type: "string"
|
|
204
187
|
}
|
|
205
188
|
};
|
|
206
|
-
async function
|
|
207
|
-
const yargsInstance = (0, yargs.default)((0, yargs_helpers.hideBin)(process.argv)).options(
|
|
189
|
+
async function parseArguments() {
|
|
190
|
+
const yargsInstance = (0, yargs.default)((0, yargs_helpers.hideBin)(process.argv)).options(arguments_).help("h").alias("h", "help").epilogue(`--> @stephansama open-source ${(/* @__PURE__ */ new Date()).getFullYear()}`);
|
|
208
191
|
const parsed = await yargsInstance.wrap(yargsInstance.terminalWidth()).parse();
|
|
209
|
-
if (parsed.verbose)
|
|
192
|
+
if (parsed.verbose) (0, obug.enable)("autoreadme*");
|
|
210
193
|
return parsed;
|
|
211
194
|
}
|
|
212
195
|
function zodToYargs() {
|
|
@@ -229,25 +212,12 @@ function zodToYargs() {
|
|
|
229
212
|
});
|
|
230
213
|
return Object.fromEntries(entries);
|
|
231
214
|
}
|
|
232
|
-
|
|
233
215
|
//#endregion
|
|
234
216
|
//#region src/log.ts
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
const [first, ...remaining] = rest;
|
|
240
|
-
error(`${first} %O`, ...remaining);
|
|
241
|
-
}
|
|
242
|
-
function INFO(...rest) {
|
|
243
|
-
const [first, ...remaining] = rest;
|
|
244
|
-
info(`${first} %O`, ...remaining);
|
|
245
|
-
}
|
|
246
|
-
function WARN(...rest) {
|
|
247
|
-
const [first, ...remaining] = rest;
|
|
248
|
-
warn(`${first} %O`, ...remaining);
|
|
249
|
-
}
|
|
250
|
-
|
|
217
|
+
const debug = (0, obug.createDebug)("autoreadme", { useColors: true });
|
|
218
|
+
const ERROR = debug.extend("error");
|
|
219
|
+
const INFO = debug.extend("info");
|
|
220
|
+
const WARN = debug.extend("warn");
|
|
251
221
|
//#endregion
|
|
252
222
|
//#region src/comment.ts
|
|
253
223
|
const SEPARATOR = "-";
|
|
@@ -264,7 +234,7 @@ function parseComment(comment) {
|
|
|
264
234
|
});
|
|
265
235
|
const languageInput = third ? first : void 0;
|
|
266
236
|
const actionInput = third ? second : first;
|
|
267
|
-
const formatInput = third
|
|
237
|
+
const formatInput = third || second;
|
|
268
238
|
const language = languageSchema.parse(languageInput);
|
|
269
239
|
const parsed = {
|
|
270
240
|
action: actionsSchema.parse(actionInput),
|
|
@@ -278,8 +248,9 @@ function parseComment(comment) {
|
|
|
278
248
|
}
|
|
279
249
|
const startComment = "<!--";
|
|
280
250
|
const endComment = "-->";
|
|
251
|
+
const commentRegex = /start|end/;
|
|
281
252
|
function trimComment(comment) {
|
|
282
|
-
return comment.replace(startComment, "").replace(
|
|
253
|
+
return comment.replace(startComment, "").replace(commentRegex, "").replace(endComment, "").trim();
|
|
283
254
|
}
|
|
284
255
|
function getComment(comment) {
|
|
285
256
|
if (!isComment(comment.value)) return false;
|
|
@@ -289,32 +260,31 @@ function getComment(comment) {
|
|
|
289
260
|
function isComment(comment) {
|
|
290
261
|
return comment.startsWith(startComment) && comment.endsWith(endComment);
|
|
291
262
|
}
|
|
292
|
-
|
|
293
263
|
//#endregion
|
|
294
264
|
//#region src/config.ts
|
|
295
265
|
const moduleName = "autoreadme";
|
|
296
266
|
const searchPlaces = getSearchPlaces();
|
|
297
267
|
const loaders = { [".toml"]: loadToml };
|
|
298
|
-
async function loadConfig(
|
|
299
|
-
const
|
|
268
|
+
async function loadConfig(arguments_) {
|
|
269
|
+
const options = {
|
|
300
270
|
loaders,
|
|
301
271
|
searchPlaces
|
|
302
272
|
};
|
|
303
|
-
if (
|
|
304
|
-
const search = await (0, cosmiconfig.cosmiconfig)(moduleName,
|
|
305
|
-
if (
|
|
306
|
-
WARN(`no config file found`, args$1.config ? " at location: " + args$1.config : "");
|
|
307
|
-
INFO("using default configuration");
|
|
308
|
-
} else {
|
|
273
|
+
if (arguments_.config) options.searchPlaces = [arguments_.config];
|
|
274
|
+
const search = await (0, cosmiconfig.cosmiconfig)(moduleName, options).search();
|
|
275
|
+
if (search) {
|
|
309
276
|
INFO("found configuration file at: ", search.filepath);
|
|
310
277
|
INFO("loaded cosmiconfig", search.config);
|
|
278
|
+
} else {
|
|
279
|
+
WARN(`no config file found`, arguments_.config ? " at location: " + arguments_.config : "");
|
|
280
|
+
INFO("using default configuration");
|
|
311
281
|
}
|
|
312
|
-
|
|
313
|
-
INFO("merging config with args",
|
|
314
|
-
return configSchema.parse((0, deepmerge.default)(search?.config || {},
|
|
282
|
+
arguments_ = removeFalsy(arguments_);
|
|
283
|
+
INFO("merging config with args", arguments_);
|
|
284
|
+
return configSchema.parse((0, deepmerge.default)(search?.config || {}, arguments_, { arrayMerge: (_, sourceArray) => sourceArray }));
|
|
315
285
|
}
|
|
316
286
|
function loadToml(_filepath, content) {
|
|
317
|
-
return
|
|
287
|
+
return smol_toml.parse(content);
|
|
318
288
|
}
|
|
319
289
|
function getSearchPlaces() {
|
|
320
290
|
return [
|
|
@@ -328,14 +298,13 @@ function getSearchPlaces() {
|
|
|
328
298
|
`.config/.${moduleName}rc.yml`
|
|
329
299
|
];
|
|
330
300
|
}
|
|
331
|
-
function removeFalsy(
|
|
332
|
-
return Object.fromEntries(Object.entries(
|
|
301
|
+
function removeFalsy(object) {
|
|
302
|
+
return Object.fromEntries(Object.entries(object).map(([k, v]) => v ? [k, v] : false).filter(Boolean));
|
|
333
303
|
}
|
|
334
|
-
|
|
335
304
|
//#endregion
|
|
336
|
-
//#region src/
|
|
305
|
+
//#region src/utilities.ts
|
|
337
306
|
const sh = String.raw;
|
|
338
|
-
const
|
|
307
|
+
const options = { encoding: "utf8" };
|
|
339
308
|
const ignore = ["**/node_modules/**"];
|
|
340
309
|
const matches = [
|
|
341
310
|
/.*README\.md$/gi,
|
|
@@ -348,56 +317,56 @@ async function fileExists(file) {
|
|
|
348
317
|
return await node_fs_promises.access(file).then(() => true).catch(() => false);
|
|
349
318
|
}
|
|
350
319
|
function findAffectedMarkdowns(root, config) {
|
|
351
|
-
const affected = node_child_process.execSync(sh`git diff --cached --name-only --diff-filter=MACT`,
|
|
352
|
-
if (
|
|
320
|
+
const affected = node_child_process.execSync(sh`git diff --cached --name-only --diff-filter=MACT`, options).trim().split("\n").filter((item) => !!item);
|
|
321
|
+
if (affected.length === 0) ERROR("no staged files found");
|
|
353
322
|
if (config.affectedRegexes?.length) INFO("adding the following expressions: ", config.affectedRegexes);
|
|
354
323
|
const allMatches = [...matches, ...config.affectedRegexes?.map((r) => new RegExp(r)) || []];
|
|
355
324
|
INFO("Checking affected files against regexes", affected, allMatches);
|
|
356
325
|
const eligible = affected.filter((a) => allMatches.some((m) => a.match(m)));
|
|
357
326
|
INFO("Found the following eligible affected files", eligible);
|
|
358
|
-
const md = eligible.map((
|
|
359
|
-
|
|
360
|
-
|
|
327
|
+
const md = eligible.map((current) => {
|
|
328
|
+
return findNearestReadme(root, node_path.default.resolve(current));
|
|
329
|
+
});
|
|
330
|
+
const rootMd = node_path.default.join(root, "README.md");
|
|
331
|
+
const dedupe = [...new Set(md), rootMd].filter((item) => !!item);
|
|
361
332
|
INFO("Found the following readmes", dedupe);
|
|
362
333
|
return dedupe;
|
|
363
334
|
}
|
|
364
335
|
function getGitRoot() {
|
|
365
|
-
const root = node_child_process.execSync(sh`git rev-parse --show-toplevel`,
|
|
336
|
+
const root = node_child_process.execSync(sh`git rev-parse --show-toplevel`, options).trim();
|
|
366
337
|
if (!root) throw new Error("must be ran within a git directory.");
|
|
367
338
|
INFO("found git root at location: ", root);
|
|
368
339
|
return root;
|
|
369
340
|
}
|
|
370
341
|
async function getMarkdownPaths(cwd, config) {
|
|
371
|
-
return (await (0,
|
|
342
|
+
return (await (0, tinyglobby.glob)(`**/${config?.onlyReadmes ? "README" : "*"}.md`, {
|
|
372
343
|
cwd,
|
|
373
344
|
ignore
|
|
374
|
-
})).map((readme) => node_path.resolve(cwd, readme));
|
|
345
|
+
})).map((readme) => node_path.default.resolve(cwd, readme));
|
|
375
346
|
}
|
|
376
347
|
async function getPrettierPaths(paths) {
|
|
377
348
|
return await Promise.all(paths.map(async (file) => {
|
|
378
349
|
if (!(await node_fs_promises.lstat(file)).isSymbolicLink()) return file;
|
|
379
350
|
const symlink = await node_fs_promises.readlink(file);
|
|
380
|
-
return node_path.join(node_path.dirname(file), symlink);
|
|
351
|
+
return node_path.default.join(node_path.default.dirname(file), symlink);
|
|
381
352
|
}));
|
|
382
353
|
}
|
|
383
354
|
function findNearestReadme(gitRoot, inputFile, maxRotations = 15) {
|
|
384
|
-
let
|
|
355
|
+
let dirname = node_path.default.dirname(inputFile);
|
|
385
356
|
let rotations = 0;
|
|
386
357
|
while (true) {
|
|
387
|
-
const option = node_path.join(
|
|
358
|
+
const option = node_path.default.join(dirname, "README.md");
|
|
388
359
|
if (node_fs.existsSync(option)) return option;
|
|
389
|
-
const parent = node_path.dirname(
|
|
390
|
-
if (parent ===
|
|
391
|
-
|
|
360
|
+
const parent = node_path.default.dirname(dirname);
|
|
361
|
+
if (parent === dirname || dirname === gitRoot || ++rotations > maxRotations) break;
|
|
362
|
+
dirname = parent;
|
|
392
363
|
}
|
|
393
|
-
return null;
|
|
394
364
|
}
|
|
395
|
-
|
|
396
365
|
//#endregion
|
|
397
366
|
//#region src/data.ts
|
|
398
367
|
function createFindParameter(parameterList) {
|
|
399
368
|
return function(parameterName) {
|
|
400
|
-
return parameterList?.find((p) => p.startsWith(parameterName))?.replace(parameterName + "=", "")?.
|
|
369
|
+
return parameterList?.find((p) => p.startsWith(parameterName))?.replace(parameterName + "=", "")?.replaceAll("\"", "")?.replaceAll("_", " ");
|
|
401
370
|
};
|
|
402
371
|
}
|
|
403
372
|
async function loadActionData(actions, file, root) {
|
|
@@ -406,7 +375,7 @@ async function loadActionData(actions, file, root) {
|
|
|
406
375
|
const find = createFindParameter(action.parameters);
|
|
407
376
|
switch (action.action) {
|
|
408
377
|
case "ACTION": {
|
|
409
|
-
const actionYaml = await loadActionYaml(node_path.dirname(file));
|
|
378
|
+
const actionYaml = await loadActionYaml(node_path.default.dirname(file));
|
|
410
379
|
return {
|
|
411
380
|
action: action.action,
|
|
412
381
|
actionYaml,
|
|
@@ -415,7 +384,7 @@ async function loadActionData(actions, file, root) {
|
|
|
415
384
|
}
|
|
416
385
|
case "PKG": {
|
|
417
386
|
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));
|
|
387
|
+
const pkgJson = await (0, pkg_types.readPackageJSON)(inputPath ? node_path.default.resolve(node_path.default.dirname(file), inputPath) : node_path.default.dirname(file));
|
|
419
388
|
return {
|
|
420
389
|
action: action.action,
|
|
421
390
|
parameters: action.parameters,
|
|
@@ -427,8 +396,8 @@ async function loadActionData(actions, file, root) {
|
|
|
427
396
|
parameters: action.parameters
|
|
428
397
|
};
|
|
429
398
|
case "WORKSPACE": {
|
|
430
|
-
const workspaces = await (0,
|
|
431
|
-
const pnpmPath = node_path.resolve(root, "pnpm-workspace.yaml");
|
|
399
|
+
const workspaces = await (0, _manypkg_get_packages.getPackages)(process.cwd());
|
|
400
|
+
const pnpmPath = node_path.default.resolve(root, "pnpm-workspace.yaml");
|
|
432
401
|
const isPnpm = node_fs.existsSync(pnpmPath);
|
|
433
402
|
return {
|
|
434
403
|
action: action.action,
|
|
@@ -442,11 +411,11 @@ async function loadActionData(actions, file, root) {
|
|
|
442
411
|
if (action.format === "LIST") throw new Error("cannot display zod in list format");
|
|
443
412
|
const inputPath = find("path");
|
|
444
413
|
if (!inputPath) {
|
|
445
|
-
const error
|
|
446
|
-
throw new Error(error
|
|
414
|
+
const error = `no path found for zod table at markdown file ${file}`;
|
|
415
|
+
throw new Error(error);
|
|
447
416
|
}
|
|
448
417
|
const body = await (0, zod2md.zod2md)({
|
|
449
|
-
entry: node_path.resolve(node_path.dirname(file), inputPath),
|
|
418
|
+
entry: node_path.default.resolve(node_path.default.dirname(file), inputPath),
|
|
450
419
|
title: find("title") || "Zod Schema"
|
|
451
420
|
});
|
|
452
421
|
return {
|
|
@@ -459,18 +428,17 @@ async function loadActionData(actions, file, root) {
|
|
|
459
428
|
}
|
|
460
429
|
}));
|
|
461
430
|
}
|
|
462
|
-
async function loadActionYaml(
|
|
463
|
-
const actionYmlPath = node_path.resolve(
|
|
464
|
-
const actionYamlPath = node_path.resolve(
|
|
431
|
+
async function loadActionYaml(baseDirectory) {
|
|
432
|
+
const actionYmlPath = node_path.default.resolve(baseDirectory, "action.yml");
|
|
433
|
+
const actionYamlPath = node_path.default.resolve(baseDirectory, "action.yaml");
|
|
465
434
|
const actualPath = await fileExists(actionYamlPath) && actionYamlPath || await fileExists(actionYmlPath) && actionYmlPath;
|
|
466
435
|
if (!actualPath) {
|
|
467
|
-
const error
|
|
468
|
-
throw new Error(error
|
|
436
|
+
const error = `no yaml file found at locations: ${[actionYmlPath, actionYamlPath].join(",")}`;
|
|
437
|
+
throw new Error(error);
|
|
469
438
|
}
|
|
470
439
|
const actionFile = await node_fs_promises.readFile(actualPath, { encoding: "utf8" });
|
|
471
440
|
return yaml.parse(actionFile);
|
|
472
441
|
}
|
|
473
|
-
|
|
474
442
|
//#endregion
|
|
475
443
|
//#region src/plugin.ts
|
|
476
444
|
function createHeading(headings, disableEmojis = false, emojis = defaultTemplates.emojis) {
|
|
@@ -482,11 +450,11 @@ function wrapRequired(required, input) {
|
|
|
482
450
|
}
|
|
483
451
|
const autoReadmeRemarkPlugin = (config, data) => (tree) => {
|
|
484
452
|
(0, mdast_zone.zone)(tree, /.*ZOD.*/gi, function(start, _, end) {
|
|
485
|
-
const zod
|
|
486
|
-
if (!zod
|
|
453
|
+
const zod = data.find((d) => d?.action === "ZOD");
|
|
454
|
+
if (!zod?.body) throw new Error("unable to load zod body");
|
|
487
455
|
return [
|
|
488
456
|
start,
|
|
489
|
-
(0, mdast_util_from_markdown.fromMarkdown)(zod
|
|
457
|
+
(0, mdast_util_from_markdown.fromMarkdown)(zod.body),
|
|
490
458
|
end
|
|
491
459
|
];
|
|
492
460
|
});
|
|
@@ -498,8 +466,8 @@ const autoReadmeRemarkPlugin = (config, data) => (tree) => {
|
|
|
498
466
|
const heading = `### ${config.disableEmojis ? "" : "🧰"} actions`;
|
|
499
467
|
if (options.format === "LIST") return [
|
|
500
468
|
start,
|
|
501
|
-
(0, mdast_util_from_markdown.fromMarkdown)(`${heading}\n` + Object.entries(inputs).
|
|
502
|
-
return `- ${wrapRequired(value
|
|
469
|
+
(0, mdast_util_from_markdown.fromMarkdown)(`${heading}\n` + Object.entries(inputs).toSorted((a) => a[1].required ? -1 : 1).map(([key, value]) => {
|
|
470
|
+
return `- ${wrapRequired(value.required, key)}: (default: ${value.default})\n\n${value.description}`;
|
|
503
471
|
}).join("\n")),
|
|
504
472
|
end
|
|
505
473
|
];
|
|
@@ -509,7 +477,7 @@ const autoReadmeRemarkPlugin = (config, data) => (tree) => {
|
|
|
509
477
|
(0, mdast_util_from_markdown.fromMarkdown)([
|
|
510
478
|
heading,
|
|
511
479
|
"",
|
|
512
|
-
(0, markdown_table.markdownTable)([createHeading(headings, config.disableEmojis, config.templates?.emojis), ...Object.entries(inputs).map(([k, v]) => headings.map((heading
|
|
480
|
+
(0, markdown_table.markdownTable)([createHeading(headings, config.disableEmojis, config.templates?.emojis), ...Object.entries(inputs).map(([k, v]) => headings.map((heading) => v[heading] || k).map(String))])
|
|
513
481
|
].join("\n")),
|
|
514
482
|
end
|
|
515
483
|
];
|
|
@@ -522,9 +490,9 @@ const autoReadmeRemarkPlugin = (config, data) => (tree) => {
|
|
|
522
490
|
const packages = workspace?.workspaces?.packages || [];
|
|
523
491
|
const headings = config.headings?.WORKSPACE?.length && config.headings?.WORKSPACE || defaultTableHeadings.WORKSPACE;
|
|
524
492
|
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) => {
|
|
493
|
+
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
494
|
const { name } = pkg.packageJson;
|
|
527
|
-
return headings
|
|
495
|
+
return headings?.map((heading) => {
|
|
528
496
|
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
497
|
if (heading === "version") return ` })})`;
|
|
530
498
|
if (heading === "downloads") return `})`;
|
|
@@ -553,13 +521,13 @@ const autoReadmeRemarkPlugin = (config, data) => (tree) => {
|
|
|
553
521
|
(0, mdast_util_from_markdown.fromMarkdown)(""),
|
|
554
522
|
end
|
|
555
523
|
];
|
|
556
|
-
function mapDependencies(
|
|
524
|
+
function mapDependencies(isDevelopment) {
|
|
557
525
|
return function([name, version]) {
|
|
558
526
|
const url = templates.registryUrl({ name });
|
|
559
527
|
return headings.map((key) => {
|
|
560
528
|
if (key === "devDependency") {
|
|
561
|
-
if (config.disableEmojis) return `\`${
|
|
562
|
-
return `${
|
|
529
|
+
if (config.disableEmojis) return `\`${isDevelopment}\``;
|
|
530
|
+
return `${isDevelopment ? "⌨️" : "👥"}`;
|
|
563
531
|
}
|
|
564
532
|
if (key === "name") return `[${name}](${url})`;
|
|
565
533
|
if (key === "version") {
|
|
@@ -597,7 +565,6 @@ function loadTemplates(templates) {
|
|
|
597
565
|
return [key, handlebars.default.compile(value)];
|
|
598
566
|
}));
|
|
599
567
|
}
|
|
600
|
-
|
|
601
568
|
//#endregion
|
|
602
569
|
//#region src/pipeline.ts
|
|
603
570
|
async function parse(file, filepath, root, config, data) {
|
|
@@ -605,10 +572,10 @@ async function parse(file, filepath, root, config, data) {
|
|
|
605
572
|
const usage = data.find((d) => d.action === "USAGE");
|
|
606
573
|
if (usage?.action === "USAGE" || config.enableUsage) {
|
|
607
574
|
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;
|
|
575
|
+
const dirname = node_path.default.dirname(filepath);
|
|
576
|
+
const resolvePath = examplePath && node_path.default.resolve(dirname, examplePath);
|
|
577
|
+
const relativeProjectPath = config.usageFile && node_path.default.relative(root, node_path.default.resolve(dirname, config.usageFile));
|
|
578
|
+
const example = examplePath && resolvePath && node_path.default.relative(root, resolvePath) || relativeProjectPath || void 0;
|
|
612
579
|
if (example && await fileExists(example)) {
|
|
613
580
|
INFO("generating usage section");
|
|
614
581
|
pipeline.use(remark_usage.default, {
|
|
@@ -626,58 +593,57 @@ async function parse(file, filepath, root, config, data) {
|
|
|
626
593
|
pipeline.use(remark_collapse.default, { test: {
|
|
627
594
|
ignoreFinalDefinitions: true,
|
|
628
595
|
test: (value, _) => {
|
|
629
|
-
return headings.some((
|
|
596
|
+
return headings.some((item) => value.trim() === item?.trim());
|
|
630
597
|
}
|
|
631
598
|
} });
|
|
632
599
|
}
|
|
633
600
|
const vfile$1 = new vfile.VFile({
|
|
634
|
-
path: node_path.resolve(filepath),
|
|
601
|
+
path: node_path.default.resolve(filepath),
|
|
635
602
|
value: file
|
|
636
603
|
});
|
|
637
604
|
return (await pipeline.process(vfile$1)).toString();
|
|
638
605
|
}
|
|
639
|
-
|
|
640
606
|
//#endregion
|
|
641
607
|
//#region src/index.ts
|
|
642
608
|
async function run() {
|
|
643
|
-
const
|
|
644
|
-
const config = await loadConfig(
|
|
609
|
+
const arguments_ = await parseArguments();
|
|
610
|
+
const config = await loadConfig(arguments_) || {};
|
|
645
611
|
INFO("Loaded the following configuration:", config);
|
|
646
612
|
const root = getGitRoot();
|
|
647
|
-
const isAffected =
|
|
648
|
-
INFO(`Loading ${
|
|
613
|
+
const isAffected = arguments_.changes && "affected";
|
|
614
|
+
INFO(`Loading ${isAffected ? "affected " : "all "}files`);
|
|
649
615
|
const paths = isAffected ? findAffectedMarkdowns(root, config) : await getMarkdownPaths(root, config);
|
|
650
616
|
INFO("Loaded the following files:", paths.join("\n"));
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
await Promise.all(paths.map(async (path
|
|
655
|
-
const file = await node_fs_promises.readFile(path
|
|
656
|
-
const actions = (()
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (!actions.length) {
|
|
660
|
-
WARN(`no action comments found in`, path$1);
|
|
617
|
+
if (paths.length === 0) return ERROR(`no ${isAffected} readmes found to update`);
|
|
618
|
+
const spinner = !arguments_.verbose && makeSpinner();
|
|
619
|
+
if (spinner) spinner.start();
|
|
620
|
+
await Promise.all(paths.filter((path) => !!path).map(async (path) => {
|
|
621
|
+
const file = await node_fs_promises.readFile(path, { encoding: "utf8" });
|
|
622
|
+
const actions = loadAstComments((0, mdast_util_from_markdown.fromMarkdown)(file));
|
|
623
|
+
if (actions.length === 0) {
|
|
624
|
+
WARN(`no action comments found in`, path);
|
|
661
625
|
if (!config.enableUsage || !config.enableToc) return ERROR("no action or plugins found");
|
|
662
|
-
else INFO("plugins enabled. continuing parsing", path
|
|
626
|
+
else INFO("plugins enabled. continuing parsing", path);
|
|
663
627
|
}
|
|
664
|
-
const data = await loadActionData(actions, path
|
|
628
|
+
const data = await loadActionData(actions, path, root);
|
|
665
629
|
INFO("Loaded comment action data", data);
|
|
666
|
-
const content = await parse(file, path
|
|
667
|
-
await node_fs_promises.writeFile(path
|
|
630
|
+
const content = await parse(file, path, root, config, data);
|
|
631
|
+
await node_fs_promises.writeFile(path, content);
|
|
668
632
|
}));
|
|
669
|
-
const
|
|
633
|
+
const options = { stdio: "inherit" };
|
|
670
634
|
if (config.enablePrettier) {
|
|
671
635
|
INFO("formatting with prettier");
|
|
672
636
|
const prettierPaths = await getPrettierPaths(paths);
|
|
673
|
-
node_child_process.execFileSync("prettier", ["--write", ...prettierPaths],
|
|
637
|
+
node_child_process.execFileSync("prettier", ["--write", ...prettierPaths], options);
|
|
674
638
|
}
|
|
675
639
|
if (isAffected) {
|
|
676
640
|
INFO("adding affected files to git stage");
|
|
677
|
-
node_child_process.execFileSync("git", ["add", ...paths],
|
|
641
|
+
node_child_process.execFileSync("git", ["add", ...paths], options);
|
|
678
642
|
}
|
|
679
643
|
if (spinner) spinner.stop();
|
|
680
644
|
}
|
|
681
|
-
|
|
645
|
+
function makeSpinner() {
|
|
646
|
+
return new picospinner.Spinner("Updating readme...", { colors: { spinner: "red" } });
|
|
647
|
+
}
|
|
682
648
|
//#endregion
|
|
683
|
-
exports.run = run;
|
|
649
|
+
exports.run = run;
|