forked from solidjs-community/solid-primitives
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-readme.ts
93 lines (76 loc) · 3.56 KB
/
update-readme.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { readFileSync, writeFileSync } from "fs";
import path from "path";
// @ts-expect-error ts-missing-module
import tablemark from "json-to-markdown-table";
import * as utils from "./utils/index.js";
type PackageData = {
Name: string;
Stage: string | number;
Size: string;
NPM: string;
Primitives: string;
};
// eslint-disable-next-line no-console
console.log("updateReadme", "Updating README documentation");
const githubURL = "https://github.com/solidjs-community/solid-primitives/tree/main/packages/";
const sizeShield = "https://img.shields.io/bundlephobia/minzip/";
const bundlephobiaURL = "https://bundlephobia.com/package/";
const npmShield = "https://img.shields.io/npm/v/";
const npmURL = "https://www.npmjs.com/package/";
const stageShieldBaseURL =
"https://img.shields.io/endpoint?style=for-the-badge&label=&url=https%3A%2F%2Fraw.githubusercontent.com%2Fsolidjs-community%2Fsolid-primitives%2Fmain%2Fassets%2Fbadges%2Fstage-"; // add "<stage>.json" after
const stageShieldLink =
"https://github.com/solidjs-community/solid-primitives/blob/main/CONTRIBUTING.md#contribution-process";
const categories: Record<string, PackageData[]> = {};
const rootDependencies: string[] = [
`@solid-primitives/utils`, // utils are not included in the modulesData
];
(async () => {
const modulesData = await utils.getModulesData();
for (const { name, category, primitives, stage, workspace_deps } of modulesData) {
const packageName = `@solid-primitives/${name}`;
if (workspace_deps.length === 0) {
rootDependencies.push(packageName);
}
const data = {} as PackageData;
data.Name = `[${name}](${githubURL}${name}#readme)`;
// Detect the stage and build size/version only if needed
if (data.Stage == "X" || data.Stage == 0) {
data.Size = "";
data.NPM = "";
} else {
data.Size = `[](${bundlephobiaURL}${packageName})`;
data.NPM = `[](${npmURL}${packageName})`;
}
data.Stage = `[](${stageShieldLink})`;
data.Primitives = primitives
.map(prim => `[${prim}](${githubURL}${name}#${prim.replace(/ /g, "-").toLowerCase()})`)
.join("<br />");
// Merge the package into the correct category
const cat = categories[category];
categories[category] = cat ? [...cat, data] : [data];
}
const pathToREADME = path.join(utils.ROOT_DIR, "README.md");
let readme = readFileSync(pathToREADME).toString();
// Update Primitives Table
const table = Object.entries(categories).reduce((md, [category, items]) => {
// Some MD jousting to get the table to render nicely
// with consistent columns
md += `|<h4>*${category}*</h4>|\n`;
md += tablemark(items, ["Name", "Stage", "Primitives", "Size", "NPM"])
.replace("|Name|Stage|Primitives|Size|NPM|\n", "")
.replace("|----|----|----|----|----|\n", "");
return md;
}, "|Name|Stage|Primitives|Size|NPM|\n|----|----|----|----|----|\n");
readme = utils.insertTextBetweenComments(readme, table, "INSERT-PRIMITIVES-TABLE");
// Update Combined Downloads Badge
const combinedDownloadsBadge = `[})](https://dash.deno.com/playground/combined-npm-downloads)`;
readme = utils.insertTextBetweenComments(
readme,
combinedDownloadsBadge,
"INSERT-NPM-DOWNLOADS-BADGE",
);
writeFileSync(pathToREADME, readme);
})();