-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.ts
103 lines (82 loc) · 3.94 KB
/
build.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
94
95
96
97
98
99
100
101
102
103
import { parse } from "https://deno.land/[email protected]/yaml/mod.ts";
interface Document {
header: string;
extensions: Extension[];
footer: string;
}
interface Extension {
repo: string;
language: string;
platforms: string[];
no_datasette?: boolean;
no_sqlite_utils?: boolean;
short: string;
long: string;
}
function printExtensions(extensions: Extension[]): string {
return `
${extensions
.map(
(extension) => `
### [\`${extension.repo}\`](https://github.com/asg017/${extension.repo})
${extension.long}
${printExtensionDistribution(extension)}
${printExtensionPlatforms(extension)}
`
)
.join("\n\n")}
`;
}
function printExtensionDistribution({
repo,
no_datasette,
no_sqlite_utils,
}: Extension): string {
const repoSnake = repo.replaceAll("-", "_");
return `
| Language/Platform | Install | |
| ----------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Python | \`pip install ${repo}\` | [![PyPI](https://img.shields.io/pypi/v/${repo}.svg?color=blue&logo=python&logoColor=white)](https://pypi.org/project/${repo}/) |
| Node.js | \`npm install ${repo}\` | [![npm](https://img.shields.io/npm/v/${repo}.svg?color=green&logo=nodedotjs&logoColor=white)](https://www.npmjs.com/package/${repo}) |
| Deno | [\`deno.land/x/${repoSnake}\`](https://deno.land/x/${repoSnake}) | [![deno.land/x release](https://img.shields.io/github/v/release/asg017/${repo}?color=fef8d2&include_prereleases&label=deno.land%2Fx&logo=deno)](https://deno.land/x/${repoSnake}) |${
no_datasette
? ``
: `\n| [Datasette](https://datasette.io/) | \`datasette install datasette-${repo}\` | [![PyPI](https://img.shields.io/pypi/v/datasette-${repo}.svg?color=B6B6D9&label=Datasette+plugin&logoColor=white&logo=python)](https://pypi.org/project/datasette-${repo}) |`
}${
no_sqlite_utils
? ``
: `\n| [sqlite-utils](https://sqlite-utils.datasette.io/) | \`sqlite-utils install sqlite-utils-${repo}\` | [![PyPI](https://img.shields.io/pypi/v/sqlite-utils-${repo}.svg?color=B6B6D9&label=sqlite-utils+plugin&logoColor=white&logo=python)](https://pypi.org/project/sqlite-utils-${repo}) |`
}
| Ruby | \`gem install ${repo}\` | ![Gem](https://img.shields.io/gem/v/${repo}?color=red&logo=rubygems&logoColor=white) |
| Github Release | | ![GitHub tag (latest SemVer pre-release)](https://img.shields.io/github/v/tag/asg017/${repo}?color=lightgrey&include_prereleases&label=Github+release&logo=github)
`;
}
function printExtensionPlatforms({ platforms }: Extension) {
return platforms
.map((p) => {
const [os, cpu] = p.split("-");
let label;
if (os === "macos" && cpu === "x86_64") label = "MacOS x86_64";
else if (os === "macos" && cpu === "aarch64")
label = "MacOS M1 and M2 chips";
else {
label = `${os[0].toUpperCase()}${os.substring(1)} ${cpu}`;
}
return `- \`${p}\` (${label})`;
})
.join("\n");
}
function main() {
const source = Deno.readTextFileSync("data.yaml");
const document: Document = parse(source) as Document;
Deno.writeTextFileSync(
"README.md",
`
${document.header}
## Extensions
${printExtensions(document.extensions)}
${document.footer}
`
);
}
main();