-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-readme.mjs
65 lines (53 loc) · 1.57 KB
/
generate-readme.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
const HEADER_MD = `
# ProseMirror Extras
Collection of ProseMirror plugins and utilities
`;
/**
* Extracts the package details from the package.json file.
*
* @param {string} packageName - The name of the package.
* @returns {{title: string, description: string, relativePath: string}} The package details.
*/
function extractPackageDetails(packageName) {
const packageJsonPath = join(
process.cwd(),
"packages",
packageName,
"package.json"
);
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
return {
title: packageJson.name,
description: packageJson?.description ?? "",
relativePath: `/packages/${packageName}`,
};
}
function getAllPackageDetails() {
const packages = readdirSync(join(process.cwd(), "packages"));
return packages
.map(extractPackageDetails)
.filter(Boolean)
.map(constructPackageDetails)
.join("\n");
}
/**
* Constructs the package details for the README.md file.
*
* @param {{title: string, description: string, relativePath: string}} packageDetails - The package details.
* @returns {string} The package details.
*/
function constructPackageDetails(packageDetails) {
return `
- [${packageDetails.title}](${packageDetails.relativePath})
> ${packageDetails.description}
`;
}
const packageDetails = getAllPackageDetails();
const BODY_MD = `
## Packages
${packageDetails}
`;
const README_MD = `${HEADER_MD}\n\n${BODY_MD}`;
writeFileSync(join(process.cwd(), "README.md"), README_MD);