|
| 1 | +import fs from 'fs/promises'; |
| 2 | +import path from 'path'; |
| 3 | + |
| 4 | +async function main() { |
| 5 | + const openMark = '<!-- <ServersTable> -->'; |
| 6 | + const closeMark = '<!-- </ServersTable> -->'; |
| 7 | + |
| 8 | + let table = `${openMark}\n`; |
| 9 | + table += await renderTable('implementations'); |
| 10 | + table += '\n'; // prettier would the new line here |
| 11 | + table += `\n${closeMark}`; |
| 12 | + |
| 13 | + const readme = (await fs.readFile('README.md')).toString(); |
| 14 | + |
| 15 | + await fs.writeFile( |
| 16 | + 'README.md', |
| 17 | + readme.replace(new RegExp(`${openMark}.+?${closeMark}`, 's'), table), |
| 18 | + ); |
| 19 | +} |
| 20 | + |
| 21 | +main().catch((err) => { |
| 22 | + console.error(err); |
| 23 | + process.exit(1); |
| 24 | +}); |
| 25 | + |
| 26 | +/** @param {string} implsDir */ |
| 27 | +async function renderTable(implsDir) { |
| 28 | + let out = `<!-- prettier-ignore-start --> |
| 29 | +| Name | Audit | |
| 30 | +|------|-------|`; |
| 31 | + for (const implDir of (await fs.readdir(implsDir)).sort()) { |
| 32 | + /** @type {{ error: number }} */ |
| 33 | + const report = JSON.parse( |
| 34 | + ( |
| 35 | + await fs.readFile(path.join(implsDir, implDir, 'report.json')) |
| 36 | + ).toString(), |
| 37 | + ); |
| 38 | + if (report.error > 0) { |
| 39 | + continue; |
| 40 | + } |
| 41 | + |
| 42 | + /** @type {Record<string, unknown>} */ |
| 43 | + const pkg = JSON.parse( |
| 44 | + ( |
| 45 | + await fs.readFile(path.join(implsDir, implDir, 'package.json')) |
| 46 | + ).toString(), |
| 47 | + ); |
| 48 | + if (pkg.name === 'express-graphql') { |
| 49 | + // deprecated |
| 50 | + continue; |
| 51 | + } |
| 52 | + |
| 53 | + out += '\n'; |
| 54 | + if (pkg.url) { |
| 55 | + out += `| [${pkg.name}](${pkg.url}) `; |
| 56 | + } else { |
| 57 | + out += `| ${pkg.name} `; |
| 58 | + } |
| 59 | + out += `| [✅ Compliant](/implementations/${implDir}/README.md) |`; |
| 60 | + } |
| 61 | + out += '\n<!-- prettier-ignore-end -->'; |
| 62 | + return out; |
| 63 | +} |
0 commit comments