serve: app-centric portfolio (apps across iOS / Android, release trains, catalog parity) and local tool detection
- portfolio.status returns apps: identity with both platforms, offline config check, release trains (current = highest version live on a store, next = highest above it; per-store phase, build, rollout fraction) and catalog parity (config vs both stores) when live - inspect --json adds product ids and the subscription count - system.tools: ffmpeg, ffprobe, Chrome / Chrome for Testing, Xcode tools, simctl, adb, git with versions and source; STOREBOUND_TOOL_PATH (front of PATH for every command) and STOREBOUND_CHROME (Playwright executablePath) let the desktop app hand over its own copies
This commit is contained in:
parent
3454a9aadb
commit
347fcc3cca
10 changed files with 393 additions and 35 deletions
|
|
@ -78,22 +78,72 @@ export interface ProjectSummary {
|
|||
languages: string[];
|
||||
play: { packageName: string } | null;
|
||||
apple: { bundleId: string; appId: string | null } | null;
|
||||
/** One-time in-app products in the config (shared by both stores). */
|
||||
products: number;
|
||||
productIds: string[];
|
||||
/** Subscriptions in the config (0 until the config defines them). */
|
||||
subscriptions: number;
|
||||
shots: boolean;
|
||||
testflightGroups: number;
|
||||
}
|
||||
|
||||
// ---- App-centric model (one app = one product on up to two platforms; a workspace holds many apps) ----
|
||||
|
||||
/** One product across platforms. id = its project folder (one storebound.config.ts per app). */
|
||||
export interface AppIdentity {
|
||||
id: string;
|
||||
name: string;
|
||||
platforms: { ios: { bundleId: string; ascAppId: string | null } | null; android: { packageName: string } | null };
|
||||
}
|
||||
|
||||
/** Where a version is on one store. */
|
||||
export type ReleasePhase = 'live' | 'rollout' | 'halted' | 'approved' | 'review' | 'rejected' | 'testing' | 'draft' | 'other';
|
||||
|
||||
export interface StoreRelease {
|
||||
store: 'ios' | 'android';
|
||||
version: string | null;
|
||||
/** iOS build number (CFBundleVersion) / highest Android versionCode. */
|
||||
build: string | null;
|
||||
/** The store's own state word (READY_FOR_SALE, inProgress ...). */
|
||||
state: string;
|
||||
phase: ReleasePhase;
|
||||
/** Android staged rollout user fraction (0-1); iOS phased release percentage comes with D2. */
|
||||
fraction: number | null;
|
||||
/** Android track (production, beta, internal ...). */
|
||||
track: string | null;
|
||||
}
|
||||
|
||||
/** A release train: one version (e.g. 2.3.0) across both stores. */
|
||||
export interface ReleaseTrain { version: string; ios: StoreRelease | null; android: StoreRelease | null }
|
||||
|
||||
/** In-app catalog parity between the config and both stores. */
|
||||
export interface CatalogParity {
|
||||
checked: 'config' | 'live';
|
||||
products: number;
|
||||
subscriptions: number;
|
||||
/** Live: ids on one store only, and config ids missing on a store the app is on. */
|
||||
onlyIos: string[];
|
||||
onlyAndroid: string[];
|
||||
missingIos: string[];
|
||||
missingAndroid: string[];
|
||||
ok: boolean;
|
||||
}
|
||||
|
||||
export interface PortfolioParams { projects: string[]; live?: boolean; credentials?: Credentials }
|
||||
|
||||
export interface PortfolioEntry {
|
||||
export interface AppStatus {
|
||||
/** Project folder as given. */
|
||||
project: string;
|
||||
ok: boolean;
|
||||
app: AppIdentity | null;
|
||||
summary: ProjectSummary | null;
|
||||
check: { ok: boolean; problems: string[]; warnings: string[] } | null;
|
||||
/** live only: `apple status --json` / `play status --json` data, or the error text. */
|
||||
apple?: { data?: unknown; error?: string };
|
||||
play?: { data?: unknown; error?: string };
|
||||
/** Release trains; `source: none` offline (no store data read). */
|
||||
release: { source: 'none' | 'live'; current: ReleaseTrain | null; next: ReleaseTrain | null };
|
||||
catalog: CatalogParity | null;
|
||||
/** live only: per-platform read errors ("unknown, never false"). */
|
||||
storeErrors: { ios?: string; android?: string };
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
export interface PortfolioResult { projects: PortfolioEntry[]; at: string }
|
||||
export interface PortfolioResult { apps: AppStatus[]; at: string }
|
||||
|
|
|
|||
100
cli/lib/portfolio.ts
Normal file
100
cli/lib/portfolio.ts
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
// Pure pieces of `portfolio.status` (serve.ts): an app's identity across platforms, its release trains (one version
|
||||
// across the App Store and Google Play) and the in-app catalog parity between the config and both stores.
|
||||
// Inputs are the `apple status --json` / `play status --json` results, read defensively: "unknown, never false".
|
||||
import type { AppIdentity, CatalogParity, ProjectSummary, ReleasePhase, ReleaseTrain, StoreRelease } from './desktop-protocol';
|
||||
|
||||
type J = Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
export function appIdentity(s: ProjectSummary): AppIdentity {
|
||||
return {
|
||||
id: s.dir,
|
||||
name: s.name,
|
||||
platforms: {
|
||||
ios: s.apple ? { bundleId: s.apple.bundleId, ascAppId: s.apple.appId } : null,
|
||||
android: s.play ? { packageName: s.play.packageName } : null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Numeric compare of dotted versions ("2.10.0" > "2.9.1"); non-numeric parts compare as 0. */
|
||||
export function cmpVersion(a: string, b: string): number {
|
||||
const pa = a.split('.').map(x => parseInt(x, 10) || 0), pb = b.split('.').map(x => parseInt(x, 10) || 0);
|
||||
for (let i = 0; i < Math.max(pa.length, pb.length); i++) { const d = (pa[i] ?? 0) - (pb[i] ?? 0); if (d) return d; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** App Store version states (appStoreState / appVersionState) -> phase. */
|
||||
export function applePhase(state: string): ReleasePhase {
|
||||
if (/^(READY_FOR_SALE|READY_FOR_DISTRIBUTION)$/.test(state)) return 'live';
|
||||
if (/^(PENDING_DEVELOPER_RELEASE|PENDING_APPLE_RELEASE|ACCEPTED)$/.test(state)) return 'approved';
|
||||
if (/^(WAITING_FOR_REVIEW|IN_REVIEW|WAITING_FOR_EXPORT_COMPLIANCE|PROCESSING_FOR_DISTRIBUTION|PROCESSING_FOR_APP_STORE)$/.test(state)) return 'review';
|
||||
if (/REJECTED$/.test(state)) return 'rejected';
|
||||
if (/^(PREPARE_FOR_SUBMISSION|DEVELOPER_ACTION_NEEDED)$/.test(state)) return 'draft';
|
||||
return 'other';
|
||||
}
|
||||
|
||||
export function appleReleases(data: unknown): StoreRelease[] {
|
||||
const versions = ((data as J)?.versions ?? []) as J[];
|
||||
const builds = new Map((((data as J)?.builds ?? []) as J[]).map(b => [b.id, b.attributes?.version] as const));
|
||||
return versions.filter(v => typeof v?.attributes?.versionString === 'string' && (v.attributes.platform ?? 'IOS') === 'IOS').map(v => {
|
||||
const state = String(v.attributes.appVersionState ?? v.attributes.appStoreState ?? 'UNKNOWN');
|
||||
const buildId = v.relationships?.build?.data?.id;
|
||||
return { store: 'ios', version: v.attributes.versionString as string, build: (buildId && builds.get(buildId)) ? String(builds.get(buildId)) : null, state, phase: applePhase(state), fraction: null, track: null };
|
||||
});
|
||||
}
|
||||
|
||||
/** Leading dotted version of a Play release name ("2.3.0 (45)" -> "2.3.0"). */
|
||||
export const versionOfName = (name: unknown): string | null => (typeof name === 'string' ? name.match(/\d+(?:\.\d+){0,3}/)?.[0] ?? null : null);
|
||||
|
||||
export function playReleases(data: unknown): StoreRelease[] {
|
||||
const out: StoreRelease[] = [];
|
||||
for (const t of ((data as J)?.tracks ?? []) as J[]) {
|
||||
for (const r of (t?.releases ?? []) as J[]) {
|
||||
const codes = ((r.versionCodes ?? []) as unknown[]).map(Number).filter(Number.isFinite);
|
||||
const production = t.track === 'production';
|
||||
const status = String(r.status ?? 'unknown');
|
||||
const phase: ReleasePhase = !production ? (status === 'draft' ? 'draft' : 'testing')
|
||||
: status === 'completed' ? 'live' : status === 'inProgress' ? 'rollout' : status === 'halted' ? 'halted' : status === 'draft' ? 'draft' : 'other';
|
||||
out.push({ store: 'android', version: versionOfName(r.name), build: codes.length ? String(Math.max(...codes)) : null, state: status, phase, fraction: typeof r.userFraction === 'number' ? r.userFraction : null, track: String(t.track) });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const PHASE_RANK: Record<ReleasePhase, number> = { live: 0, rollout: 1, halted: 2, approved: 3, review: 4, rejected: 5, testing: 6, draft: 7, other: 8 };
|
||||
const pick = (rs: StoreRelease[]): StoreRelease | null => [...rs].sort((a, b) => PHASE_RANK[a.phase] - PHASE_RANK[b.phase])[0] ?? null;
|
||||
|
||||
/**
|
||||
* Release trains: one version across both stores. current = the highest version that is live (fully) on a store;
|
||||
* next = the highest version above it on either store (review, testing, rollout, draft ...). A store without that
|
||||
* version has null in the train.
|
||||
*/
|
||||
export function releaseTrains(ios: StoreRelease[], android: StoreRelease[]): { current: ReleaseTrain | null; next: ReleaseTrain | null } {
|
||||
const all = [...ios, ...android].filter((r): r is StoreRelease & { version: string } => !!r.version);
|
||||
const train = (v: string): ReleaseTrain => ({ version: v, ios: pick(all.filter(r => r.store === 'ios' && r.version === v)), android: pick(all.filter(r => r.store === 'android' && r.version === v)) });
|
||||
const live = all.filter(r => r.phase === 'live').map(r => r.version).sort(cmpVersion).at(-1) ?? null;
|
||||
const above = all.filter(r => !live || cmpVersion(r.version, live) > 0).map(r => r.version).sort(cmpVersion).at(-1) ?? null;
|
||||
return { current: live ? train(live) : null, next: above ? train(above) : null };
|
||||
}
|
||||
|
||||
/** Product ids on App Store Connect (`apple status --json` iaps) and Google Play (`play status --json` products). */
|
||||
export const appleProductIds = (data: unknown): string[] => (((data as J)?.iaps ?? []) as J[]).map(p => p?.attributes?.productId).filter((x): x is string => typeof x === 'string');
|
||||
export const playProductIds = (data: unknown): string[] => (((data as J)?.products ?? []) as J[]).map(p => p?.productId ?? p?.sku).filter((x): x is string => typeof x === 'string');
|
||||
|
||||
/**
|
||||
* Catalog parity. Without store data (offline) only the config side is known. With it: ids only on one store,
|
||||
* and config ids missing from a store the app is on.
|
||||
*/
|
||||
export function catalogParity(s: ProjectSummary, apple?: string[], play?: string[]): CatalogParity {
|
||||
const ids = s.productIds;
|
||||
const live = apple !== undefined || play !== undefined;
|
||||
const onlyIos = apple && play ? apple.filter(x => !play.includes(x)) : [];
|
||||
const onlyAndroid = apple && play ? play.filter(x => !apple.includes(x)) : [];
|
||||
const missingIos = s.apple && apple ? ids.filter(x => !apple.includes(x)) : [];
|
||||
const missingAndroid = s.play && play ? ids.filter(x => !play.includes(x)) : [];
|
||||
return {
|
||||
checked: live ? 'live' : 'config', products: s.products, subscriptions: s.subscriptions,
|
||||
onlyIos, onlyAndroid, missingIos, missingAndroid,
|
||||
ok: !onlyIos.length && !onlyAndroid.length && !missingIos.length && !missingAndroid.length,
|
||||
};
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
// binary re-executes itself. Output is streamed line by line (progress) and the `--json` result line is picked out.
|
||||
import { join } from 'node:path';
|
||||
import { RESULT_MARK } from './log';
|
||||
import { toolPath } from './tools';
|
||||
|
||||
/** True inside a `bun build --compile` executable (the entry module lives in Bun's embedded file system). */
|
||||
export const compiled = (): boolean => /^(\/\$bunfs\/|[A-Z]:[\\/]~BUN[\\/])/.test(Bun.main);
|
||||
|
|
@ -39,6 +40,8 @@ export function pickCallEnv(env: Record<string, unknown> | undefined): Record<st
|
|||
export function childEnv(extra: Record<string, string> = {}, machine = false): Record<string, string> {
|
||||
const base: Record<string, string> = {};
|
||||
for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !k.startsWith('STOREBOUND_SESSION')) base[k] = v;
|
||||
// app-managed tools (desktop data folder) come first on PATH
|
||||
if (base.STOREBOUND_TOOL_PATH) base.PATH = toolPath(base);
|
||||
return { ...base, ...extra, NO_COLOR: '1', ...(machine ? { STOREBOUND_MACHINE: '1', STOREBOUND_SERVE: '1' } : {}) };
|
||||
}
|
||||
|
||||
|
|
|
|||
90
cli/lib/tools.ts
Normal file
90
cli/lib/tools.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
// Optional local tools storebound uses (screenshots, previews, icons, simulator and emulator captures), found on this
|
||||
// machine with their versions. The desktop app can manage its own copies of ffmpeg and Chrome for Testing in its data
|
||||
// folder and points storebound at them:
|
||||
// STOREBOUND_TOOL_PATH folders put in front of PATH for every command (app-managed ffmpeg / ffprobe)
|
||||
// STOREBOUND_CHROME Chrome / Chrome for Testing executable for renders and web captures
|
||||
// Nothing is installed system-wide. Sources and licenses: docs/desktop.md.
|
||||
import { existsSync } from 'node:fs';
|
||||
import { delimiter, join } from 'node:path';
|
||||
|
||||
export type ToolId = 'ffmpeg' | 'ffprobe' | 'chrome' | 'xcode' | 'simctl' | 'adb' | 'git';
|
||||
|
||||
export interface ToolStatus {
|
||||
id: ToolId;
|
||||
name: string;
|
||||
found: boolean;
|
||||
path: string | null;
|
||||
version: string | null;
|
||||
/** 'app' = the desktop app's own copy (STOREBOUND_TOOL_PATH / STOREBOUND_CHROME), 'system' = installed by the user. */
|
||||
source: 'app' | 'system' | null;
|
||||
/** What needs it. */
|
||||
usedFor: string;
|
||||
/** How to get it: the desktop app downloads ffmpeg and Chrome for Testing; Xcode and the Android SDK are link-out. */
|
||||
install: { kind: 'download' | 'link'; url: string; note: string };
|
||||
}
|
||||
|
||||
/** PATH with the app-managed tool folders first. */
|
||||
export function toolPath(env: Record<string, string | undefined> = process.env): string {
|
||||
const extra = (env.STOREBOUND_TOOL_PATH ?? '').split(delimiter).filter(Boolean);
|
||||
return [...extra, env.PATH ?? ''].filter(Boolean).join(delimiter);
|
||||
}
|
||||
|
||||
/** First line of `<cmd> <args>` (version banners), or null. */
|
||||
function firstLine(cmd: string[], env: Record<string, string>): string | null {
|
||||
try {
|
||||
const r = Bun.spawnSync(cmd, { stdout: 'pipe', stderr: 'pipe', env, timeout: 5_000 });
|
||||
if (r.exitCode !== 0) return null;
|
||||
return (r.stdout.toString() || r.stderr.toString()).trim().split('\n')[0]?.trim() || null;
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
/** "ffmpeg version 7.1.1 Copyright ..." -> "7.1.1"; "Google Chrome for Testing 131.0.6778.85" -> "131.0.6778.85". */
|
||||
export function parseVersion(line: string | null): string | null {
|
||||
if (!line) return null;
|
||||
return line.match(/version\s+([^\s,]+)/i)?.[1] ?? line.match(/(\d+(?:\.\d+)+)/)?.[1] ?? null;
|
||||
}
|
||||
|
||||
export function systemChrome(platform = process.platform, env: Record<string, string | undefined> = process.env): string | null {
|
||||
const c = platform === 'darwin' ? ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome']
|
||||
: platform === 'win32' ? [env.PROGRAMFILES, env['PROGRAMFILES(X86)'], env.LOCALAPPDATA].filter((d): d is string => !!d).map(d => join(d, 'Google/Chrome/Application/chrome.exe'))
|
||||
: ['/usr/bin/google-chrome', '/usr/bin/google-chrome-stable', '/usr/bin/chromium', '/usr/bin/chromium-browser'];
|
||||
return c.find(p => existsSync(p)) ?? null;
|
||||
}
|
||||
|
||||
const FFMPEG_NOTE = 'Static build into the app data folder (GPL; never bundled with the app). Checksum-verified.';
|
||||
|
||||
export function detectTools(env: Record<string, string | undefined> = process.env): ToolStatus[] {
|
||||
const PATH = toolPath(env);
|
||||
const spawnEnv: Record<string, string> = { ...Object.fromEntries(Object.entries(env).filter((e): e is [string, string] => e[1] !== undefined)), PATH };
|
||||
const appDirs = (env.STOREBOUND_TOOL_PATH ?? '').split(delimiter).filter(Boolean);
|
||||
const which = (n: string): string | null => Bun.which(n, { PATH });
|
||||
const src = (p: string | null): ToolStatus['source'] => (!p ? null : appDirs.some(d => p.startsWith(d)) ? 'app' : 'system');
|
||||
const bin = (id: ToolId, name: string, usedFor: string, install: ToolStatus['install'], versionArgs: string[]): ToolStatus => {
|
||||
const path = which(id);
|
||||
const version = path ? parseVersion(firstLine([path, ...versionArgs], spawnEnv)) : null;
|
||||
return { id, name, found: !!path, path, version, source: src(path), usedFor, install };
|
||||
};
|
||||
const out: ToolStatus[] = [
|
||||
bin('ffmpeg', 'ffmpeg', 'icons, screenshot renders, app preview videos, frame crops', { kind: 'download', url: 'https://ffmpeg.org/download.html', note: FFMPEG_NOTE }, ['-version']),
|
||||
bin('ffprobe', 'ffprobe', 'checks of app preview videos and clips', { kind: 'download', url: 'https://ffmpeg.org/download.html', note: 'Comes with the ffmpeg download.' }, ['-version']),
|
||||
];
|
||||
const appChrome = env.STOREBOUND_CHROME && existsSync(env.STOREBOUND_CHROME) ? env.STOREBOUND_CHROME : null;
|
||||
const chrome = appChrome ?? systemChrome(process.platform, env);
|
||||
out.push({
|
||||
id: 'chrome', name: appChrome ? 'Chrome for Testing' : 'Google Chrome', found: !!chrome, path: chrome,
|
||||
version: chrome ? parseVersion(firstLine([chrome, '--version'], spawnEnv)) : null, source: appChrome ? 'app' : chrome ? 'system' : null,
|
||||
usedFor: 'screenshot renders, captions, web captures and recordings',
|
||||
install: { kind: 'download', url: 'https://googlechromelabs.github.io/chrome-for-testing/', note: 'Chrome for Testing from Google\'s official endpoints into the app data folder.' },
|
||||
});
|
||||
if (process.platform === 'darwin') {
|
||||
const dev = firstLine(['xcode-select', '-p'], spawnEnv);
|
||||
out.push({ id: 'xcode', name: 'Xcode command line tools', found: !!dev, path: dev, version: parseVersion(firstLine(['xcodebuild', '-version'], spawnEnv)), source: dev ? 'system' : null,
|
||||
usedFor: 'iOS builds, the iOS Simulator (simctl)', install: { kind: 'link', url: 'https://developer.apple.com/xcode/', note: 'Install Xcode from the App Store or developer.apple.com.' } });
|
||||
const simctl = firstLine(['xcrun', '--find', 'simctl'], spawnEnv);
|
||||
out.push({ id: 'simctl', name: 'simctl (iOS Simulator)', found: !!simctl, path: simctl, version: null, source: simctl ? 'system' : null,
|
||||
usedFor: 'iOS Simulator screenshots and recordings', install: { kind: 'link', url: 'https://developer.apple.com/xcode/', note: 'Part of Xcode.' } });
|
||||
}
|
||||
out.push(bin('adb', 'adb (Android platform tools)', 'Android emulator / device screenshots and recordings', { kind: 'link', url: 'https://developer.android.com/tools/releases/platform-tools', note: 'Install Android Studio or the SDK platform tools.' }, ['version']));
|
||||
out.push(bin('git', 'git', 'release notes from history, analytics compare', { kind: 'link', url: 'https://git-scm.com/downloads', note: 'Install git from your OS package manager.' }, ['--version']));
|
||||
return out;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue