Files
awesome-opencode/scripts/fmt.js
John SmithandClaude Opus 5.5 56fad94c34 feat(schema): add kind, topics, compat, npm and path; reject unknown fields and non-root repo URLs
Entries gain a fixed kind and 1-3 topics (replacing 374 one-off tags as the categorization axis), an OpenCode API compat field (required for plugins), and npm/path for packages and monorepo folders. repo must be a repository root; unknown fields such as install: or repository: are rejected. Cross-entry rules (one entry per repo+path, kind must fit the category, no placeholder owners or mojibake) live in scripts/utils/catalog.js, and validate.js now always loads the whole catalog and fails on unparseable YAML. Adds npm run fmt for canonical formatting and drops the unused glob dependency.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:00:22 -04:00

47 lines
1.5 KiB
JavaScript

#!/usr/bin/env node
/**
* Rewrite catalog entries in canonical format (key order, safe quoting).
* Usage: node scripts/fmt.js [--check] [file.yaml ...]
*
* --check lists files that would change and exits 1 without writing.
*/
const fs = require('fs');
const path = require('path');
const { loadCatalog, formatProblems } = require('./utils/catalog');
const { dumpEntry } = require('./utils/format');
const ROOT = path.join(__dirname, '..');
function main() {
const argv = process.argv.slice(2);
const check = argv.includes('--check');
const only = argv.filter(a => a.endsWith('.yaml')).map(f => path.relative(ROOT, path.resolve(f)));
const { entries, errors } = loadCatalog();
if (errors.length) {
console.error(formatProblems(errors));
console.error('\nFix the YAML syntax errors above first.');
process.exit(1);
}
const changed = [];
for (const entry of entries) {
if (only.length && !only.includes(entry.file)) continue;
const target = path.join(ROOT, entry.file);
const formatted = dumpEntry(entry.data);
if (fs.readFileSync(target, 'utf8') !== formatted) {
changed.push(entry.file);
if (!check) fs.writeFileSync(target, formatted);
}
}
if (check && changed.length) {
console.error(`${changed.length} file(s) are not in canonical format:\n${changed.map(f => ` ${f}`).join('\n')}\nRun: npm run fmt`);
process.exit(1);
}
console.log(check ? '✓ All entries are formatted.' : `✓ Formatted ${changed.length} file(s).`);
}
main();