From 9ea20847f2eaec16fc3fc59c08b37ff08f3f1127 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Tue, 21 May 2024 07:42:44 +0200 Subject: [PATCH] fix(readme-generator): sort app names before writing --- .github/scripts/readme-generator.ts | 49 ++++++++++++----------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/.github/scripts/readme-generator.ts b/.github/scripts/readme-generator.ts index c01be829..0147f4a0 100644 --- a/.github/scripts/readme-generator.ts +++ b/.github/scripts/readme-generator.ts @@ -1,5 +1,5 @@ -import { exec } from "child_process"; -import fs from "fs"; +import { exec } from 'child_process'; +import fs from 'fs'; type App = { id: string; @@ -12,14 +12,11 @@ type App = { const getAppsList = async () => { const apps: Record = {}; - const appNames = fs.readdirSync(__dirname + "/../../apps"); + const appNames = fs.readdirSync(__dirname + '/../../apps'); for (const app of appNames) { try { - const appConfig = fs.readFileSync( - `${__dirname}/../../apps/${app}/config.json`, - "utf8", - ); + const appConfig = fs.readFileSync(`${__dirname}/../../apps/${app}/config.json`, 'utf8'); const appConfigJson = JSON.parse(appConfig); if (!appConfigJson.deprecated) { @@ -44,36 +41,30 @@ const appToReadme = async (app: App) => { }; const writeToReadme = (appsList: string, count: number) => { - const baseReadme = fs.readFileSync( - __dirname + "/../../templates/README.md", - "utf8", - ); - let finalReadme = baseReadme.replace("", appsList); - finalReadme = finalReadme.replace("", count.toString()); - fs.writeFileSync(__dirname + "/../../README.md", finalReadme); + const baseReadme = fs.readFileSync(__dirname + '/../../templates/README.md', 'utf8'); + let finalReadme = baseReadme.replace('', appsList); + finalReadme = finalReadme.replace('', count.toString()); + fs.writeFileSync(__dirname + '/../../README.md', finalReadme); }; const main = async () => { - const apps = await getAppsList(); - const appKeys = Object.keys(apps["apps"]); - let appsList = ""; + const { apps } = await getAppsList(); + const appKeys = Object.keys(apps).sort(); + let appsList = ''; for (let i = 0; i < appKeys.length; i++) { - const appFinal = await appToReadme(apps["apps"][appKeys[i]]); - appsList = appsList + (appFinal + "\n"); + const appFinal = await appToReadme(apps[appKeys[i]]); + appsList = appsList + (appFinal + '\n'); } writeToReadme(appsList, appKeys.length); - exec( - `npx prettier ${__dirname + "/../../README.md"} --write`, - (stdout, stderr) => { - if (stderr) { - console.error(stderr); - } else if (stdout) { - console.log(stdout); - } - }, - ); + exec(`npx prettier ${__dirname + '/../../README.md'} --write`, (stdout, stderr) => { + if (stderr) { + console.error(stderr); + } else if (stdout) { + console.log(stdout); + } + }); }; main();