mirror of
https://github.com/Heretek-AI/awesome-opencode.git
synced 2026-11-07 10:45:57 -10:00
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]>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
/**
|
|
* Canonical YAML formatting for catalog entries.
|
|
*
|
|
* All bot-written and scaffolded entries go through dumpEntry() so quoting is always valid YAML
|
|
* (unquoted ": " in a tagline broke README generation for every entry before this existed).
|
|
*/
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
const KEY_ORDER = [
|
|
'name', 'repo', 'path', 'npm', 'homepage', 'tagline', 'description',
|
|
'kind', 'also', 'topics', 'compat', 'scope', 'tags', 'min_version', 'installation'
|
|
];
|
|
|
|
/**
|
|
* Order keys canonically; unknown keys are kept at the end so validation can report them.
|
|
* @param {object} data
|
|
* @returns {object}
|
|
*/
|
|
function orderEntry(data) {
|
|
const ordered = {};
|
|
for (const key of KEY_ORDER) {
|
|
if (data[key] !== undefined && data[key] !== null && !(Array.isArray(data[key]) && data[key].length === 0)) {
|
|
ordered[key] = data[key];
|
|
}
|
|
}
|
|
for (const key of Object.keys(data)) {
|
|
if (!(key in ordered) && !KEY_ORDER.includes(key) && !key.startsWith('_')) ordered[key] = data[key];
|
|
}
|
|
return ordered;
|
|
}
|
|
|
|
/**
|
|
* Serialize an entry to YAML text.
|
|
* @param {object} data
|
|
* @returns {string}
|
|
*/
|
|
function dumpEntry(data) {
|
|
const clean = orderEntry(data);
|
|
for (const key of ['name', 'tagline', 'description']) {
|
|
if (typeof clean[key] === 'string') clean[key] = clean[key].trim();
|
|
}
|
|
return yaml.dump(clean, { lineWidth: -1, noRefs: true, quotingType: '"' });
|
|
}
|
|
|
|
module.exports = { KEY_ORDER, dumpEntry, orderEntry };
|