storebound/cli/lib/plist.ts
CRT 9d0af72806 Store operations: TestFlight wait / expire, IAP review submissions, listing pulls, release notes per language, offers, custom product pages, in-app events, reports, triage, keyword ranks, AdAttributionKit scan
- apple testflight wait --build N (progress, timeout, exit 0/1/7) and expire --keep N | --older-than D (dry run, asks)
- apple iap-submit: IAP / subscription / group versions into a review submission; first of a type only with the app
  version (--with-version), --no-submit keeps the draft; read-only MCP plan
- apple listing pull, play listing pull (diff, --write), catalog pull (config proposal, never rewritten)
- whats-new --languages / check / apply: one file per language, agent or hook translation, per-store limits
- apple offer-codes, win-back, promoted, preorder; Play pre-registration as a guide (no API)
- apple cpp and apple events: list, create, upload, submit (asks)
- reports: Apple sales / finance, Play earnings / sales into .storebound/reports with summary and CSV
- triage: TestFlight crash / feedback and Play error reports grouped by signature, device, OS
- aso rank: iTunes Search API ranks and competitors, rate limited
- ads scan: AdAttributionKit / SKAdNetwork Info.plist and source checks
- tests against recorded, sanitized answers; skills, README, CHANGELOG
2026-10-11 15:58:17 +00:00

56 lines
2.7 KiB
TypeScript

// Minimal XML property list reader (Info.plist as Xcode writes it): dict, array, string, integer, real, true, false,
// date, data. No dependency; binary plists are reported, not read (a source Info.plist is XML). Pure.
export type PlistValue = string | number | boolean | PlistValue[] | { [k: string]: PlistValue } | null;
const unescape = (s: string): string => s.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&#(\d+);/g, (_m, d: string) => String.fromCodePoint(Number(d))).replace(/&amp;/g, '&');
export function parsePlist(xml: string): PlistValue {
if (xml.startsWith('bplist')) throw new Error('binary plist: convert it with `plutil -convert xml1` first');
const tokens = [...xml.replace(/<\?xml[^>]*\?>|<!DOCTYPE[^>]*>|<!--[\s\S]*?-->/g, '').matchAll(/<(\/?)([A-Za-z]+)(?:\s[^>]*?)?(\/)?>|([^<]+)/g)];
let i = 0;
const skipText = () => { while (i < tokens.length && tokens[i]![4] !== undefined && !tokens[i]![4]!.trim()) i++; };
const textUntil = (tag: string): string => {
let t = '';
while (i < tokens.length && !(tokens[i]![1] === '/' && tokens[i]![2] === tag)) { t += tokens[i]![4] ?? ''; i++; }
i++;
return unescape(t);
};
const value = (): PlistValue => {
skipText();
const tok = tokens[i++];
if (!tok || tok[4] !== undefined) throw new Error('plist: value expected');
const [, close, tag, selfClose] = tok;
if (close) throw new Error(`plist: unexpected </${tag}>`);
switch (tag) {
case 'plist': { const v = value(); skipText(); if (tokens[i]?.[1] === '/' && tokens[i]?.[2] === 'plist') i++; return v; }
case 'true': return true;
case 'false': return false;
case 'string': return selfClose ? '' : textUntil('string');
case 'date': return textUntil('date');
case 'data': return textUntil('data').replace(/\s+/g, '');
case 'integer': return Number(textUntil('integer').trim());
case 'real': return Number(textUntil('real').trim());
case 'array': {
const out: PlistValue[] = [];
if (selfClose) return out;
for (;;) { skipText(); if (tokens[i]?.[1] === '/' && tokens[i]?.[2] === 'array') { i++; return out; } out.push(value()); }
}
case 'dict': {
const out: { [k: string]: PlistValue } = {};
if (selfClose) return out;
for (;;) {
skipText();
const t = tokens[i];
if (t?.[1] === '/' && t[2] === 'dict') { i++; return out; }
if (t?.[2] !== 'key') throw new Error('plist: <key> expected in <dict>');
i++;
const k = textUntil('key');
out[k] = value();
}
}
default: throw new Error(`plist: unsupported <${tag}>`);
}
};
return value();
}