Build option
This commit is contained in:
rodič
dd13463b6e
revize
07bb99d1ee
|
@ -0,0 +1,41 @@
|
|||
name: Test, build, deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master # Set a branch to deploy
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: denoland/setup-deno@v1
|
||||
with:
|
||||
deno-version: v1.x
|
||||
|
||||
- uses: szenius/set-timezone@v1.0
|
||||
with:
|
||||
timezoneLinux: "Europe/Prague"
|
||||
|
||||
- name: Build sources
|
||||
run: make
|
||||
|
||||
# - name: Build changelog
|
||||
# run: make changelog
|
||||
|
||||
- name: Add custom domain
|
||||
run: "touch dist/CNAME && echo \"data.prgblockweek.com\" >> dist/CNAME"
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
if: ${{ github.ref == 'refs/heads/master' }}
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./dist
|
|
@ -1 +1,2 @@
|
|||
.DS_Store
|
||||
dist
|
102
utils/engine.js
102
utils/engine.js
|
@ -1,40 +1,92 @@
|
|||
import { emptyDir, exists } from "https://deno.land/std@0.119.0/fs/mod.ts";
|
||||
import { parse as tomlParse } from "https://deno.land/std@0.173.0/encoding/toml.ts";
|
||||
|
||||
const _silentMode = false;
|
||||
|
||||
export class DeConfEngine {
|
||||
constructor(options = {}) {
|
||||
this.options = options;
|
||||
this.srcDir = this.options.srcDir || "./data";
|
||||
this.outputDir = this.options.outputDir || "./dist";
|
||||
}
|
||||
async init() {}
|
||||
async build() {
|
||||
await emptyDir(this.outputDir);
|
||||
|
||||
this.entries = {};
|
||||
for await (const f of Deno.readDir(this.srcDir)) {
|
||||
if (!f.name.match(/^\d+$/)) {
|
||||
continue;
|
||||
}
|
||||
const specDir = [this.srcDir, f.name].join("/");
|
||||
|
||||
const entry = this.entries[f.name] = {};
|
||||
// load year index
|
||||
entry.index = await this._tomlLoad([specDir, "index.toml"].join("/"));
|
||||
console.log(`\n##\n## [${entry.index.name}] \n##`);
|
||||
// load sub-events
|
||||
entry.events = [];
|
||||
for await (const ef of Deno.readDir([specDir, "events"].join("/"))) {
|
||||
if (!ef.name.match(/^[\w\d\-]+$/)) {
|
||||
continue;
|
||||
}
|
||||
const efDir = [specDir, "events", ef.name].join("/");
|
||||
const efIndex = await this._tomlLoad([efDir, "index.toml"].join("/"));
|
||||
const event = {
|
||||
index: efIndex,
|
||||
};
|
||||
entry.events.push(event);
|
||||
}
|
||||
console.table(entry.events.map((e) => e.index), ["name"]);
|
||||
if (!f.name.match(/^\d+$/)) continue;
|
||||
const pkg = new DeConf_Package(f.name);
|
||||
await pkg.load([this.srcDir, f.name]);
|
||||
console.table(pkg.data.events.map((e) => e.data.index), ["name"]);
|
||||
await pkg.write(this.outputDir);
|
||||
}
|
||||
}
|
||||
async _tomlLoad(fn) {
|
||||
return tomlParse(await Deno.readTextFile(fn));
|
||||
}
|
||||
|
||||
class DeConf_Package {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
async load(specDir) {
|
||||
const pkg = {};
|
||||
// load year index
|
||||
pkg.index = await _tomlLoad([...specDir, "index.toml"].join("/"));
|
||||
console.log(`\n##\n## [${pkg.index.name}] \n##`);
|
||||
// load sub-events
|
||||
pkg.events = [];
|
||||
for await (const ef of Deno.readDir([...specDir, "events"].join("/"))) {
|
||||
if (!ef.name.match(/^[\w\d\-]+$/)) continue;
|
||||
const ev = new DeConf_Event(ef.name);
|
||||
await ev.load([...specDir, "events", ef.name]);
|
||||
pkg.events.push(ev);
|
||||
}
|
||||
this.data = pkg;
|
||||
}
|
||||
async write(dir) {
|
||||
const outputDir = [dir, this.id].join("/");
|
||||
await emptyDir(outputDir);
|
||||
await _jsonWrite([outputDir, "bundle.json"], this.toJSON());
|
||||
}
|
||||
toJSON() {
|
||||
return Object.assign({ id: this.id }, this.data.index, {
|
||||
events: this.data.events,
|
||||
time: new Date(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class DeConf_Event {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
async load(dir) {
|
||||
const efIndex = await _tomlLoad([...dir, "index.toml"].join("/"));
|
||||
const event = {
|
||||
index: efIndex,
|
||||
};
|
||||
this.data = event;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return Object.assign({ id: this.id }, this.data.index);
|
||||
}
|
||||
}
|
||||
|
||||
async function _tomlLoad(fn) {
|
||||
return tomlParse(await Deno.readTextFile(fn));
|
||||
}
|
||||
async function _jsonWrite(fn, data) {
|
||||
if (Array.isArray(fn)) {
|
||||
fn = fn.join("/");
|
||||
}
|
||||
await Deno.writeTextFile(fn, JSON.stringify(data, null, 2));
|
||||
if (!_silentMode) {
|
||||
console.log(`${fn} writed`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Načítá se…
Odkázat v novém úkolu