Files
curios/tools/release-catalog.mjs
T

38 lines
1.9 KiB
JavaScript

// Published identity is (Curio ID, version, target). Existing identities are immutable.
export function appendRelease(catalog, manifest, artifact, releasedAt) {
const next = structuredClone(catalog);
let curio = next.curios.find(item => item.id === manifest.id);
if (!curio) {
curio = { id: manifest.id, name: manifest.name, description: manifest.description ?? '', versions: [] };
next.curios.push(curio);
}
let version = curio.versions.find(item => item.version === manifest.version);
if (version && version.engine.trove !== manifest.engine.trove) {
throw new Error(`${manifest.id}@${manifest.version}: published engine range cannot change; bump the plugin version`);
}
const existing = version?.artifacts.find(item => item.target === artifact.target);
if (existing) {
for (const key of ['sha256', 'size', 'url']) {
if (existing[key] !== artifact[key]) throw new Error(`${manifest.id}@${manifest.version}/${artifact.target}: published ${key} differs; bump the plugin version`);
}
return next;
}
if (!version) {
version = { version: manifest.version, engine: structuredClone(manifest.engine), releasedAt, artifacts: [] };
curio.versions.unshift(version);
curio.name = manifest.name;
curio.description = manifest.description ?? '';
}
version.artifacts.push(structuredClone(artifact));
next.generatedAt = releasedAt;
return next;
}
export function artifactPath(manifest, target) {
// Validate path components before they become a publication path.
if (!/^[a-z0-9][a-z0-9.-]*[a-z0-9]$/.test(manifest.id)) throw new Error('Invalid Curio ID');
if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(manifest.version)) throw new Error('Invalid plugin version');
if (!['any', 'aarch64-apple-darwin', 'x86_64-apple-darwin'].includes(target)) throw new Error('Unsupported artifact target');
return `packages/${manifest.id}/${manifest.version}/${target}.curio`;
}