Files
ipal-kit/src/modules/starter/prompts.ts
T
Radosław SmolińskiandClaude Opus 5.5 804a09efed Project starter: ipal-kit create <domain> generates a new site from the reference site
- bin `ipal-kit` (subcommand `create`): the architecture questions (or --answers JSON),
  rendering from reference/ through starter.manifest.json (placeholders, @starter:if variants,
  //: alternatives, demo dropped), answers into AGENTS.md "Project decisions" and ipal-doctor.json,
  local .env with a fresh PAYLOAD_SECRET, install from the shipped lockfile, ipal-skills,
  ipal-tokens, generate:types/importmap, typecheck, ipal-doctor when shipped, secret check,
  first commit
- @intecion/ipal-kit/starter: the building blocks (renderSite, validateAnswers, applyVariants,
  collectBundle, lockfileWithoutPlugin, secretFindings …)
- build:starter packs reference/ into dist/starter/template.json.gz (90 KB);
  starter:gate in prepublishOnly: site from the packed tarball, frozen install, seed, build,
  targeted SEED_ONLY seed in production mode, full seed refused, pnpm start checks
- D15: plugin dependencies pinned exactly (nodemailer 10.3.1)
- reference/: @starter:if markers (runs as before), manifest generate/variants/rewrite
- docs: project-starter.md, AGENT.md, ipal-setup, ipal-site, ipal-reference (+ api.md),
  README, PROGRAMISTA §2, CHANGELOG, docs/README, reference index

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 15:50:44 +01:00

107 lines
6.6 KiB
TypeScript

/**
* The architecture questions asked in the terminal, all before a single file is written.
* Enter takes the shown recommendation — an explicit choice, recorded as the owner's answer.
* Agents pass the same answers as JSON with `--answers` instead.
*/
import { createInterface } from 'node:readline/promises'
import type { AnalyticsTool, ContentCollection, StarterAnswers } from './answers.js'
type Ask = (question: string) => Promise<string>
function asker(ask: Ask) {
const text = async (question: string, recommended?: string): Promise<string> => {
for (;;) {
const answer = (await ask(`${question}${recommended ? ` [${recommended}]` : ''}: `)).trim()
if (answer) {return answer}
if (recommended !== undefined) {return recommended}
}
}
const choice = async <T extends string>(question: string, options: readonly T[], recommended: T): Promise<T> => {
for (;;) {
const answer = await text(`${question} (${options.join(' / ')})`, recommended)
if ((options as readonly string[]).includes(answer)) {return answer as T}
}
}
const yes = async (question: string, recommended: boolean) => (await choice(question, ['yes', 'no'] as const, recommended ? 'yes' : 'no')) === 'yes'
const list = async (question: string, recommended: string): Promise<string[]> =>
(await text(`${question} (comma-separated, "none" for none)`, recommended)).split(',').map((s) => s.trim()).filter((s) => s && s !== 'none')
return { choice, list, text, yes }
}
/** Asks every topic of AGENT.md "Ask before you build" and returns the answers (not yet validated). */
export async function askAnswers(ask: Ask): Promise<StarterAnswers> {
const { choice, list, text, yes } = asker(ask)
const siteName = await text('1. Site / company name (also the 2FA issuer)')
const market = await text(' Market', 'PL')
const industry = await text(' Industry, one line')
const extra = await list('2. Languages besides pl (default) and en, as code:Label', 'none')
const locales = [{ code: 'pl', label: 'Polski' }, { code: 'en', label: 'English' }, ...extra.map((e) => {
const [code = '', label = code] = e.split(':').map((s) => s.trim())
return { code, label }
})]
const primary = await text('3. Brand primary colour (any CSS colour)')
const secondary = await text(' Secondary colour ("none")', 'none')
const accent = await text(' Accent colour ("none")', 'none')
const fontBody = await text(' Body font (Google font name)', 'Inter')
const fontHeading = await text(' Heading font (Google font name)', fontBody)
const theme = await choice(' Theme', ['both', 'light', 'dark'] as const, 'both')
const defaultTheme = theme === 'both' ? await choice(' Default theme', ['system', 'light', 'dark'] as const, 'system') : theme
const radius = await choice(' Corner style', ['sharp', 'soft', 'round'] as const, 'soft')
const fluid = await choice(' Scale (standard = to 1280px, wide = to 1920px)', ['wide', 'standard'] as const, 'wide')
const pages = await list('4. Pages (site map)', 'Home, About, Services, Contact, Privacy policy, Cookie policy')
const collections = (await list(' Collections with their own URLs: posts, caseStudies', 'none')) as ContentCollection[]
const forms = await list('5. Forms', 'Contact form')
const recipient = await text(' Inbox that receives submissions')
const transport = await choice(' E-mail transport', ['smtp', 'graph'] as const, 'smtp')
const tools = (await list('6. Analytics: ga4, gtm, metaPixel, linkedIn, tiktok, clarity', 'ga4')) as AnalyticsTool[]
const consentMode = await choice(' Consent Mode', ['advanced', 'basic'] as const, 'advanced')
const banner = await choice(' Cookie settings window', ['detailed', 'modal', 'inline'] as const, 'detailed')
const cookieScanner = await yes(' Cookie scanner', true)
const cookieScannerOffReason = cookieScanner ? undefined : await text(' Why off (owner\'s reason)')
const crawl = cookieScanner ? await yes(' Browser crawl through the shared cookie-crawler service', true) : false
const localBusiness = await yes('7. Local business (address, opening hours in JSON-LD)', true)
const businessType = localBusiness ? await text(' schema.org type', 'ProfessionalService') : ''
const aiBots = await choice(' AI crawlers', ['allow', 'block-training', 'disallow'] as const, 'allow')
const aiBotsReason = aiBots === 'allow' ? undefined : await text(' Client decision behind it')
const media = await choice('8. Media', ['r2', 'local'] as const, 'r2')
const twoFactor = await yes('9. 2FA for the panel', true)
const twoFactorOffReason = twoFactor ? undefined : await text(' Why off (owner\'s reason)')
const whiteLabel = await yes(' White-label (client brand in the panel)', true)
const agencyChoice = await choice(' Agency credit', ['intecion', 'none', 'other'] as const, 'intecion')
const agency = agencyChoice === 'other' ? { name: await text(' Agency name'), url: await text(' Agency URL (https://…)') } : agencyChoice
const adminMeta = await yes(' Panel link preview (adminMeta)', true)
const adminMetaOffReason = adminMeta ? undefined : await text(' Why off (owner\'s reason)')
const canonical = await choice('10. Canonical host', ['apex', 'www'] as const, 'apex')
const coolify = await text(' Coolify server / project')
const dns = await text(' Who adds the DNS records', 'the team')
const external = await list('11. External skills (ext-react-best-practices, ext-composition-patterns, ext-accessibility, ext-frontend-design, ext-payload)', 'none')
const optional = (value: string) => (value === 'none' ? undefined : value)
return {
admin: { adminMeta, adminMetaOffReason, agency, twoFactor, twoFactorOffReason, whiteLabel },
consent: { banner, consentMode, cookieScanner, cookieScannerOffReason, crawl, tools },
content: { collections, pages },
forms: { list: forms, recipient, transport },
hosting: { canonical, coolify, dns },
industry,
languages: { default: 'pl', locales },
market,
media,
seo: { aiBots, aiBotsReason, localBusiness: localBusiness ? { type: businessType } : false },
siteName,
styling: { accent: optional(accent), defaultTheme, fluid, fontBody, fontHeading, primary, radius, secondary: optional(secondary), theme },
tooling: { external },
}
}
/** Runs the questions on stdin/stdout. */
export async function askInTerminal(): Promise<StarterAnswers> {
const rl = createInterface({ input: process.stdin, output: process.stdout })
try {
process.stdout.write('Architecture questions (AGENT.md "Ask before you build"). Enter = the recommendation in [brackets].\n\n')
return await askAnswers((q) => rl.question(q))
} finally {
rl.close()
}
}