37 lines
1.7 KiB
TypeScript
37 lines
1.7 KiB
TypeScript
// Copies the templates into the current project without overwriting anything, and makes sure .crt-ship/ is ignored.
|
|
// crt-ship 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][] = [
|
|
['crt-ship.config.ts', 'crt-ship.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', '.crt-ship/credentials.json'],
|
|
];
|
|
|
|
export async function run(args: Args): Promise<void> {
|
|
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 (!/^\/?\.crt-ship\/?$/m.test(cur)) {
|
|
if (cur) appendFileSync(gi, `${cur.endsWith('\n') ? '' : '\n'}# crt-ship: credentials, fonts, temp files\n.crt-ship/\n`);
|
|
else writeFileSync(gi, '# crt-ship: credentials, fonts, temp files\n.crt-ship/\n');
|
|
log('init', '.gitignore: added .crt-ship/');
|
|
}
|
|
log('init', 'next: edit crt-ship.config.ts and .crt-ship/credentials.json, then `crt-ship check`');
|
|
}
|