2023-10-07 20:48:35 +02:00
|
|
|
import yaml from "npm:js-yaml";
|
2023-10-07 20:01:09 +02:00
|
|
|
|
|
|
|
export class W3PData {
|
2023-10-07 20:48:35 +02:00
|
|
|
constructor() {
|
|
|
|
}
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
async init() {
|
|
|
|
this.data = await this.load("./src");
|
|
|
|
}
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
async load(dataDir) {
|
|
|
|
const out = {};
|
|
|
|
for await (const f of Deno.readDir(dataDir)) {
|
|
|
|
if (f.isFile && f.name.match(/\.yaml$/)) {
|
|
|
|
const name = f.name.split(".")[0];
|
|
|
|
out[name] = await this.loadYaml(`${dataDir}/${f.name}`);
|
|
|
|
}
|
|
|
|
if (f.isDirectory && f.name === "projects") {
|
|
|
|
out.projects = [];
|
|
|
|
const projectsDir = `${dataDir}/${f.name}`;
|
|
|
|
for await (const pcd of Deno.readDir(projectsDir)) {
|
|
|
|
const catName = pcd.name;
|
|
|
|
const catDir = `${projectsDir}/${pcd.name}`;
|
|
|
|
for await (const pd of Deno.readDir(catDir)) {
|
|
|
|
if (!pd.isDirectory) {
|
|
|
|
continue;
|
2023-10-07 20:01:09 +02:00
|
|
|
}
|
2023-10-07 20:48:35 +02:00
|
|
|
const pDir = `${catDir}/${pd.name}`;
|
2023-10-08 00:51:50 +02:00
|
|
|
const indexFn = `${pDir}/index.yaml`;
|
|
|
|
try {
|
|
|
|
await Deno.stat(indexFn);
|
|
|
|
} catch(e) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
const index = yaml.load(
|
2023-10-08 00:51:50 +02:00
|
|
|
await Deno.readTextFile(indexFn),
|
2023-10-07 20:48:35 +02:00
|
|
|
);
|
|
|
|
out.projects.push(Object.assign({ id: pd.name }, index));
|
|
|
|
}
|
2023-10-07 20:01:09 +02:00
|
|
|
}
|
2023-10-07 20:48:35 +02:00
|
|
|
}
|
2023-10-07 20:01:09 +02:00
|
|
|
}
|
2023-10-07 20:48:35 +02:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
async loadYaml(f) {
|
|
|
|
return yaml.load(await Deno.readTextFile(f));
|
|
|
|
}
|
|
|
|
}
|