#!/usr/bin/env node import { mkdir, writeFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { parseArgs } from 'node:util' import process from 'node:process' import { buildSite } from './site.js' const HELP = `Usage: pds-cms-render [options] Renders an account's pds-cms content into a static site. Options: -o, --out Output directory (default: site) -t, --title Site title (default: the account's handle) -d, --description <s> Site description -h, --help Show this help ` const { values, positionals } = parseArgs({ options: { out: { type: 'string', short: 'o', default: 'site' }, title: { type: 'string', short: 't' }, description: { type: 'string', short: 'd' }, help: { type: 'boolean', short: 'h' }, }, allowPositionals: true, }) if (values.help || positionals.length !== 1) { console.log(HELP) process.exit(values.help ? 0 : 1) } const actor = positionals[0] console.log(`Fetching content for ${actor}...`) const files = await buildSite(actor, { title: values.title, description: values.description, }) if (files.length === 1) { console.log('Note: no content records found — the site is just an empty index page.') } for (const file of files) { const path = join(values.out, file.path) await mkdir(dirname(path), { recursive: true }) await writeFile(path, file.html) console.log(` wrote ${path}`) } console.log(`Done: ${files.length} page(s) in ${values.out}/`)