// Copies the templates into the current project without overwriting anything, and makes sure .storebound/ is ignored. // storebound init [--dir .] [--profile app|game|subscription-app] // Profiles (default app): app = utility / productivity app with an optional account and analytics, no ads; // game = free-to-play game with ads and in-app purchases (the templates storebound shipped before 0.5.0); // subscription-app = accounts plus auto-renewable subscriptions. Each profile has its own config, declarations, // App Privacy answers, Data safety section, listing copy and screenshot copy; every answer is a starting point to edit. // Lookup per file: templates/profiles//, then the profile it builds on, then templates/. import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import type { Args } from './lib/args'; import { type AppProfile, PROFILES } from './lib/config'; import { log } from './lib/log'; const T = join(import.meta.dir, '..', 'templates'); export const FILES: [string, string][] = [ ['storebound.config.ts', 'storebound.config.ts'], ['listing.md', 'store/listing.md'], ['appstore.md', 'store/appstore.md'], ['shots-copy.json', 'store/shots/copy.json'], ['app-privacy.md', 'store/app-privacy.md'], ['declarations.md', 'store/declarations.md'], ['privacy-policy.html', 'store/privacy-policy.html'], ['credentials.example.json', '.storebound/credentials.json'], ['testers.csv', '.storebound/testers.csv'], ]; /** Template folders a profile reads from, most specific first. game = the root templates. */ const CHAIN: Record = { 'game': [T], 'app': [join(T, 'profiles', 'app'), T], 'subscription-app': [join(T, 'profiles', 'subscription-app'), join(T, 'profiles', 'app'), T], }; /** Source file of one template for a profile. Pure apart from existsSync. */ export function templateFor(profile: AppProfile, name: string): string { for (const dir of CHAIN[profile]) if (existsSync(join(dir, name))) return join(dir, name); throw new Error(`template ${name} not found`); } export async function run(args: Args): Promise { const root = resolve(args.str('dir', '.')); const profile = args.str('profile', 'app') as AppProfile; if (!PROFILES.includes(profile)) throw new Error(`--profile ${profile}: one of ${PROFILES.join(', ')}`); log('init', `profile ${profile} (templates are starting points: edit every answer to match your app)`); for (const [from, to] of FILES) { const dest = join(root, to); if (existsSync(dest)) { log('init', `keep ${to} (exists)`); continue; } mkdirSync(dirname(dest), { recursive: true }); copyFileSync(templateFor(profile, from), dest); log('init', `create ${to}`); } const gi = join(root, '.gitignore'); const cur = existsSync(gi) ? readFileSync(gi, 'utf8') : ''; if (!/^\/?\.storebound\/?$/m.test(cur)) { if (cur) appendFileSync(gi, `${cur.endsWith('\n') ? '' : '\n'}# storebound: credentials, fonts, temp files\n.storebound/\n`); else writeFileSync(gi, '# storebound: credentials, fonts, temp files\n.storebound/\n'); log('init', '.gitignore: added .storebound/'); } log('init', 'next: edit storebound.config.ts, store/*.md and .storebound/credentials.json, then `storebound check`'); }