storebound/cli/check.ts

52 lines
3.3 KiB
TypeScript

// Offline sanity check of everything the store commands read: config, both listing files, the screenshot copy, data
// safety answers, product texts vs store limits, and the files the config points at. No network, no credentials.
// storebound check
import { existsSync, readFileSync } from 'node:fs';
import { playCodes } from './lib/config';
import { len, parseAppStoreListing, parsePlayListing } from './lib/copy';
import type { Ctx } from './lib/ctx';
import { dataSafetyRows } from './lib/data-safety';
import { log, warn } from './lib/log';
import { type CopyFile, validateCopy } from './shots/lib';
export async function run(ctx: Ctx): Promise<void> {
const { config, resolve, path } = ctx.loaded;
log('check', `config ok: ${path}`);
const problems: string[] = [];
const tryDo = (what: string, fn: () => string): void => { try { log('check', `${what}: ${fn()}`); } catch (e) { problems.push(`${what}: ${(e as Error).message}`); } };
if (config.play) tryDo('play listing', () => {
const f = resolve(config.play!.listing ?? 'store/listing.md');
const copy = parsePlayListing(readFileSync(f, 'utf8'), config.app.name);
const want = config.languages.flatMap(playCodes);
const missing = want.filter(c => !copy.some(x => x.lang === c));
if (missing.length) warn('check', `play listing has no section for ${missing.join(', ')}`);
return `${copy.length} languages`;
});
if (config.apple) tryDo('appstore listing', () => {
const f = resolve(config.apple!.listing ?? 'store/appstore.md');
const copy = parseAppStoreListing(readFileSync(f, 'utf8'));
const missing = config.languages.filter(l => l.apple && !copy[l.apple]).map(l => l.apple);
if (missing.length) warn('check', `appstore listing has no section for ${missing.join(', ')}`);
return `${Object.keys(copy).length} locales`;
});
if (config.dataSafety) tryDo('data safety', () => `${dataSafetyRows(config.dataSafety!).length - 1} CSV rows`);
for (const p of config.products ?? []) for (const [lang, l] of Object.entries(p.listings)) {
if (config.apple && len(l.description) > 55) problems.push(`product ${p.id} ${lang}: description ${len(l.description)} > 55 (App Store limit)`);
if (len(l.description) > 200) problems.push(`product ${p.id} ${lang}: description ${len(l.description)} > 200 (Play limit)`);
}
if (config.shots) tryDo('shots copy', () => {
const copy = JSON.parse(readFileSync(resolve(config.shots!.copy), 'utf8')) as CopyFile;
const e = validateCopy(copy, config.shots!, config.languages.map(l => l.id));
if (e.length) throw new Error(e.join('; '));
return `${Object.keys(copy).length} languages x ${config.shots!.scenes.length} scenes`;
});
const files = [config.icons?.composite, config.icons?.foreground, config.icons?.background, config.shots?.logo,
...(config.products ?? []).map(p => p.reviewScreenshot)].filter((f): f is string => !!f);
for (const f of new Set(files)) if (!existsSync(resolve(f))) problems.push(`missing file: ${f}`);
if (existsSync(resolve('.gitignore')) && !/^\/?\.storebound\/?$/m.test(readFileSync(resolve('.gitignore'), 'utf8')))
problems.push('.gitignore does not ignore .storebound/ (credentials live there)');
if (problems.length) { for (const p of problems) console.error(` - ${p}`); throw new Error(`${problems.length} problems`); }
log('check', 'all good');
}