This commit is contained in:
tree🌴 2024-01-25 20:45:28 +01:00
parent be3825b5a1
commit 0e83c3897f
7 changed files with 64 additions and 29 deletions

View file

@ -1,4 +1,4 @@
all: build
all: test build
cache:
deno cache utils/build.js

View file

@ -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:

View file

@ -4,3 +4,7 @@ core-team:
- name: Mykola
- name: PG
- name: Coinmandeer
projects:
$load: projects
events:
$load: events

View file

@ -0,0 +1 @@
name: Pagency

View file

@ -4,3 +4,5 @@ const engine = new Engine();
await engine.init();
await engine.build();
console.log('Done')

View file

@ -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]);
}
}*/
}
}

View file

@ -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;