From 5e3a485edcea44bd4b79d0c68665613486fcb0df Mon Sep 17 00:00:00 2001 From: V Date: Fri, 8 Sep 2023 02:26:22 +0200 Subject: [PATCH] ci: generate plugin readme map --- .github/workflows/build.yml | 2 +- scripts/generatePluginList.ts | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3815d0d4e..d9e2789d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,7 @@ jobs: run: pnpm build --standalone - name: Generate plugin list - run: pnpm generatePluginJson dist/plugins.json + run: pnpm generatePluginJson dist/plugins.json dist/plugin-readmes.json - name: Clean up obsolete files run: | diff --git a/scripts/generatePluginList.ts b/scripts/generatePluginList.ts index 2c96e61bc..b788178cd 100644 --- a/scripts/generatePluginList.ts +++ b/scripts/generatePluginList.ts @@ -165,7 +165,11 @@ async function parseFile(fileName: string) { data.target = target as any; } - return data; + let readme = ""; + try { + readme = readFileSync(join(fileName, "..", "README.md"), "utf-8"); + } catch { } + return [data, readme] as const; } throw fail("no default export called 'definePlugin' found"); @@ -194,18 +198,24 @@ function isPluginFile({ name }: { name: string; }) { (async () => { parseDevs(); - const plugins = ["src/plugins", "src/plugins/_core"].flatMap(dir => + const plugins = [] as PluginData[]; + const readmes = {} as Record; + + await Promise.all(["src/plugins", "src/plugins/_core"].flatMap(dir => readdirSync(dir, { withFileTypes: true }) .filter(isPluginFile) - .map(async dirent => - parseFile(await getEntryPoint(dir, dirent)) - ) - ); + .map(async dirent => { + const [data, readme] = await parseFile(await getEntryPoint(dir, dirent)); + plugins.push(data); + if (readme) readmes[data.name] = readme; + }) + )); - const data = JSON.stringify(await Promise.all(plugins)); + const data = JSON.stringify(plugins); - if (process.argv.length > 2) { + if (process.argv.length > 3) { writeFileSync(process.argv[2], data); + writeFileSync(process.argv[3], JSON.stringify(readmes)); } else { console.log(data); }