-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.ts
More file actions
103 lines (82 loc) · 3.94 KB
/
build.ts
File metadata and controls
103 lines (82 loc) · 3.94 KB
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/std@0.185.0/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}\` | [](https://pypi.org/project/${repo}/) |
| Node.js | \`npm install ${repo}\` | [](https://www.npmjs.com/package/${repo}) |
| Deno | [\`deno.land/x/${repoSnake}\`](https://deno.land/x/${repoSnake}) | [](https://deno.land/x/${repoSnake}) |${
no_datasette
? ``
: `\n| [Datasette](https://datasette.io/) | \`datasette install datasette-${repo}\` | [](https://pypi.org/project/datasette-${repo}) |`
}${
no_sqlite_utils
? ``
: `\n| [sqlite-utils](https://sqlite-utils.datasette.io/) | \`sqlite-utils install sqlite-utils-${repo}\` | [](https://pypi.org/project/sqlite-utils-${repo}) |`
}
| Ruby | \`gem install ${repo}\` |  |
| Github Release | | 
`;
}
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();