-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
37 lines (31 loc) · 1.26 KB
/
mod.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
import { parse } from "https://deno.land/[email protected]/yaml/mod.ts";
import { join, basename } from "https://deno.land/[email protected]/path/posix.ts";
const SOURCE_DIR = "./src";
const SCHEMA_DIR = "schema";
export const VERSION = "0.0.4";
const $schemaUrl = (revision: string, key = "index"): string =>
`https://event-lists.ethevents.club/${revision}/schema/${key}.json`;
function $schema(revision: string, name = "index"): any {
return parse(Deno.readTextFileSync(join(SOURCE_DIR, revision, SCHEMA_DIR, name + ".yaml")));
}
// collection available revisions
export const revisions: { [key: string]: any } = {};
for (const rd of Deno.readDirSync(SOURCE_DIR)) {
const rev = basename(rd.name);
const current: any = Object.assign({ $id: $schemaUrl(rev, "index") }, $schema(rev));
for (const f of Deno.readDirSync(join(SOURCE_DIR, rev, SCHEMA_DIR))) {
const key = (f.name.match(/^(.*)\.yaml$/) || [])[1];
if (!key) continue;
if (key === "index") {
continue;
}
current["definitions"][key] = Object.assign(
{ $id: $schemaUrl(rev, key) },
$schema(rev, key),
);
}
revisions[rev] = current;
}
const revisionIndex = Object.keys(revisions)
export const revision = revisionIndex[revisionIndex.length-1];
export const schema = revisions[revision];