mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 00:51:17 -08:00
70 lines
2.3 KiB
JavaScript
70 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/* oxlint-disable no-console */
|
|
|
|
// Updates altstore-source.json with a new version entry pointing at a release
|
|
// IPA asset, then prints the updated file. Used by .github/workflows/tauri-build.yml.
|
|
//
|
|
// Usage: update-altstore-source.mjs <source.json> <version> <build> <ipa-size> <downloadURL> <date> [description]
|
|
// Env: none
|
|
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import process from 'node:process';
|
|
|
|
const [sourcePath, version, build, sizeStr, downloadURL, date, description] = process.argv.slice(2);
|
|
|
|
if (!sourcePath || !version || !build || !sizeStr || !downloadURL || !date) {
|
|
console.error(
|
|
'Usage: update-altstore-source.mjs <source.json> <version> <build> <ipa-size> <downloadURL> <date> [description]'
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const size = Number(sizeStr);
|
|
if (!Number.isInteger(size) || size <= 0) {
|
|
console.error(`ipa-size must be a positive integer (got: ${sizeStr})`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const source = JSON.parse(readFileSync(sourcePath, 'utf8'));
|
|
const app = source.apps?.[0];
|
|
if (!app) {
|
|
console.error('Source JSON has no apps[0] to update.');
|
|
process.exit(1);
|
|
}
|
|
|
|
// Clean version string for AltStore/SideStore compatibility:
|
|
// Apple Info.plist CFBundleShortVersionString / CFBundleVersion replaces hyphens/prereleases (e.g. -nightly.) with numeric/dot delimiters.
|
|
const normalizedVersion = version
|
|
.replace(/-nightly\./g, '.')
|
|
.replace(/[^0-9.]/g, '.')
|
|
.replace(/\.+/g, '.')
|
|
.replace(/^\.|\.$/g, '');
|
|
const normalizedBuild = build
|
|
.replace(/-nightly\./g, '.')
|
|
.replace(/[^0-9.]/g, '.')
|
|
.replace(/\.+/g, '.')
|
|
.replace(/^\.|\.$/g, '');
|
|
|
|
const entry = {
|
|
version: normalizedVersion,
|
|
buildVersion: normalizedBuild,
|
|
date,
|
|
size,
|
|
downloadURL,
|
|
localizedDescription: description ?? `v${version}`,
|
|
};
|
|
|
|
// Replace an existing entry for this version, otherwise prepend as latest.
|
|
const versions = Array.isArray(app.versions) ? app.versions : [];
|
|
const idx = versions.findIndex((v) => v.version === version);
|
|
if (idx >= 0) versions[idx] = entry;
|
|
else versions.unshift(entry);
|
|
|
|
// Keep only the most recent 20 versions in the manifest.
|
|
app.versions = versions.slice(0, 20);
|
|
|
|
writeFileSync(sourcePath, `${JSON.stringify(source, null, 2)}\n`);
|
|
console.log(
|
|
`Updated ${sourcePath}: ${app.bundleIdentifier} v${version} (${build}) -> ${downloadURL}`
|
|
);
|