Salvaged from wip/shots-pipeline. Pure modules (spec, devices, report, video, check), variant support in render / lib, 13" iPad size and 3:4 template layout. Not all of it is wired into the CLI yet.
61 lines
4 KiB
TypeScript
61 lines
4 KiB
TypeScript
// Local store checks of the renders folder, before any upload:
|
|
// storebound shots check [--lang en,tr] [--variants] [--json]
|
|
// Per image: exact pixel size for its store type, no alpha (both stores), Play: no palette PNG, 8 MB per screenshot.
|
|
// Per set: Play 2-8 phone screenshots, Apple 1-10 per display type, 13" iPad set when apple.ipad, feature graphic.
|
|
// Per app preview: 886x1920 / 1200x1600, H.264, <= 30 fps, 15-30 s, stereo AAC track, <= 500 MB, <= 3 per set.
|
|
// Text overflow flags come from the last `shots render` (report.json). Frames: with capture.source "folder" every frame
|
|
// the scenes use must exist with the right aspect. Exit 1 on any error (warnings do not fail).
|
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import type { ShipConfig } from '../lib/config';
|
|
import type { Ctx } from '../lib/ctx';
|
|
import { log } from '../lib/log';
|
|
import { checkFrames, type FrameIssue } from './devices';
|
|
import { DEFAULT_PHONE, DEFAULT_TABLET, defaultSizes, SIZES } from './lib';
|
|
import { allIssues, requiredSets, type RendersScan, scanRenders } from './report';
|
|
import { imageInfo } from './spec';
|
|
|
|
/** Frame files the scenes (and the feature graphic) use, per language and device class. */
|
|
export function framesNeeded(config: ShipConfig, langs: string[]): { lang: string; device: 'phone' | 'tablet'; name: string }[] {
|
|
const shots = config.shots!;
|
|
const sizes = defaultSizes(config);
|
|
const devices: ('phone' | 'tablet')[] = ['phone', ...(sizes.some(s => SIZES[s]!.device === 'tablet') ? ['tablet' as const] : [])];
|
|
const scene = [...new Set(shots.scenes.flatMap(s => s.frames.map(f => f.src)))];
|
|
const phone = [...new Set([...scene, ...(shots.feature?.frame && sizes.includes('feature') ? [shots.feature.frame] : [])])];
|
|
return langs.flatMap(lang => devices.flatMap(device => (device === 'phone' ? phone : scene).map(name => ({ lang, device, name }))));
|
|
}
|
|
|
|
export function checkFrameFolder(config: ShipConfig, dir: string, langs: string[]): FrameIssue[] {
|
|
const found = new Map<string, { w: number; h: number }>();
|
|
for (const lang of langs) for (const device of ['phone', 'tablet']) {
|
|
const d = join(dir, lang, device);
|
|
if (!existsSync(d)) continue;
|
|
for (const f of readdirSync(d).filter(x => /\.png$/i.test(x))) { const i = imageInfo(readFileSync(join(d, f))); found.set(`${lang}/${device}/${f}`, i); }
|
|
}
|
|
const s = config.shots!;
|
|
return checkFrames(found, framesNeeded(config, langs), { phone: { ...DEFAULT_PHONE, ...s.phone }, tablet: { ...DEFAULT_TABLET, ...s.tablet } });
|
|
}
|
|
|
|
export function scanProject(ctx: Ctx): RendersScan {
|
|
const { config, resolve } = ctx.loaded;
|
|
const langs = ctx.args.list('lang').length ? ctx.args.list('lang') : config.languages.map(l => l.id);
|
|
const dir = resolve(ctx.args.get('src') ?? config.renders ?? config.shots?.out ?? 'store/renders');
|
|
return scanRenders(dir, { langs, variants: Object.keys(config.shots?.variants ?? {}), required: requiredSets(config) });
|
|
}
|
|
|
|
export async function run(ctx: Ctx): Promise<void> {
|
|
const { config, resolve } = ctx.loaded;
|
|
const scan = scanProject(ctx);
|
|
const issues = allIssues(scan);
|
|
const cap = config.shots?.capture;
|
|
const frameIssues = cap?.source === 'folder' ? checkFrameFolder(config, resolve(cap.folder ?? config.shots!.frames), scan.langs) : [];
|
|
if (ctx.args.has('json')) {
|
|
console.log(JSON.stringify({ images: scan.images.length, videos: scan.videos.length, issues, frames: frameIssues }, null, 2));
|
|
} else {
|
|
for (const { where, issue } of issues) console.log(`${issue.level === 'error' ? 'ERROR' : 'warn '} ${where}: ${issue.msg}`);
|
|
for (const f of frameIssues) console.log(`ERROR frames/${f.file}: ${f.msg}`);
|
|
}
|
|
const errors = issues.filter(i => i.issue.level === 'error').length + frameIssues.length;
|
|
log('shots', `checked ${scan.images.length} images, ${scan.videos.length} videos, ${scan.sets.length} sets: ${errors} errors, ${issues.length - issues.filter(i => i.issue.level === 'error').length} warnings`);
|
|
if (errors) process.exitCode = 1;
|
|
}
|