From 1a9040e0b0c200f735a72968ff5e0de5375ef544 Mon Sep 17 00:00:00 2001 From: tree Date: Fri, 28 Jan 2022 17:07:43 +0100 Subject: [PATCH] Publish schema to gh-pages --- Makefile | 5 ++++- spec/22/index.yaml | 1 + utils/build.js | 6 ------ utils/engine.js | 25 +++++++++++++++++++++---- utils/exec.js | 9 +++++++++ utils/schema/{ => 1}/events.yaml | 0 utils/schema/{ => 1}/faqs.yaml | 0 utils/schema/{ => 1}/index.yaml | 2 ++ utils/schema/{ => 1}/partners.yaml | 0 utils/schema/{ => 1}/projects.yaml | 0 utils/schema/{ => 1}/speakers.yaml | 0 utils/schema/{ => 1}/tracks.yaml | 0 12 files changed, 37 insertions(+), 11 deletions(-) delete mode 100644 utils/build.js create mode 100644 utils/exec.js rename utils/schema/{ => 1}/events.yaml (100%) rename utils/schema/{ => 1}/faqs.yaml (100%) rename utils/schema/{ => 1}/index.yaml (94%) rename utils/schema/{ => 1}/partners.yaml (100%) rename utils/schema/{ => 1}/projects.yaml (100%) rename utils/schema/{ => 1}/speakers.yaml (100%) rename utils/schema/{ => 1}/tracks.yaml (100%) diff --git a/Makefile b/Makefile index 7d562f3..ea0bfa5 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ format: fmt: format build: - deno run --unstable --allow-read --allow-write utils/build.js + deno run --unstable --allow-read --allow-write utils/exec.js build docs-update: deno run --unstable --allow-read --allow-write utils/update-docs.js @@ -52,5 +52,8 @@ twitter-photos: events: deno run --unstable --allow-read utils/events.js +schema: + deno run --unstable --allow-read --allow-write utils/schema.js + server: cd dist && python -m SimpleHTTPServer 8000 diff --git a/spec/22/index.yaml b/spec/22/index.yaml index 395a25b..b17685a 100644 --- a/spec/22/index.yaml +++ b/spec/22/index.yaml @@ -15,6 +15,7 @@ links: substack: https://utxoprague.substack.com/ instagram: https://www.instagram.com/utxoprague/ youtube: https://www.youtube.com/channel/UCXLBCW1pstQPQf-4zRESepA +schemaVersion: 1 specDef: - type: speakers - type: tracks diff --git a/utils/build.js b/utils/build.js deleted file mode 100644 index 13e0160..0000000 --- a/utils/build.js +++ /dev/null @@ -1,6 +0,0 @@ -import { UTXOEngine } from "./engine.js"; - -const utxo = new UTXOEngine({ srcDir: "./spec" }); -await utxo.init(); - -await utxo.build("./dist"); diff --git a/utils/engine.js b/utils/engine.js index 3e3fc3e..76844e7 100644 --- a/utils/engine.js +++ b/utils/engine.js @@ -16,6 +16,7 @@ const banner = ` export class UTXOEngine { constructor(options = {}) { this.options = options; + this.defaultSchemaVersion = "1"; this.srcDir = this.options.srcDir || "./spec"; if (!this.options.silent) { console.log(banner); @@ -96,7 +97,7 @@ export class UTXOEngine { return Object.keys(this.entries); } - async build(outputDir) { + async build(outputDir = "./dist") { await emptyDir(outputDir); const entriesIndex = []; @@ -148,10 +149,26 @@ export class UTXOEngine { entriesIndex.push({ id: `utxo${entryId}`, entryId, - url: `${baseUrl}/${entryId}`, + url: `${baseUrl}/${entryId}/`, + schema: `${baseUrl}/schema/${entry.schemaVersion || "1"}/`, }); } + // write schemas + const schemaVersion = this.defaultSchemaVersion; + const schemas = await this.schemas(schemaVersion); + + const outputSchemaDir = [outputDir, "schema", schemaVersion].join("/"); + await emptyDir(outputSchemaDir); + console.log(`UTXO: writing schema (v${schemaVersion}) ..`); + + for (const schema of schemas) { + await this._jsonWrite( + [outputSchemaDir, schema.name + ".json"], + schema.schema, + ); + } + // write global index await this._jsonWrite([outputDir, "index.json"], entriesIndex); @@ -160,8 +177,8 @@ export class UTXOEngine { } } - async schemas() { - const schemaDir = "./utils/schema"; + async schemas(version = "1") { + const schemaDir = `./utils/schema/${version}`; const arr = []; for await (const f of Deno.readDir(schemaDir)) { const m = f.name.match(/^(.+)\.yaml$/); diff --git a/utils/exec.js b/utils/exec.js new file mode 100644 index 0000000..1817c82 --- /dev/null +++ b/utils/exec.js @@ -0,0 +1,9 @@ +import { UTXOEngine } from "./engine.js"; + +const utxo = new UTXOEngine(); +await utxo.init(); + +let cmd = Deno.args[0] || "build"; +let args = Deno.args.slice(1) || []; + +await utxo[cmd](...args); diff --git a/utils/schema/events.yaml b/utils/schema/1/events.yaml similarity index 100% rename from utils/schema/events.yaml rename to utils/schema/1/events.yaml diff --git a/utils/schema/faqs.yaml b/utils/schema/1/faqs.yaml similarity index 100% rename from utils/schema/faqs.yaml rename to utils/schema/1/faqs.yaml diff --git a/utils/schema/index.yaml b/utils/schema/1/index.yaml similarity index 94% rename from utils/schema/index.yaml rename to utils/schema/1/index.yaml index a93ffeb..61df75a 100644 --- a/utils/schema/index.yaml +++ b/utils/schema/1/index.yaml @@ -34,5 +34,7 @@ properties: type: type: string pattern: "[a-z]+" + schemaVersion: + type: number diff --git a/utils/schema/partners.yaml b/utils/schema/1/partners.yaml similarity index 100% rename from utils/schema/partners.yaml rename to utils/schema/1/partners.yaml diff --git a/utils/schema/projects.yaml b/utils/schema/1/projects.yaml similarity index 100% rename from utils/schema/projects.yaml rename to utils/schema/1/projects.yaml diff --git a/utils/schema/speakers.yaml b/utils/schema/1/speakers.yaml similarity index 100% rename from utils/schema/speakers.yaml rename to utils/schema/1/speakers.yaml diff --git a/utils/schema/tracks.yaml b/utils/schema/1/tracks.yaml similarity index 100% rename from utils/schema/tracks.yaml rename to utils/schema/1/tracks.yaml