fix(readme-generator): sort app names before writing
This commit is contained in:
parent
8f7f4fb576
commit
9ea20847f2
49
.github/scripts/readme-generator.ts
vendored
49
.github/scripts/readme-generator.ts
vendored
|
@ -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<string, App> = {};
|
||||
|
||||
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>", appsList);
|
||||
finalReadme = finalReadme.replace("<!appsCount>", count.toString());
|
||||
fs.writeFileSync(__dirname + "/../../README.md", finalReadme);
|
||||
const baseReadme = fs.readFileSync(__dirname + '/../../templates/README.md', 'utf8');
|
||||
let finalReadme = baseReadme.replace('<!appsList>', appsList);
|
||||
finalReadme = finalReadme.replace('<!appsCount>', 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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user