WIP from the MacBook: apple platform helper for submit, resubmit, release and status
This commit is contained in:
parent
3e4015b686
commit
96c1074701
8 changed files with 169 additions and 57 deletions
71
cli/lib/apple-platform.ts
Normal file
71
cli/lib/apple-platform.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
// The platform of an App Store version: one app record can hold an iOS, a macOS, a tvOS and a visionOS version, each
|
||||
// with its own version string, state, build and review submission. Commands that act on "the" version (listing,
|
||||
// submit, resubmit, release, status --wait-review) pick the platform here: --platform when given, else the only
|
||||
// platform the app has, else the one platform where the version the command needs is (a rejected one for resubmit,
|
||||
// an editable one for listing), else iOS with a note. Two candidates refuse and ask for --platform: guessing between
|
||||
// a rejected iOS and a rejected macOS version would act on the wrong one. Pure.
|
||||
//
|
||||
// Lesson (2026-10-20): `apple resubmit` read iOS versions only and said "nothing to resubmit" while a macOS version was
|
||||
// REJECTED with an UNRESOLVED_ISSUES submission; `apple listing --version` refused because the iOS version with that
|
||||
// number was READY_FOR_DISTRIBUTION while the macOS one was the rejected one to fix.
|
||||
|
||||
export type ApplePlatform = 'IOS' | 'MAC_OS' | 'TV_OS' | 'VISION_OS';
|
||||
export const APPLE_PLATFORMS: readonly ApplePlatform[] = ['IOS', 'MAC_OS', 'TV_OS', 'VISION_OS'];
|
||||
|
||||
const NAMES: Record<ApplePlatform, string> = { IOS: 'iOS', MAC_OS: 'macOS', TV_OS: 'tvOS', VISION_OS: 'visionOS' };
|
||||
const SLUGS: Record<ApplePlatform, string> = { IOS: 'ios', MAC_OS: 'macos', TV_OS: 'tvos', VISION_OS: 'visionos' };
|
||||
|
||||
/** "iOS", "macOS", ... (an unknown value as it is). */
|
||||
export const platformName = (p: string): string => NAMES[p as ApplePlatform] ?? p;
|
||||
/** The --platform value of a platform: ios, macos, tvos, visionos. */
|
||||
export const platformSlug = (p: ApplePlatform): string => SLUGS[p];
|
||||
|
||||
/** --platform ios|macos|tvos|visionos (also IOS, MAC_OS, mac, ipados, xros, ...) -> the API value; undefined when not given. */
|
||||
export function parsePlatform(v: string | undefined): ApplePlatform | undefined {
|
||||
if (v === undefined || v === '') return undefined;
|
||||
const k = v.toLowerCase().replace(/[^a-z]/g, '');
|
||||
if (['ios', 'ipados', 'iphone', 'ipad'].includes(k)) return 'IOS';
|
||||
if (['macos', 'mac', 'osx', 'macosx'].includes(k)) return 'MAC_OS';
|
||||
if (['tvos', 'appletv', 'tv'].includes(k)) return 'TV_OS';
|
||||
if (['visionos', 'vision', 'xros', 'visionpro'].includes(k)) return 'VISION_OS';
|
||||
throw new Error(`--platform ${v}: one of ios, macos, tvos, visionos`);
|
||||
}
|
||||
|
||||
interface Row { id?: string; attributes: Record<string, unknown> }
|
||||
/** The platform of a version row (rows without one are iOS, as App Store Connect answered before it had others). */
|
||||
export const platformOf = (r: Row): ApplePlatform => (APPLE_PLATFORMS as readonly string[]).includes(String(r.attributes.platform)) ? r.attributes.platform as ApplePlatform : 'IOS';
|
||||
export const stateOfRow = (r: Row): string => String(r.attributes.appVersionState ?? r.attributes.appStoreState ?? '');
|
||||
const distinct = (rows: Row[]): ApplePlatform[] => APPLE_PLATFORMS.filter(p => rows.some(r => platformOf(r) === p));
|
||||
|
||||
export interface PlatformPick {
|
||||
platform: ApplePlatform;
|
||||
/** flag: --platform; only: the app has versions on one platform (or none); auto: the one platform with the wanted
|
||||
* version; default: iOS while other platforms exist (said in `note`). */
|
||||
how: 'flag' | 'only' | 'auto' | 'default';
|
||||
note?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Picks the platform a command acts on. `want(row)`: the version the command needs (resubmit: rejected or held by a
|
||||
* submission back from App Review; listing: editable; release: approved / live). `what` names it for the messages
|
||||
* ("a rejected version"). Throws when the wanted version is on more than one platform and no --platform was given. Pure.
|
||||
*/
|
||||
export function pickPlatform(rows: Row[], o: { flag?: ApplePlatform; version?: string; want: (r: Row) => boolean; what: string }): PlatformPick {
|
||||
if (o.flag) return { platform: o.flag, how: 'flag' };
|
||||
const present = distinct(rows);
|
||||
if (present.length <= 1) return { platform: present[0] ?? 'IOS', how: 'only' };
|
||||
const scoped = o.version ? rows.filter(r => r.attributes.versionString === o.version) : rows;
|
||||
const label = `${o.what}${o.version ? ` (${o.version})` : ''}`;
|
||||
const hits = distinct(scoped.filter(o.want));
|
||||
if (hits.length > 1)
|
||||
throw new Error(`${label} on ${hits.map(platformName).join(' and ')}: say which with --platform ${hits.map(platformSlug).join('|')} (storebound apple status lists every version with its platform)`);
|
||||
if (hits.length === 1) return { platform: hits[0]!, how: 'auto', note: `${label} only on ${platformName(hits[0]!)}: acting on ${platformName(hits[0]!)} (--platform ${present.map(platformSlug).join('|')} to choose)` };
|
||||
if (o.version) {
|
||||
const has = distinct(scoped);
|
||||
if (has.length === 1) return { platform: has[0]!, how: 'auto', note: `version ${o.version} only on ${platformName(has[0]!)}: acting on ${platformName(has[0]!)} (--platform to choose)` };
|
||||
}
|
||||
return { platform: 'IOS', how: 'default', note: `the app has versions on ${present.map(platformName).join(', ')}; acting on iOS (--platform ${present.filter(p => p !== 'IOS').map(platformSlug).join('|')} for the other)` };
|
||||
}
|
||||
|
||||
/** Version rows of one platform. */
|
||||
export const onPlatform = <T extends Row>(rows: T[], p: ApplePlatform): T[] => rows.filter(r => platformOf(r) === p);
|
||||
Loading…
Add table
Add a link
Reference in a new issue