// Copies the templates into the current project without overwriting anything, and makes sure .storebound/ is ignored. // storebound init [--dir .] import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import type { Args } from './lib/args'; import { log } from './lib/log'; const T = join(import.meta.dir, '..', 'templates'); 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'], ]; export async function run(args: Args): Promise { const root = resolve(args.str('dir', '.')); 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(join(T, 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 and .storebound/credentials.json, then `storebound check`'); }