2023-06-16 02:23:05 +02:00
|
|
|
import Ajv from "npm:ajv@8.8.2";
|
|
|
|
import addFormats from "npm:ajv-formats@2.1.1";
|
|
|
|
import { load as yamlLoad } from "https://deno.land/x/js_yaml_port@3.14.0/js-yaml.js";
|
|
|
|
import { emptyDir } from "https://deno.land/std@0.173.0/fs/mod.ts";
|
|
|
|
|
2023-06-16 02:31:54 +02:00
|
|
|
const types = ["summits", "meetups"];
|
2023-06-16 02:23:05 +02:00
|
|
|
|
|
|
|
async function _loadYaml(fn) {
|
|
|
|
return yamlLoad(await Deno.readTextFile(fn));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function test() {
|
|
|
|
const ajv = new Ajv({ strict: false });
|
|
|
|
addFormats(ajv);
|
|
|
|
const schema = await _loadYaml("./schema.yaml");
|
|
|
|
const validator = ajv.compile(schema);
|
2023-06-16 02:31:54 +02:00
|
|
|
|
2023-06-16 02:23:05 +02:00
|
|
|
for (const type of types) {
|
|
|
|
Deno.test(`Check schema: ${type}`, async () => {
|
2023-06-16 02:31:54 +02:00
|
|
|
const list = await _loadYaml(`./events/${type}.yaml`);
|
|
|
|
if (!validator(list)) {
|
|
|
|
throw validator.errors;
|
|
|
|
}
|
|
|
|
});
|
2023-06-16 02:23:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function build() {
|
2023-06-16 02:31:54 +02:00
|
|
|
const output = {};
|
|
|
|
for (const type of types) {
|
|
|
|
const list = await _loadYaml(`./events/${type}.yaml`);
|
|
|
|
output[type] = list;
|
|
|
|
}
|
|
|
|
await emptyDir("./dist");
|
|
|
|
const fn = "./dist/index.json";
|
|
|
|
await Deno.writeTextFile(fn, JSON.stringify(output, null, 2));
|
|
|
|
console.log(`File saved: `);
|
2023-06-16 02:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (Deno.args[0] || "test") {
|
|
|
|
case "test":
|
|
|
|
await test();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "build":
|
|
|
|
await build();
|
|
|
|
break;
|
|
|
|
}
|