|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * 生成 SideStore / AltStore 源文件(apps.json)。 |
| 4 | + * |
| 5 | + * 发布 workflow 会下载未签名 IPA,计算 sha256 与大小后调用本脚本生成 |
| 6 | + * apps.json 并上传到 Release。用户在 SideStore 里添加下面的 sourceURL |
| 7 | + * 即可订阅并一键安装/更新(SideStore 会用用户自己的 Apple ID 重签): |
| 8 | + * |
| 9 | + * https://github.com/while-coder/nes-emulator/releases/latest/download/apps.json |
| 10 | + * |
| 11 | + * 环境变量: |
| 12 | + * SIDESTORE_VERSION 版本号(必填) |
| 13 | + * SIDESTORE_DOWNLOAD_URL IPA 下载地址(必填) |
| 14 | + * SIDESTORE_SHA256 IPA 的 sha256(必填) |
| 15 | + * SIDESTORE_SIZE IPA 字节大小(必填) |
| 16 | + * SIDESTORE_NOTES 版本说明(可选) |
| 17 | + * SIDESTORE_OUTPUT 输出文件(可选,缺省输出到 stdout) |
| 18 | + */ |
| 19 | +const fs = require("node:fs"); |
| 20 | + |
| 21 | +const REPO = "while-coder/nes-emulator"; |
| 22 | +const BUNDLE_ID = "com.while.nesemulator"; |
| 23 | +// releases/latest/download 是 GitHub 提供的稳定地址,始终指向最新 Release 的同名资源。 |
| 24 | +const SOURCE_URL = `https://github.com/${REPO}/releases/latest/download/apps.json`; |
| 25 | +const ICON_URL = `https://raw.githubusercontent.com/${REPO}/main/apps/icon/icon.png`; |
| 26 | +const WEBSITE = "https://while-coder.github.io/nes-emulator/"; |
| 27 | +const TINT_COLOR = "#C8102E"; |
| 28 | +const APP_NAME = "NES Emulator"; |
| 29 | +const DEFAULT_NOTES = "NES/FC 模拟器,支持触屏手柄与即时存档。"; |
| 30 | + |
| 31 | +const version = process.env.SIDESTORE_VERSION; |
| 32 | +const downloadURL = process.env.SIDESTORE_DOWNLOAD_URL; |
| 33 | +const sha256 = process.env.SIDESTORE_SHA256; |
| 34 | +const size = Number(process.env.SIDESTORE_SIZE); |
| 35 | +const notes = (process.env.SIDESTORE_NOTES || "").trim() || DEFAULT_NOTES; |
| 36 | + |
| 37 | +for (const [name, value] of [["SIDESTORE_VERSION", version], ["SIDESTORE_DOWNLOAD_URL", downloadURL], ["SIDESTORE_SHA256", sha256]]) { |
| 38 | + if (!value) { |
| 39 | + console.error(`缺少环境变量 ${name}`); |
| 40 | + process.exit(1); |
| 41 | + } |
| 42 | +} |
| 43 | +if (!Number.isFinite(size) || size <= 0) { |
| 44 | + console.error("SIDESTORE_SIZE 必须是正整数(IPA 字节大小)"); |
| 45 | + process.exit(1); |
| 46 | +} |
| 47 | + |
| 48 | +// AltStore / SideStore 源格式:https://github.com/AltStore/AltStore/blob/main/Sources.md |
| 49 | +const source = { |
| 50 | + name: APP_NAME, |
| 51 | + identifier: `${BUNDLE_ID}.source`, |
| 52 | + sourceURL: SOURCE_URL, |
| 53 | + iconURL: ICON_URL, |
| 54 | + website: WEBSITE, |
| 55 | + tintColor: TINT_COLOR, |
| 56 | + apps: [ |
| 57 | + { |
| 58 | + name: APP_NAME, |
| 59 | + bundleIdentifier: BUNDLE_ID, |
| 60 | + developerName: "while", |
| 61 | + localizedDescription: "NES/FC 模拟器,支持触屏手柄与即时存档,可离线游玩。", |
| 62 | + iconURL: ICON_URL, |
| 63 | + tintColor: TINT_COLOR, |
| 64 | + category: "games", |
| 65 | + appID: BUNDLE_ID, |
| 66 | + versions: [ |
| 67 | + { |
| 68 | + version, |
| 69 | + date: new Date().toISOString(), |
| 70 | + localizedDescription: notes, |
| 71 | + downloadURL, |
| 72 | + size, |
| 73 | + sha256, |
| 74 | + }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + ], |
| 78 | +}; |
| 79 | + |
| 80 | +const json = JSON.stringify(source, null, 2) + "\n"; |
| 81 | +const output = process.env.SIDESTORE_OUTPUT; |
| 82 | +if (output) { |
| 83 | + fs.writeFileSync(output, json); |
| 84 | + console.log(`已生成 ${output}(v${version},${size} 字节)`); |
| 85 | +} else { |
| 86 | + process.stdout.write(json); |
| 87 | +} |
0 commit comments