|
| 1 | +// scripts/make-latest-json.mjs |
| 2 | +import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs'; |
| 3 | +import { basename } from 'node:path'; |
| 4 | +import fg from 'fast-glob'; |
| 5 | + |
| 6 | +function getVersion() { |
| 7 | + if (process.env.APP_VERSION) return process.env.APP_VERSION; |
| 8 | + const cfg = JSON.parse(readFileSync('src-tauri/tauri.conf.json', 'utf8')); |
| 9 | + if (!cfg.version) throw new Error('No version in src-tauri/tauri.conf.json and APP_VERSION not set'); |
| 10 | + return cfg.version; |
| 11 | +} |
| 12 | + |
| 13 | +function reqEnv(name) { |
| 14 | + const v = process.env[name]; |
| 15 | + if (!v) throw new Error(`Missing env ${name}`); |
| 16 | + return v; |
| 17 | +} |
| 18 | + |
| 19 | +async function findOne(glob) { |
| 20 | + const list = await fg(glob); |
| 21 | + return list[0] || null; |
| 22 | +} |
| 23 | + |
| 24 | +(async () => { |
| 25 | + const OWNER = 'runtime-org'; |
| 26 | + const REPO = 'runtime'; |
| 27 | + const VERSION = getVersion(); |
| 28 | + const TAG = process.env.GIT_TAG || `v${VERSION}`; |
| 29 | + |
| 30 | + // Universal artifacts |
| 31 | + const base = 'src-tauri/target/universal-apple-darwin/release/bundle/macos'; |
| 32 | + const tar = await findOne(`${base}/*.app.tar.gz`); |
| 33 | + const sig = await findOne(`${base}/*.app.tar.gz.sig`); |
| 34 | + if (!tar || !sig) { |
| 35 | + throw new Error('Universal updater artifacts not found. Did you build with "--target universal-apple-darwin --bundles dmg app"?'); |
| 36 | + } |
| 37 | + |
| 38 | + const url = `https://github.com/${OWNER}/${REPO}/releases/download/${TAG}/${basename(tar)}`; |
| 39 | + const signature = readFileSync(sig, 'utf8').trim(); |
| 40 | + |
| 41 | + const latest = { |
| 42 | + version: VERSION, |
| 43 | + notes: "", |
| 44 | + pub_date: new Date().toISOString(), |
| 45 | + platforms: { |
| 46 | + // Point both architectures to the same universal tarball |
| 47 | + "darwin-aarch64": { url, signature }, |
| 48 | + "darwin-x86_64": { url, signature } |
| 49 | + } |
| 50 | + }; |
| 51 | + |
| 52 | + if (!existsSync('dist')) mkdirSync('dist', { recursive: true }); |
| 53 | + writeFileSync('dist/latest.json', JSON.stringify(latest, null, 2)); |
| 54 | + console.log('dist/latest.json written for universal macOS'); |
| 55 | +})(); |
0 commit comments