Kaleido-Desktop/scripts/update-manifest.mjs
Elijah be865fa992
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 1m21s
Document the release and push flow for future sessions
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 17:28:04 -07:00

53 lines
2.6 KiB
JavaScript

// Writes updates/latest.json, the feed Kaleido's updater reads, from built bundles.
// Usage: node scripts/update-manifest.mjs <version> <baseDownloadUrl> [notesFile]
// Notes come from the version's CHANGELOG.md section unless a notes file is given.
// Each platform's signed artifact (and its .sig) must be in src-tauri/target/release/bundle,
// or pass several bundle folders via KALEIDO_BUNDLES (path;path) when collecting CI outputs.
import fs from 'node:fs';
import path from 'node:path';
const [version, baseUrl, notesFile] = process.argv.slice(2);
if (!version || !baseUrl) {
console.error('usage: node scripts/update-manifest.mjs <version> <baseDownloadUrl> [notesFile]');
process.exit(1);
}
const root = path.resolve(import.meta.dirname, '..');
const bundles = (process.env.KALEIDO_BUNDLES ?? path.join(root, 'src-tauri/target/release/bundle')).split(';');
/** Tauri updater platform keys and the artifact each one installs. */
const PLATFORMS = [
{ key: 'windows-x86_64', dir: 'nsis', match: /-setup\.exe$/ },
{ key: 'darwin-aarch64', dir: 'macos', match: /aarch64.*\.app\.tar\.gz$/ },
{ key: 'darwin-x86_64', dir: 'macos', match: /x64.*\.app\.tar\.gz$/ },
{ key: 'linux-x86_64', dir: 'appimage', match: /\.AppImage$/ },
];
const manifestPath = path.join(root, 'updates/latest.json');
const manifest = fs.existsSync(manifestPath) ? JSON.parse(fs.readFileSync(manifestPath, 'utf8')) : { platforms: {} };
manifest.version = version;
// Notes default to this version's section of CHANGELOG.md.
const changelogNotes = () => {
const section = fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8').split(/^## /m).find((x) => x.startsWith(version));
return section ? section.slice(version.length).trim() : '';
};
manifest.notes = notesFile ? fs.readFileSync(notesFile, 'utf8').trim() : changelogNotes();
manifest.pub_date = new Date().toISOString();
manifest.platforms ??= {};
for (const bundle of bundles) {
for (const p of PLATFORMS) {
const dir = path.join(bundle, p.dir);
if (!fs.existsSync(dir)) continue;
const file = fs.readdirSync(dir).find((f) => p.match.test(f) && f.includes(version));
if (!file || !fs.existsSync(path.join(dir, `${file}.sig`))) continue;
manifest.platforms[p.key] = {
signature: fs.readFileSync(path.join(dir, `${file}.sig`), 'utf8').trim(),
url: `${baseUrl.replace(/\/$/, '')}/${encodeURIComponent(file)}`,
};
console.log(`${p.key}: ${file}`);
}
}
fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
console.log(`Wrote ${path.relative(root, manifestPath)}`);