-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathto_table.ts
72 lines (62 loc) · 2.24 KB
/
to_table.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
import unstableApis from "./unstable_apis.json" with { type: "json" };
import unstablePackages from "./unstable_packages.json" with { type: "json" };
import { formatDate } from "./utils.ts";
import { sortBy } from "jsr:@std/collections";
import toAge from "npm:date-age";
const dateAge = new toAge.Age();
const age = (d: Date) => dateAge.dobToAge(d);
const now = new Date();
function unstablePackageTable() {
const lines = [];
const packages = sortBy(unstablePackages, (pkg) => new Date(pkg.startedAt));
lines.push(`### Unstable packages
| No | Package | Current version | Started at | Age at<br/>${formatDate(now)} |
| -- | ------- | --------------- | ---------- | ------------------------- |`);
let i = 0;
for (const pkg of packages) {
i++;
const { name } = pkg;
const pkgName = `[${name}](https://jsr.io/${name})`;
const d = new Date(pkg.startedAt);
const date = formatDate(d);
lines.push(
`| ${i} | ${pkgName} | ${pkg.version} | ${date} | ${age(d)} |`,
);
}
return lines.join("\n");
}
function unstableApiTable() {
const lines = [];
const apis = sortBy(unstableApis, (api) => new Date(api.startedAt));
lines.push(`### Unstable APIs
| No | Package | Path | Started at | Age at<br/>${formatDate(now)} |
| -- | ------- | ----- | ---------- | ------------------------- |`);
let i = 0;
for (const api of apis) {
i++;
const name = api.package;
const specifier = api.specifier.split("/");
const path = specifier.pop();
const pkg = specifier.join("/");
const pkgUrl = pkg.replace(name + "/", name + "/doc/");
const pkgLink = `[${pkg}](https://jsr.io/${pkgUrl})`;
const pathUrl = api.specifier.replace(name, name + "/doc");
const pathLink = `[${path}](https://jsr.io/${pathUrl})`;
const d = new Date(api.startedAt);
const date = formatDate(d);
lines.push(`| ${i} | ${pkgLink} | ${pathLink} | ${date} | ${age(d)} |`);
}
return lines.join("\n");
}
Deno.writeTextFileSync(
"README.md",
Deno.readTextFileSync("README.md").replace(
/<!-- Tables Start -->[\s\S]*<!-- Tables End -->/,
`<!-- Tables Start -->
${unstablePackageTable()}
${unstableApiTable()}
<!-- Tables End -->`,
),
);
await new Deno.Command(Deno.execPath(), { args: ["fmt", "README.md"] })
.output();