Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | import { fileURLToPath } from 'node:url'; |
| 2 | import { checkCodeExamples, listCodeExampleFiles, inventoryCodeExamples } from '../lib/code-examples'; |
| 3 | |
| 4 | const USAGE = 'Usage: bun scripts/check-code-examples.ts [--json] [--inventory]'; |
| 5 | const args = process.argv.slice(2); |
| 6 | const unknown = args.filter((arg) => arg !== '--json' && arg !== '--inventory'); |
| 7 | if (unknown.length) { |
| 8 | console.error(`Unknown argument(s): ${unknown.join(' ')}\n${USAGE}`); |
| 9 | process.exit(2); |
| 10 | } |
| 11 | |
| 12 | const docsRoot = fileURLToPath(new URL('..', import.meta.url)); |
| 13 | if (args.includes('--inventory')) { |
| 14 | console.log(JSON.stringify(inventoryCodeExamples(docsRoot), null, 2)); |
| 15 | process.exit(0); |
| 16 | } |
| 17 | const files = listCodeExampleFiles(docsRoot); |
| 18 | const violations = checkCodeExamples(files, { requireApi: true }); |
| 19 | const counts: Record<string, number> = {}; |
| 20 | for (const violation of violations) counts[violation.rule] = (counts[violation.rule] ?? 0) + 1; |
| 21 | |
| 22 | if (args.includes('--json')) { |
| 23 | console.log(JSON.stringify({ files: files.length, violations, counts }, null, 2)); |
| 24 | } else if (violations.length) { |
| 25 | for (const { path, line, rule, message } of violations) console.log(`${path}:${line} ${rule} ${message}`); |
| 26 | const fileCount = new Set(violations.map((violation) => violation.path)).size; |
| 27 | console.log(`\n${violations.length} code example violation(s) in ${fileCount} of ${files.length} file(s):`); |
| 28 | for (const rule of Object.keys(counts).sort()) console.log(` ${rule}: ${counts[rule]}`); |
| 29 | } else { |
| 30 | console.log(`No code example violations in ${files.length} file(s).`); |
| 31 | } |
| 32 | |
| 33 | process.exit(violations.length ? 1 : 0); |