storebound/cli/lib/whats-new.ts
CRT 1fc94da443 CLI: store readiness, release management, export compliance, ASO audit, release notes, privacy manifest scan
- validate: read-only App Store Connect + Play report with ordered blockers (exit 1)
- apple release --phased on|pause|resume|complete and --manual-release (asks first)
- apple status --wait-review (exit 0 approved, 1 rejected, 7 timeout), apple next-build, apple encryption
- play rollout --fraction|--halt|--resume|--complete, play next-version-code
- check --aso, whats-new --since <tag>, privacy-manifest --ios <path>, version
- Apple IAP description limit is 45 characters (App Store Connect Help), not 55
- config: apple.usesNonExemptEncryption, apple.screenshotTypes, ads.appAdsTxt
2026-10-10 21:02:55 +08:00

100 lines
4.9 KiB
TypeScript

// Player-facing release notes from commit subjects, and writing them into the two listing files. Pure.
// The draft is a starting point for a human: commit messages are written for developers, notes are for players.
import { len, PLAY_LIMITS } from './copy';
export const NOTES_LIMITS = { play: PLAY_LIMITS.whatsNew, apple: 4000 } as const;
/** Roughly what both stores show before "more" on a phone. */
export const HOOK_CHARS = 170;
const SKIP = /^(chore|ci|build|docs?|test|tests|refactor|style|revert|wip|merge|bump|release|lint|deps?)(\(.+?\))?!?:|^Merge |^v?\d+\.\d+\.\d+$|^Release\b/i;
const KIND: [RegExp, 'new' | 'fix' | 'better'][] = [
[/^feat(\(.+?\))?!?:\s*/i, 'new'],
[/^(fix|bugfix|hotfix)(\(.+?\))?!?:\s*/i, 'fix'],
[/^(perf|improve|ux|ui|balance|content)(\(.+?\))?!?:\s*/i, 'better'],
];
export interface NoteItem { kind: 'new' | 'fix' | 'better'; text: string }
/** Commit subjects -> note items: drops housekeeping, strips conventional prefixes and issue refs, dedupes. */
export function noteItems(subjects: string[]): NoteItem[] {
const out: NoteItem[] = [];
const seen = new Set<string>();
for (const raw of subjects) {
const s = raw.trim();
if (!s || SKIP.test(s) || /\[(skip notes|internal)\]/i.test(s)) continue;
let kind: NoteItem['kind'] = 'better';
let text = s;
for (const [re, k] of KIND) if (re.test(text)) { kind = k; text = text.replace(re, ''); break; }
text = text.replace(/\s*\((#|!)\d+\)\s*$/, '').replace(/\s*(closes|fixes|refs?)\s+#\d+.*$/i, '').trim();
if (!text) continue;
text = kind === 'fix' && !/^fix(ed)?\b/i.test(text) ? `Fixed: ${text[0]!.toLocaleLowerCase() + text.slice(1)}` : text[0]!.toLocaleUpperCase() + text.slice(1);
if (!/[.!?]$/.test(text)) text += '.';
const key = text.toLowerCase();
if (seen.has(key)) continue;
seen.add(key);
out.push({ kind, text });
}
const rank = { new: 0, better: 1, fix: 2 } as const;
return out.sort((a, b) => rank[a.kind] - rank[b.kind]);
}
/** Bullet list under a one-line hook, cut to `limit` characters at a whole line. */
export function formatNotes(items: NoteItem[], o: { hook?: string; limit: number }): string {
const hook = o.hook ?? (items.some(i => i.kind === 'new') ? 'New in this update:' : 'Fixes and polish in this update:');
if (!items.length) return 'Bug fixes and performance improvements.'.slice(0, o.limit);
const lines = [hook, ...items.map(i => `• ${i.text}`)];
let text = '';
for (const l of lines) {
const next = text ? `${text}\n${l}` : l;
if (len(next) > o.limit) break;
text = next;
}
return text;
}
/** Problems with a finished note text for one store. */
export function checkNotes(text: string, store: 'play' | 'apple'): string[] {
const e: string[] = [];
const n = len(text);
if (n > NOTES_LIMITS[store]) e.push(`${n} > ${NOTES_LIMITS[store]} characters`);
const firstBreak = text.indexOf('\n');
const hook = firstBreak < 0 ? text : text.slice(0, firstBreak);
if (len(hook) > HOOK_CHARS) e.push(`first line is ${len(hook)} characters; the part before "more" is about ${HOOK_CHARS}`);
if (/\b(bump|refactor|merge|ci|lint)\b/i.test(text)) e.push('reads like a commit log (bump / refactor / merge ...)');
return e;
}
const fence = (t: string) => '```\n' + t + '\n```';
/** Sets the "What's new" block of every `<!-- play: ... -->` section that contains `lang` (or of all, lang = '*'). */
export function setPlayWhatsNew(md: string, lang: string, text: string): { md: string; changed: string[] } {
const parts = md.split(/^(?=## )/m);
const changed: string[] = [];
const out = parts.map(sec => {
const m = /^<!--\s*play:\s*([^>]+?)\s*-->$/m.exec(sec);
if (!m) return sec;
const codes = m[1]!.split(',').map(s => s.trim());
if (lang !== '*' && !codes.includes(lang)) return sec;
changed.push(...codes);
const re = /(^### [^\n]*(what'?s new|release notes)[^\n]*\n)```[^\n]*\n[\s\S]*?\n```/im;
if (re.test(sec)) return sec.replace(re, (_a, h: string) => h + fence(text));
return sec.replace(/\s*$/, '') + `\n\n### What's new (max 500)\n${fence(text)}\n\n`;
});
return { md: out.join(''), changed };
}
/** Sets `### whatsNew` of one App Store locale section (or of all, locale = '*'). */
export function setAppleWhatsNew(md: string, locale: string, text: string): { md: string; changed: string[] } {
const parts = md.split(/^(?=## )/m);
const changed: string[] = [];
const out = parts.map(sec => {
if (!sec.startsWith('## ')) return sec;
const loc = sec.slice(3).split(/[\s·]/)[0]!.trim();
if (!/^[a-z]{2,3}(-[A-Za-z]{2,4})?$/.test(loc) || (locale !== '*' && loc !== locale)) return sec;
changed.push(loc);
const re = /(^### whatsNew[^\n]*\n)```[^\n]*\n[\s\S]*?\n```/m;
if (re.test(sec)) return sec.replace(re, (_a, h: string) => h + fence(text));
return sec.replace(/\s*$/, '') + `\n\n### whatsNew\n${fence(text)}\n\n`;
});
return { md: out.join(''), changed };
}