diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e025953..c1724e2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,11 +21,10 @@ jobs: - uses: szenius/set-timezone@v1.0 with: timezoneLinux: "Europe/Prague" - - run: make - - run: find dist - run: "deno run --allow-run utils/tag.js >> $GITHUB_ENV" - - run: "echo \"${{ env.TAG }}\" >> ./dist/TAG" - - run: "echo \"Builded Tag: ${{ env.TAG }}\"" + - run: "echo \"Tag: ${{ env.TAG }}\"" + - run: "make tag=${{ env.TAG }}" + - run: find dist - uses: montudor/action-zip@v1 - run: "zip -qq -r release.zip dist" - uses: actions/upload-artifact@v3 diff --git a/.gitignore b/.gitignore index 19b1931..f0e9622 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist dist-mirror cache .env +.vscode \ No newline at end of file diff --git a/Makefile b/Makefile index f56bc94..82a17f1 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ format: fmt: format build: - deno run --unstable --allow-read --allow-write utils/exec.js build + deno run --unstable --allow-read --allow-write utils/build.js tag=$(tag) build-mirror: deno run --unstable --allow-read --allow-write utils/mirror.js diff --git a/utils/build.js b/utils/build.js new file mode 100644 index 0000000..25b7a5b --- /dev/null +++ b/utils/build.js @@ -0,0 +1,19 @@ +import { DeConfEngine } from "./engine.js"; + +const args = Deno.args || []; +const options = Object.fromEntries( + args.map((x) => { + const [key, value] = x.split("="); + if (!value) return null; + return [key, value]; + }).filter((x) => x), +); + +const deconf = new DeConfEngine(); +console.log(options) +await deconf.init(options); + +const output = await deconf.build(); +if (output) { + console.log(output); +} diff --git a/utils/engine.js b/utils/engine.js index dfdbee5..5312ca6 100644 --- a/utils/engine.js +++ b/utils/engine.js @@ -16,6 +16,7 @@ let _silentMode = false; export class DeConfEngine { constructor(options = {}) { this.options = options; + this.tag = this.options.tag || "dev"; this.srcDir = this.options.srcDir || "./data"; this.outputDir = this.options.outputDir || "./dist"; this.publicUrl = this.options.publicUrl || "https://data.prgblockweek.com"; @@ -39,6 +40,8 @@ export class DeConfEngine { } async build() { await emptyDir(this.outputDir); + console.log(this.tag) + await _textWrite([this.outputDir, "TAG"], this.tag); for (const pkg of this.entries) { console.table(pkg.data.events.map((e) => e.data.index), ["name"]); await pkg.write(this.outputDir); @@ -103,6 +106,7 @@ class DeConf_Package { this.id = id; this.data = null; this.engine = engine; + this.tag = engine.tag; this.colMapper = { places: "place", events: "event", @@ -170,7 +174,8 @@ class DeConf_Package { return [col, this.data[col]]; }), ), - time: new Date(), + __time: new Date(), + __tag: this.tag, }); } } @@ -338,6 +343,12 @@ async function _jsonWrite(fn, data) { } return true; } +async function _textWrite(fn, text) { + if (Array.isArray(fn)) { + fn = fn.join("/"); + } + await Deno.writeTextFile(fn, text); +} async function _jsonLoad(fn) { return JSON.parse(await Deno.readTextFile(fn)); } diff --git a/utils/exec.js b/utils/exec.js index 26c8fdb..4f3b6bd 100644 --- a/utils/exec.js +++ b/utils/exec.js @@ -6,6 +6,14 @@ await deconf.init(); let cmd = Deno.args[0] || "build"; let args = Deno.args.slice(1) || []; +const options = Object.fromEntries( + args.map((x) => { + const [key, value] = x.split("="); + if (!value) return null; + return [key, value]; + }).filter((x) => x), +); + const output = await deconf[cmd](...args); if (output) { console.log(output);