2024-05-11 09:52:07 +00:00
|
|
|
import { exec } from "child_process";
|
2024-01-22 14:25:48 +00:00
|
|
|
import fs from "fs";
|
|
|
|
|
|
|
|
type App = {
|
2024-05-11 09:52:07 +00:00
|
|
|
id: string;
|
2024-01-22 14:25:48 +00:00
|
|
|
name: string;
|
|
|
|
description: string;
|
2024-05-11 09:52:07 +00:00
|
|
|
source: string;
|
|
|
|
port: number;
|
2024-01-22 14:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const getAppsList = async () => {
|
|
|
|
const apps: Record<string, App> = {};
|
|
|
|
|
2024-05-11 10:04:42 +00:00
|
|
|
const appNames = fs.readdirSync(__dirname + "/../../apps");
|
2024-01-22 14:25:48 +00:00
|
|
|
|
|
|
|
for (const app of appNames) {
|
|
|
|
try {
|
2024-05-11 10:04:42 +00:00
|
|
|
const appConfig = fs.readFileSync(
|
|
|
|
`${__dirname}/../../apps/${app}/config.json`,
|
|
|
|
"utf8"
|
|
|
|
);
|
2024-01-22 14:25:48 +00:00
|
|
|
const appConfigJson = JSON.parse(appConfig);
|
|
|
|
|
|
|
|
if (!appConfigJson.deprecated) {
|
|
|
|
apps[app] = {
|
2024-05-11 09:52:07 +00:00
|
|
|
id: appConfigJson.id,
|
2024-01-22 14:25:48 +00:00
|
|
|
name: appConfigJson.name,
|
|
|
|
description: appConfigJson.short_desc,
|
2024-05-11 09:52:07 +00:00
|
|
|
source: appConfigJson.source,
|
|
|
|
port: appConfigJson.port,
|
2024-01-22 14:25:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(`Error parsing config for ${app}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { apps };
|
|
|
|
};
|
|
|
|
|
2024-05-11 09:52:07 +00:00
|
|
|
const appToReadme = async (app: App) => {
|
2024-05-11 10:04:42 +00:00
|
|
|
return `| <img src="apps/${app.id}/metadata/logo.jpg" style="border-radius: 10px;" height="auto" width=50> | [${app.name}](${app.source}) | ${app.description} | ${app.port} |`;
|
2024-01-22 14:25:48 +00:00
|
|
|
};
|
|
|
|
|
2024-05-11 10:10:40 +00:00
|
|
|
const writeToReadme = (appsList: string, count: number) => {
|
2024-01-22 14:25:48 +00:00
|
|
|
const baseReadme = fs.readFileSync(
|
|
|
|
__dirname + "/../../templates/README.md",
|
2024-05-11 10:04:42 +00:00
|
|
|
"utf8"
|
2024-01-22 14:25:48 +00:00
|
|
|
);
|
2024-05-11 10:10:40 +00:00
|
|
|
let finalReadme = baseReadme.replace("<!appsList>", appsList);
|
|
|
|
finalReadme = finalReadme.replace("<!appsCount>", count.toString());
|
2024-01-22 14:25:48 +00:00
|
|
|
fs.writeFileSync(__dirname + "/../../README.md", finalReadme);
|
|
|
|
};
|
|
|
|
|
|
|
|
const main = async () => {
|
|
|
|
const apps = await getAppsList();
|
|
|
|
const appKeys = Object.keys(apps["apps"]);
|
|
|
|
let appsList = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < appKeys.length; i++) {
|
|
|
|
const appFinal = await appToReadme(apps["apps"][appKeys[i]]);
|
2024-05-11 09:52:07 +00:00
|
|
|
appsList = appsList + (appFinal + "\n");
|
2024-01-22 14:25:48 +00:00
|
|
|
}
|
|
|
|
|
2024-05-11 10:10:40 +00:00
|
|
|
writeToReadme(appsList, appKeys.length);
|
2024-05-11 09:52:07 +00:00
|
|
|
exec(
|
|
|
|
`npx prettier ${__dirname + "/../../README.md"} --write`,
|
|
|
|
(stdout, stderr) => {
|
|
|
|
if (stderr) {
|
|
|
|
console.error(stderr);
|
|
|
|
} else if (stdout) {
|
|
|
|
console.log(stdout);
|
|
|
|
}
|
2024-05-11 10:04:42 +00:00
|
|
|
}
|
2024-05-11 09:52:07 +00:00
|
|
|
);
|
2024-01-22 14:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
main();
|