// Play store listing text + app details in one edit. // crt-ship play listing [--dry] [--only en-US,de-DE] // App details: default language, contact email, website (must be the domain that serves app-ads.txt). // Listings: title, short and full description of every `` section of the listing file. import { readFileSync } from 'node:fs'; import { parsePlayListing } from '../lib/copy'; import type { Ctx } from '../lib/ctx'; import { need } from '../lib/ctx'; import { done, log, step } from '../lib/log'; import { playClient } from './client'; export function readPlayCopy(ctx: Ctx) { const { config, resolve } = ctx.loaded; const file = resolve(config.play?.listing ?? 'store/listing.md'); const only = ctx.args.list('only'); return parsePlayListing(readFileSync(file, 'utf8'), config.app.name).filter(c => !only.length || only.includes(c.lang)); } export async function run(ctx: Ctx): Promise { const { config, root } = ctx.loaded; const pkg = need(config.play?.packageName, 'play.packageName'); const copy = readPlayCopy(ctx); const details = { defaultLanguage: config.play?.defaultLanguage ?? 'en-US', contactEmail: config.app.contactEmail, contactWebsite: config.app.website }; if (!copy.some(c => c.lang === details.defaultLanguage) && !ctx.args.has('only')) throw new Error(`listing has no section for the default language ${details.defaultLanguage}`); log('play', `${copy.length} listings: ${copy.map(c => c.lang).join(', ')}`); const play = await playClient(root, pkg); await play.edit(async id => { await play.call('PUT', `${play.API}/edits/${id}/details`, details); log('play', `details: ${details.defaultLanguage} · ${details.contactEmail} · ${details.contactWebsite}`); for (const [i, c] of copy.entries()) { await play.call('PUT', `${play.API}/edits/${id}/listings/${c.lang}`, { language: c.lang, title: c.title, shortDescription: c.short, fullDescription: c.full }); log('play', step(i + 1, copy.length, c.lang)); } }, { dry: ctx.args.has('dry') }); done('play', 'listing done'); }