From 0e83c3897f31c223ccf24f74416dd5bbac95e9dd Mon Sep 17 00:00:00 2001 From: tree Date: Thu, 25 Jan 2024 20:45:28 +0100 Subject: [PATCH] refactor --- Makefile | 2 +- data/events.yaml => src/events/index.yaml | 26 ++++------- {data => src}/index.yaml | 6 ++- src/projects/pagency/index.yaml | 1 + utils/build.js | 2 + utils/engine.js | 53 +++++++++++++++++++---- utils/test.js | 3 ++ 7 files changed, 64 insertions(+), 29 deletions(-) rename data/events.yaml => src/events/index.yaml (93%) rename {data => src}/index.yaml (51%) create mode 100644 src/projects/pagency/index.yaml diff --git a/Makefile b/Makefile index 6f69019..89cde84 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: build +all: test build cache: deno cache utils/build.js diff --git a/data/events.yaml b/src/events/index.yaml similarity index 93% rename from data/events.yaml rename to src/events/index.yaml index 4b65bbf..a796131 100644 --- a/data/events.yaml +++ b/src/events/index.yaml @@ -41,25 +41,13 @@ links: web: https://lu.ma/w3pm-prg1 -- id: w3pm-bcn1 +- id: w3pm-ath1 type: meetup date: "2024/Q1" - city: Barcelona - country: es + city: Athens + country: gr coincidence: "" - lead: Tree - helpers: - - Mykola - optional: true - slots: 3 - -- id: w3pm-itxx - type: meetup - date: "2024/Q1" - city: Italy (TBD) - country: it - coincidence: "" - lead: PG + lead: Mykola optional: true slots: 3 @@ -125,9 +113,10 @@ - id: w3pm-ber1 type: meetup - date: "2024-05-25" + date: "2024-05-22" city: Berlin country: de + place: "[c-base](https://c-base.org/)" # ETHBerlin 4 - May 24-26, 2024 coincidence: "ETHBerlin" lead: Tree @@ -137,9 +126,10 @@ - id: w3ps3 type: summit - date: "2024-06-04" + date: "2024-05-30" city: Prague country: cz + # ETHPrague 2024 - May 31-June 2 2024 coincidence: "ETHPrague" lead: Tree helpers: diff --git a/data/index.yaml b/src/index.yaml similarity index 51% rename from data/index.yaml rename to src/index.yaml index 59a2bea..7059ff6 100644 --- a/data/index.yaml +++ b/src/index.yaml @@ -3,4 +3,8 @@ core-team: - name: Tree - name: Mykola - name: PG - - name: Coinmandeer \ No newline at end of file + - name: Coinmandeer +projects: + $load: projects +events: + $load: events \ No newline at end of file diff --git a/src/projects/pagency/index.yaml b/src/projects/pagency/index.yaml new file mode 100644 index 0000000..7586ffc --- /dev/null +++ b/src/projects/pagency/index.yaml @@ -0,0 +1 @@ +name: Pagency \ No newline at end of file diff --git a/utils/build.js b/utils/build.js index b1c9ea0..ca14d7a 100644 --- a/utils/build.js +++ b/utils/build.js @@ -4,3 +4,5 @@ const engine = new Engine(); await engine.init(); await engine.build(); + +console.log('Done') \ No newline at end of file diff --git a/utils/engine.js b/utils/engine.js index ef8b389..7324228 100644 --- a/utils/engine.js +++ b/utils/engine.js @@ -1,8 +1,9 @@ import { join } from "https://deno.land/std@0.208.0/path/mod.ts"; import { emptyDir } from "https://deno.land/std@0.196.0/fs/empty_dir.ts"; import { parse, stringify } from "npm:yaml"; +import { exists } from "https://deno.land/std@0.213.0/fs/exists.ts"; -const SRC_DIR = "./data"; +const SRC_DIR = "./src"; const DEST_DIR = "./dist"; const SCHEMA_DIR = "./schema"; @@ -19,26 +20,60 @@ export class Engine { const [fn, _] = dirEntry.name.split("."); this.schemas[fn] = await readYamlFile(join(SCHEMA_DIR, dirEntry.name)); } - // load data + // load this.index = await readYamlFile(join(SRC_DIR, "index.yaml")); - for await (const dirEntry of Deno.readDir(SRC_DIR)) { + this.rendered = await this.render(this.index); + + } + + async loadDir(src) { + const out = {} + const dir = join(SRC_DIR, src) + console.log(`reading dir=${dir}`) + + if (await exists(join(dir, "index.yaml"))) { + const out = readYamlFile(join(dir, "index.yaml")); + return out + } + + for await (const dirEntry of Deno.readDir(dir)) { const [fn, ext] = dirEntry.name.split("."); + + if (!ext) { + out[fn] = await this.loadDir(join(src, fn)) + continue; + } if (ext === "yaml" && fn !== "index") { - this.db[fn] = await readYamlFile(join(SRC_DIR, dirEntry.name)); + out[fn] = await readYamlFile(join(dir, dirEntry.name)); } } + return out + } + + async render(src) { + const out = {} + for (const key of Object.keys(src)) { + const val = src[key]; + if (typeof val === "object" && val.$load) { + out[key] = await this.loadDir(val.$load); + continue; + } + + out[key] = val + } + return out } async build() { await emptyDir(DEST_DIR); - await writeJSONFile(join(DEST_DIR, "index.json"), this.index); + //await writeJSONFile(join(DEST_DIR, "index.json"), this.index); await writeJSONFile( - join(DEST_DIR, "bundle.json"), - Object.assign({}, this.index, this.db), + join(DEST_DIR, "index.json"), + Object.assign({}, this.rendered), ); - for (const col of Object.keys(this.db)) { + /*for (const col of Object.keys(this.db)) { await writeJSONFile(join(DEST_DIR, `${col}.json`), this.db[col]); - } + }*/ } } diff --git a/utils/test.js b/utils/test.js index ded3004..dd43f26 100644 --- a/utils/test.js +++ b/utils/test.js @@ -11,6 +11,9 @@ addFormats(ajv); function checkCollection (name, schema, data) { Deno.test(name, () => { + if (!schema) { + return + } const validator = ajv.compile(schema); if (!validator(data)) { throw validator.errors;