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 { exec } from 'child_process';
|
||||||
import fs from "fs";
|
import fs from 'fs';
|
||||||
|
|
||||||
type App = {
|
type App = {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -12,14 +12,11 @@ type App = {
|
||||||
const getAppsList = async () => {
|
const getAppsList = async () => {
|
||||||
const apps: Record<string, App> = {};
|
const apps: Record<string, App> = {};
|
||||||
|
|
||||||
const appNames = fs.readdirSync(__dirname + "/../../apps");
|
const appNames = fs.readdirSync(__dirname + '/../../apps');
|
||||||
|
|
||||||
for (const app of appNames) {
|
for (const app of appNames) {
|
||||||
try {
|
try {
|
||||||
const appConfig = fs.readFileSync(
|
const appConfig = fs.readFileSync(`${__dirname}/../../apps/${app}/config.json`, 'utf8');
|
||||||
`${__dirname}/../../apps/${app}/config.json`,
|
|
||||||
"utf8",
|
|
||||||
);
|
|
||||||
const appConfigJson = JSON.parse(appConfig);
|
const appConfigJson = JSON.parse(appConfig);
|
||||||
|
|
||||||
if (!appConfigJson.deprecated) {
|
if (!appConfigJson.deprecated) {
|
||||||
|
@ -44,36 +41,30 @@ const appToReadme = async (app: App) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const writeToReadme = (appsList: string, count: number) => {
|
const writeToReadme = (appsList: string, count: number) => {
|
||||||
const baseReadme = fs.readFileSync(
|
const baseReadme = fs.readFileSync(__dirname + '/../../templates/README.md', 'utf8');
|
||||||
__dirname + "/../../templates/README.md",
|
let finalReadme = baseReadme.replace('<!appsList>', appsList);
|
||||||
"utf8",
|
finalReadme = finalReadme.replace('<!appsCount>', count.toString());
|
||||||
);
|
fs.writeFileSync(__dirname + '/../../README.md', finalReadme);
|
||||||
let finalReadme = baseReadme.replace("<!appsList>", appsList);
|
|
||||||
finalReadme = finalReadme.replace("<!appsCount>", count.toString());
|
|
||||||
fs.writeFileSync(__dirname + "/../../README.md", finalReadme);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const apps = await getAppsList();
|
const { apps } = await getAppsList();
|
||||||
const appKeys = Object.keys(apps["apps"]);
|
const appKeys = Object.keys(apps).sort();
|
||||||
let appsList = "";
|
let appsList = '';
|
||||||
|
|
||||||
for (let i = 0; i < appKeys.length; i++) {
|
for (let i = 0; i < appKeys.length; i++) {
|
||||||
const appFinal = await appToReadme(apps["apps"][appKeys[i]]);
|
const appFinal = await appToReadme(apps[appKeys[i]]);
|
||||||
appsList = appsList + (appFinal + "\n");
|
appsList = appsList + (appFinal + '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
writeToReadme(appsList, appKeys.length);
|
writeToReadme(appsList, appKeys.length);
|
||||||
exec(
|
exec(`npx prettier ${__dirname + '/../../README.md'} --write`, (stdout, stderr) => {
|
||||||
`npx prettier ${__dirname + "/../../README.md"} --write`,
|
if (stderr) {
|
||||||
(stdout, stderr) => {
|
console.error(stderr);
|
||||||
if (stderr) {
|
} else if (stdout) {
|
||||||
console.error(stderr);
|
console.log(stdout);
|
||||||
} else if (stdout) {
|
}
|
||||||
console.log(stdout);
|
});
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user