2023-10-07 20:48:35 +02:00
|
|
|
import yaml from "npm:js-yaml";
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-08 00:02:42 +02:00
|
|
|
import { W3PData } from "./w3pdata.js";
|
|
|
|
|
|
|
|
const w3pd = new W3PData();
|
|
|
|
await w3pd.init();
|
|
|
|
|
2023-10-07 20:01:09 +02:00
|
|
|
function slugify(input) {
|
2023-10-07 20:48:35 +02:00
|
|
|
if (!input) {
|
|
|
|
return "";
|
|
|
|
}
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
// make lower case and trim
|
|
|
|
var slug = input.toLowerCase().trim();
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
// remove accents from charaters
|
|
|
|
slug = slug.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
// replace invalid chars with spaces
|
|
|
|
slug = slug.replace(/[^a-z0-9\s-]/g, " ").trim();
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
// replace multiple spaces or hyphens with a single hyphen
|
|
|
|
slug = slug.replace(/[\s-]+/g, "-");
|
2023-10-07 20:01:09 +02:00
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
return slug;
|
2023-10-07 20:01:09 +02:00
|
|
|
}
|
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
const projectDir = "src/projects";
|
|
|
|
|
|
|
|
async function genCat(cat) {
|
|
|
|
const catDir = `${projectDir}/${cat}`;
|
|
|
|
const f = await Deno.readTextFile(`${catDir}/src.json`);
|
|
|
|
const src = JSON.parse(f);
|
|
|
|
|
|
|
|
for (const p of src.data.Projects) {
|
|
|
|
const id = slugify(p.Project);
|
2023-10-08 00:02:42 +02:00
|
|
|
|
|
|
|
// try to find
|
|
|
|
const found = w3pd.data.projects.find(p => p.id === id)
|
|
|
|
const baseObject = found || {}
|
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
const pDir = `${catDir}/${id}`;
|
|
|
|
console.log(`${id}:\n -> ${pDir}`);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await Deno.mkdir(pDir);
|
|
|
|
} catch {}
|
|
|
|
|
2023-10-08 00:02:42 +02:00
|
|
|
const out = Object.assign(baseObject, {
|
2023-10-07 20:48:35 +02:00
|
|
|
name: p.Project,
|
2023-10-07 21:27:58 +02:00
|
|
|
categories: [cat],
|
2023-10-07 20:48:35 +02:00
|
|
|
description: p.Description,
|
2023-10-07 22:22:56 +02:00
|
|
|
ecosystem: p.Ecosystem !== '-' ? p.Ecosystem : undefined,
|
|
|
|
product_readiness: p.ProductReadiness !== '-' ? p.ProductReadiness : undefined,
|
2023-10-08 00:02:42 +02:00
|
|
|
links: Object.assign(baseObject.links || {}, {
|
2023-10-07 21:58:23 +02:00
|
|
|
web: p.ProjectLink,
|
2023-10-07 21:36:20 +02:00
|
|
|
github: p.GitHub && p.GitHub !== '-' ? p.GitHub : undefined,
|
2023-10-08 00:02:42 +02:00
|
|
|
}),
|
|
|
|
team: Object.assign({}, baseObject.team || {}),
|
|
|
|
});
|
2023-10-08 00:51:50 +02:00
|
|
|
if (p.Docs && p.Docs !== '-') {
|
|
|
|
out.links.docs = p.Docs
|
|
|
|
}
|
2023-10-07 22:22:56 +02:00
|
|
|
if (p.Team === "anon" || p.Team === 'Public') {
|
|
|
|
out.team.anonymous = p.Team === "anon" ? true : false
|
|
|
|
}
|
2023-10-07 22:39:39 +02:00
|
|
|
if (p.TeamLink && p.TeamLink !== '-') {
|
|
|
|
out.team.company = { link: p.TeamLink !== '-' ? p.TeamLink : undefined }
|
2023-10-07 21:36:20 +02:00
|
|
|
}
|
2023-10-07 22:57:52 +02:00
|
|
|
if (Object.keys(out.team).length === 0) {
|
|
|
|
delete out.team
|
|
|
|
}
|
2023-10-08 00:51:50 +02:00
|
|
|
if (p.Token && p.Token !== 'No' && p.Token !== 'no') {
|
2023-10-07 22:22:56 +02:00
|
|
|
out.have_token = true
|
2023-10-08 00:51:50 +02:00
|
|
|
if (typeof(p.Token) === "string" && p.Token.match(/^[A-Z]+$/)) {
|
2023-10-08 00:56:59 +02:00
|
|
|
out.tokens = [{
|
2023-10-08 00:51:50 +02:00
|
|
|
symbol: p.Token
|
2023-10-08 00:56:59 +02:00
|
|
|
}]
|
2023-10-08 00:51:50 +02:00
|
|
|
}
|
2023-10-07 22:22:56 +02:00
|
|
|
if (p.TokenLink) {
|
2023-10-07 22:39:39 +02:00
|
|
|
out.token_link = p.TokenLink !== '-' ? p.TokenLink : undefined
|
2023-10-07 22:22:56 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-08 00:02:42 +02:00
|
|
|
delete out.id
|
2023-10-07 20:48:35 +02:00
|
|
|
const yml = yaml.dump(out);
|
|
|
|
await Deno.writeTextFile(`${pDir}/index.yaml`, yml);
|
|
|
|
//console.log(id, yml)
|
|
|
|
}
|
2023-10-07 20:01:09 +02:00
|
|
|
}
|
|
|
|
|
2023-10-07 20:48:35 +02:00
|
|
|
genCat(Deno.args[0]);
|