2023-10-08 01:57:19 +02:00
|
|
|
import { emptyDir } from "https://deno.land/std@0.203.0/fs/empty_dir.ts";
|
2023-10-08 04:04:22 +02:00
|
|
|
import { ensureDir } from "https://deno.land/std@0.203.0/fs/ensure_dir.ts";
|
|
|
|
|
2023-10-07 20:01:09 +02:00
|
|
|
import { W3PData } from "./w3pdata.js";
|
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
const w3pd = new W3PData();
|
|
|
|
await w3pd.init();
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
const outputDir = "./dist";
|
2023-10-07 20:01:09 +02:00
|
|
|
|
|
|
|
try {
|
2023-10-08 01:57:19 +02:00
|
|
|
await emptyDir(outputDir);
|
2023-10-07 20:01:09 +02:00
|
|
|
} catch {}
|
|
|
|
|
2023-10-08 04:04:22 +02:00
|
|
|
for (const p of w3pd.data.projects) {
|
|
|
|
if (!p.logos) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for (const asset of p.logos) {
|
|
|
|
const src = `${p._path}/${asset.file}`
|
|
|
|
const destDir = `${outputDir}/assets/projects/${p.id}`
|
|
|
|
const dest = `${destDir}/${asset.file}`
|
|
|
|
|
|
|
|
await ensureDir(destDir)
|
|
|
|
await Deno.copyFile(src, dest);
|
|
|
|
|
|
|
|
console.log(`${src} -> ${dest}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-08 01:57:19 +02:00
|
|
|
const bundleFn = `${outputDir}/index.json`;
|
2023-10-08 04:04:22 +02:00
|
|
|
|
|
|
|
const out = {}
|
|
|
|
for (const key of Object.keys(w3pd.data)) {
|
|
|
|
|
|
|
|
const arr = []
|
|
|
|
if (key === 'projects') {
|
|
|
|
for (const p of w3pd.data[key]) {
|
|
|
|
delete p._path
|
|
|
|
arr.push(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out[key] = arr
|
|
|
|
}
|
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
await Deno.writeTextFile(bundleFn, JSON.stringify(w3pd.data, null, 2));
|
|
|
|
console.log(`Bundle writed: ${bundleFn}`);
|