init --profile app|game|subscription-app (default app): per-profile config, declarations, App Privacy, Data safety, listing and screenshot copy
This commit is contained in:
parent
222a1df9e2
commit
1d8c40dccb
15 changed files with 872 additions and 5 deletions
30
cli/init.ts
30
cli/init.ts
|
|
@ -1,12 +1,18 @@
|
|||
// Copies the templates into the current project without overwriting anything, and makes sure .storebound/ is ignored.
|
||||
// storebound init [--dir .]
|
||||
// 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/<profile>/<file>, then the profile it builds on, then templates/<file>.
|
||||
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');
|
||||
const FILES: [string, string][] = [
|
||||
export const FILES: [string, string][] = [
|
||||
['storebound.config.ts', 'storebound.config.ts'],
|
||||
['listing.md', 'store/listing.md'],
|
||||
['appstore.md', 'store/appstore.md'],
|
||||
|
|
@ -18,13 +24,29 @@ const FILES: [string, string][] = [
|
|||
['testers.csv', '.storebound/testers.csv'],
|
||||
];
|
||||
|
||||
/** Template folders a profile reads from, most specific first. game = the root templates. */
|
||||
const CHAIN: Record<AppProfile, string[]> = {
|
||||
'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<void> {
|
||||
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(join(T, from), dest);
|
||||
copyFileSync(templateFor(profile, from), dest);
|
||||
log('init', `create ${to}`);
|
||||
}
|
||||
const gi = join(root, '.gitignore');
|
||||
|
|
@ -34,5 +56,5 @@ export async function run(args: Args): Promise<void> {
|
|||
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`');
|
||||
log('init', 'next: edit storebound.config.ts, store/*.md and .storebound/credentials.json, then `storebound check`');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue