crt-ship 0.1.0: CLI, Claude Code skills and templates for shipping mobile games to Google Play and the App Store
This commit is contained in:
commit
ecb3dc3dc3
64 changed files with 4509 additions and 0 deletions
81
cli/lib/copy.ts
Normal file
81
cli/lib/copy.ts
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Store copy lives in two human-edited Markdown files (templates/listing.md, templates/appstore.md). Pure parsers +
|
||||
// limit checks; the consoles count characters (code points), so do we.
|
||||
|
||||
export const PLAY_LIMITS = { title: 30, short: 80, full: 4000, whatsNew: 500 } as const;
|
||||
export const APPLE_LIMITS = { name: 30, subtitle: 30, promotionalText: 170, keywords: 100, description: 4000, whatsNew: 4000 } as const;
|
||||
|
||||
export interface PlayCopy { lang: string; title: string; short: string; full: string; whatsNew: string }
|
||||
export type AppleField = keyof typeof APPLE_LIMITS;
|
||||
export type AppleCopy = Partial<Record<AppleField, string>>;
|
||||
|
||||
export const len = (s: string): number => [...s].length;
|
||||
|
||||
/** "### heading" sub-sections of a "## " section, each with its first fenced block. */
|
||||
function blocks(section: string): { heading: string; text: string }[] {
|
||||
const out: { heading: string; text: string }[] = [];
|
||||
for (const part of section.split(/^### /m).slice(1)) {
|
||||
const heading = part.split('\n')[0]!.trim();
|
||||
const m = /^```[^\n]*\n([\s\S]*?)\n```/m.exec(part);
|
||||
if (m) out.push({ heading, text: m[1]!.trim() });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play copy. Every "## ..." section with a `<!-- play: en-US[, en-GB] -->` line contributes, under "### " headings
|
||||
* that contain (case-insensitive): "title" (optional, defaults to `defaultTitle`), "short", "full", "what's new"
|
||||
* (or "release notes"). One section can serve several Play languages.
|
||||
*/
|
||||
export function parsePlayListing(md: string, defaultTitle: string): PlayCopy[] {
|
||||
const out: PlayCopy[] = [];
|
||||
const errors: string[] = [];
|
||||
for (const sec of md.split(/^## /m).slice(1)) {
|
||||
const m = /^<!--\s*play:\s*([^>]+?)\s*-->$/m.exec(sec);
|
||||
if (!m) continue;
|
||||
const name = sec.split('\n')[0]!.trim();
|
||||
const bs = blocks(sec);
|
||||
const find = (re: RegExp): string | undefined => bs.find(b => re.test(b.heading))?.text;
|
||||
const title = find(/\btitle\b/i) ?? defaultTitle;
|
||||
const short = find(/\bshort\b/i);
|
||||
const full = find(/\bfull\b/i);
|
||||
const whatsNew = find(/what'?s new|release notes/i) ?? '';
|
||||
if (!short) errors.push(`"${name}": no "### ... short ..." block`);
|
||||
if (!full) errors.push(`"${name}": no "### ... full ..." block`);
|
||||
if (!short || !full) continue;
|
||||
for (const lang of m[1]!.split(',').map(s => s.trim()).filter(Boolean)) {
|
||||
const c: PlayCopy = { lang, title, short, full, whatsNew };
|
||||
for (const k of Object.keys(PLAY_LIMITS) as (keyof typeof PLAY_LIMITS)[])
|
||||
if (len(c[k]) > PLAY_LIMITS[k]) errors.push(`${lang}: ${k} is ${len(c[k])} > ${PLAY_LIMITS[k]}`);
|
||||
if (out.some(o => o.lang === lang)) errors.push(`${lang}: listed in two sections`);
|
||||
out.push(c);
|
||||
}
|
||||
}
|
||||
if (errors.length) throw new Error('listing: ' + errors.join('; '));
|
||||
return out;
|
||||
}
|
||||
|
||||
const APPLE_REQUIRED: AppleField[] = ['subtitle', 'promotionalText', 'keywords', 'description'];
|
||||
|
||||
/**
|
||||
* App Store copy. One "## <ASC locale> ..." section per locale (the first word is the locale), with "### <field>"
|
||||
* headings named exactly like the API attributes: name (optional), subtitle, promotionalText, keywords, description,
|
||||
* whatsNew (optional; not allowed on a first version).
|
||||
*/
|
||||
export function parseAppStoreListing(md: string): Record<string, AppleCopy> {
|
||||
const out: Record<string, AppleCopy> = {};
|
||||
const errors: string[] = [];
|
||||
for (const sec of md.split(/^## /m).slice(1)) {
|
||||
const locale = sec.split(/[\s·]/)[0]!.trim();
|
||||
if (!/^[a-z]{2,3}(-[A-Za-z]{2,4})?$/.test(locale)) continue; // prose sections
|
||||
const f: AppleCopy = {};
|
||||
for (const b of blocks(sec)) if (b.heading in APPLE_LIMITS) f[b.heading as AppleField] = b.text;
|
||||
for (const k of APPLE_REQUIRED) if (!f[k]) errors.push(`${locale}: missing ${k}`);
|
||||
for (const [k, v] of Object.entries(f) as [AppleField, string][])
|
||||
if (len(v) > APPLE_LIMITS[k]) errors.push(`${locale}: ${k} is ${len(v)} > ${APPLE_LIMITS[k]}`);
|
||||
if (f.keywords && Buffer.byteLength(f.keywords) > 100) errors.push(`${locale}: keywords are ${Buffer.byteLength(f.keywords)} bytes > 100`);
|
||||
if (f.keywords && /,\s/.test(f.keywords)) errors.push(`${locale}: keywords: no spaces after commas (they count)`);
|
||||
out[locale] = f;
|
||||
}
|
||||
if (errors.length) throw new Error('appstore listing: ' + errors.join('; '));
|
||||
return out;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue