Files
ipal-kit/docs/project-starter.md
T

221 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# project starter — `iapl create`
One command creates a new Payload 3 + Next 16 client site that already follows every team convention, so
every project starts identical. The site is generated from the **reference site** (`reference/` in the plugin
repo, not shipped as a folder): the same files, with the made-up company's values replaced by the owner's
answers and its demo content left out.
```bash
pnpm --config.auto-install-peers=false dlx @intecion/[email protected] create intecion.com
```
- Always give the version: it pins the templates and therefore every dependency of the new site.
- Run it from the folder that will hold the project, with the `@intecion` registry line in `~/.npmrc`
(README "Installation") — there is no project `.npmrc` yet.
- `--config.auto-install-peers=false` keeps `dlx` to the plugin itself: 7 packages, ~44 MB, ~1 s with a warm
store. Without it pnpm also installs the plugin's peers (Payload, Next, React — 356 packages, ~750 MB in the dlx
cache) that the generator never loads.
- An agent that already has the plugin installed: `pnpm exec iapl create <domain> --dir ../<name>-web`. The
command refuses to write into the current project.
## What it asks — and where the answers go
The architecture questions of AGENT.md "Ask before you build" (the same list as `iapl-setup` stage 0), all before
a single file is written. Enter takes the recommendation shown in brackets — an explicit choice, recorded as the
owner's answer. There is no `--yes`: a missing answer stops the run with the list of open topics.
| Topic | Asked | Goes to |
|---|---|---|
| Site name, market, industry | name (also the 2FA issuer) | `AGENTS.md` header, Site settings and Company (seed), `twoFactor.issuer` |
| Languages | locales besides `pl` (default) and `en` | `src/i18n.config.ts` (every language with a URL prefix) |
| Styling | primary (+ secondary, accent), body and heading font, theme light / dark / both + default, radius sharp / soft / round, fluid standard / wide | `src/design/tokens.ts`, `DESIGN.md`, the next/font calls in the root layout, Site settings → Theme (seed) |
| Pages and content | the site map; collections `posts` / `caseStudies` | `AGENTS.md` → Site map; the collection files, `content.config.ts`, the entry list block, the blog archive page |
| Forms | forms, the inbox that receives them, SMTP or Microsoft Graph | Company → E-mail (seed), the seeded forms, `iaplEnvRules({ emailGraph })` + `GRAPH_*` |
| Analytics and consent | tools, Consent Mode, the settings window, cookie scanner, browser crawl | CSP flags in `next.config.ts`, `SiteProviders analytics` / `banner`, `cookieScanner`, `IAPL_COOKIE_SCAN_*` |
| SEO / GEO | local business (schema.org type), AI crawlers | `siteJsonLd` with `buildLocalBusinessJsonLd`, `robots.aiBots` |
| Media | R2 or local disk | `iaplEnvRules({ storage })`, `docs/DEPLOY.md` (Persistent Storage without R2) |
| Admin | 2FA, white-label, agency credit, panel link preview | `twoFactor`, `whiteLabel`, `agency`, `adminMeta` |
| Hosting | canonical host apex / www, Coolify server, who adds DNS | `NEXT_PUBLIC_SERVER_URL`, `docs/DEPLOY.md` |
| Agent tooling | external skills | `iapl-skills --external` |
A site made by the starter gets the new spelling of the two stored names: `iapl({ storageNames: 'iapl' })` in
`payload.config.ts` (2FA counter key `iapl:2fa-verify:…`; visitor cookie `iapl_vid`, with
`visitorCookie={IAPL_VISITOR_COOKIE}` on `<PageStats>` when statistics are turned on — stats.md). Sites made before
1.17.0 keep the old ones.
Every answer is written into `AGENTS.md` → **Project decisions** (one line per topic) and the full set into
`.iapl/starter.json`. A module the owner turns off needs the owner's reason, which goes into
`iapl-audit-skip:` and `iapl-doctor.json` (`"rules": { "2fa": { "off": true, "reason": "…" } }`).
**Not supported yet — the command stops before writing anything** and points to the manual path (the
`iapl-setup` skill, stages 1–11), which covers them:
- **single-language sites** (owner's decision: later);
- **a default language other than `pl`**, and sites without `en` — the base seed is Polish + English with Polish
default-locale slugs;
- URLs without a language prefix; Postgres (MongoDB only).
Check: `iapl create acme.pl --answers single.json` with one locale exits 1 with "a single-language site is not
supported by `iapl create` yet — set the site up by hand with the iapl-setup skill", and the folder is not created.
For agents and CI, the same answers as JSON (shape: `StarterAnswers`, `@intecion/ipal-kit/starter`):
```bash
pnpm exec iapl create intecion.com --dir ../intecioncom-web --answers answers.json
```
```json
{
"siteName": "Intecion", "market": "PL", "industry": "software house",
"languages": { "default": "pl", "locales": [{ "code": "pl", "label": "Polski" }, { "code": "en", "label": "English" }] },
"styling": { "primary": "oklch(0.5 0.17 250)", "fontBody": "Inter", "fontHeading": "Inter", "theme": "both", "defaultTheme": "system", "radius": "soft", "fluid": "wide" },
"content": { "pages": ["Home", "About", "Services", "Contact"], "collections": ["posts"] },
"forms": { "list": ["Contact form"], "recipient": "[email protected]", "transport": "relay" },
"consent": { "tools": ["ga4"], "consentMode": "advanced", "banner": "detailed", "cookieScanner": true, "crawl": true },
"seo": { "aiBots": "allow", "localBusiness": { "type": "ProfessionalService" } },
"media": "r2",
"admin": { "twoFactor": true, "whiteLabel": true, "agency": "intecion", "adminMeta": true },
"hosting": { "canonical": "apex", "coolify": "coolify-1 / intecion", "dns": "the team" },
"tooling": { "external": [] }
}
```
## Options
| Option | Default | What it does |
|---|---|---|
| `<domain>` | — (required) | the production domain; `https://`, `www.` and a path are stripped, IDN → punycode |
| `--dir <path>` | `./<domain without dots>-web` | target folder; must not exist or be empty |
| `--answers <file>` | — | the answers as JSON, no questions |
| `--external [a,b]` | none | also the vendored `ext-*` skills (all, or the listed ones) |
| `--no-install` | install | write the files only; the report lists the remaining commands |
| `--no-git` | git | no `git init` / first commit |
| `--dry-run` | off | print the file list and the database names, write nothing |
| `--plugin-spec <spec>` | the exact version | install the plugin from another spec — the release gate uses the packed tarball |
## What it does, in order
1. Validates the domain, the folder and every answer — nothing is written while one is missing.
2. Renders the site from the starter bundle (below) and writes it; writes a local `.env` (`.env.example` with a
fresh `PAYLOAD_SECRET`; git-ignored, never committed).
3. `pnpm install` from the shipped lockfile, `pnpm exec iapl-skills` (+ `--external`), `pnpm exec iapl-tokens`
(writes `src/design/tokens.css`, fails on a WCAG contrast error — pick another colour), `pnpm generate:types`,
`pnpm generate:importmap`, `pnpm typecheck`, and `pnpm exec iapl-doctor --strict --offline` when the installed
IAPL ships it.
4. `git init -b main`, a secret check of every staged file (no `.env*` except `.env.example`, no assigned
`*_SECRET` / `*_TOKEN` / `*_PASSWORD` / `*_ACCESS_KEY` value, no private key) and one commit
`chore: create site with iapl create <version>`. No remote, no push.
5. Prints the next steps: local MongoDB with `<domain>_dev`, `pnpm seed` (before launch), the panel steps, the
deploy (`docs/DEPLOY.md`).
**Check:** in the new folder `git log --oneline` = one commit, `git status` clean, `pnpm typecheck` passes,
`grep -c 'Project decisions' AGENTS.md` = 1, `cat iapl-doctor.json` shows the domain and `launched: false`.
## The generated site
The reference site's tree (AGENT.md §3) with: the plugin pinned to the exact released version, the database
names from `databaseNamesFor(domain)` (`intecion.com` → `intecioncom_dev` / `intecioncom_prod`; hyphens stay),
`packageManager` pinned (copied from the reference site), CSP in **report-only** (`iapl-doctor.json` silences the
report-only finding for 28 days with the reason, and carries the reference site's own reasoned silences —
`i18n-literals` for the `/design` styleguide, `audit:collections-present` only while `posts` / `caseStudies` are in),
`assertEnv(iaplEnvRules({ databaseName, ipHeader, storage, … }))` in `instrumentation.ts`, the blocks from the
block library (`libraryBlocks` + `createBlockRegistry(content, { Image, Link, … })`), the design-token standard
(`styles.css` imports only, the brand in `src/design/tokens.ts`, next/font `--font-family-body` /
`--font-family-heading`), seeds through `createSeeder` with `SEED_ONLY`, and `docs/DEPLOY.md` for the team's
Coolify flow — build and check locally, Coolify builds the app from the repo with its default build pack,
MongoDB is a separate Coolify resource on the same Docker network, **no Dockerfile**:
```bash
SEED_ONLY="pages:kontakt" SEED_DRY_RUN=1 pnpm seed # in Coolify → the app → Terminal: read the plan
# Coolify → MongoDB resource → Backup now
SEED_ONLY="pages:kontakt" pnpm seed # the real run
```
Not in a new site: the reference company's demo content and media, the Blocks showcase page, the smoke tests
(`e2e/`), `.agents/skills` (re-installed by `iapl-skills`), `README.md`.
## How the reference site becomes a site
`reference/starter.manifest.json` (owned by the reference site) gives every path a role:
| Role | Meaning |
|---|---|
| `drop` | left out (demo seeds and media, e2e, generated files) |
| `generate` | written by the starter from the answers (`src/i18n.config.ts`, `src/design/tokens.ts`, `DESIGN.md`, `iapl-doctor.json`) |
| `template` | copied with `placeholders` replaced — the reference's unique fake values (`example-studio.pl`, `Example Studio`, `example-studiopl`…) → the new site's values |
| `keep` | copied as is; must not contain a fake value (the bundle build fails) |
| `variants` | whole files that exist only with a flag on (`src/collections/Posts.ts` → `posts`) |
| `rewrite` | `package.json` entries set or removed (`null`) |
Inside files, variants are comment lines, so the reference site stays a normal, runnable project:
```ts
// @starter:if twoFactor
twoFactor: { issuer: 'Example Studio', plugin: payloadTotp },
// @starter:else
//: twoFactor: false, // turned off by the owner
// @starter:endif
```
`// @starter:if <flag>` / `!<flag>` … `// @starter:else` … `// @starter:endif` (also `#` in env files, `<!-- -->`
in Markdown, `{/* */}` in TSX children); blocks nest. Inside a kept block a `//: ` / `#: ` line is uncommented —
that is how the reference carries code it does not run itself. The flags come from the answers
(`flagsFromAnswers`): `twoFactor`, `posts`, `caseStudies`, `collections`, `crawl`, `scannerWithoutCrawl`, `r2`,
`graph`, `localBusiness`, `aiBotsBlockTraining`, `aiBotsDisallow`, `analytics`, `metaPixel`, `linkedIn`, `tiktok`,
`clarity`, `consentBasic`, `bannerDetailed`, `bannerInline`, `bannerModal`, `themeToggle`, `defaultLight`,
`defaultDark`, `defaultSystem`, `whiteLabel`, `adminMeta`, `agencyNone`, `agencyCustom`, `enforceCsp` (always
off in a new site) and `demo` (always off). A flag the reference uses that this IAPL does not set stops the
run with its name.
**Adding a feature to the starter** = changing the reference site: write the code there (marked with
`@starter:if` when it depends on an answer), add a placeholder to the manifest when it holds a per-client value,
and — for a new answer — the question in `answers.ts` / `prompts.ts` and the flag in `flagsFromAnswers`.
## Release: the bundle and the gate
`pnpm build:starter` (in `prepublishOnly`, after `pnpm build`) packs the reference site into
`dist/starter/template.json.gz`: the kept files, the manifest and the reference lockfile **without the plugin
itself** — its integrity hash does not exist before the tarball is published. The new site's `pnpm install`
keeps every locked entry and resolves only the plugin (exact version) and its four dependencies (exact versions
too), then the complete lockfile goes into the first commit; from then on `--frozen-lockfile`. Size (measured on
1.14.6): the bundle is 90 KB gzipped (69 files + lockfile, 283 KB of text); everything the starter adds — bundle,
compiled code with source maps, docs — is ~340 KB unpacked (~4 % of 7.96 MB) and ~180 KB of the 2.40 MB tarball.
`pnpm starter:gate` (the last step of `prepublishOnly`) blocks the publish unless a site created from the
**packed tarball** works the way it will in Coolify: `dlx` create → frozen install → first seed of a fresh
`_dev` database (MongoDB in its own Docker container) → `pnpm generate:types && pnpm build` →
`SEED_ONLY="pages:kontakt" [SEED_DRY_RUN=1] pnpm seed` in production mode → a full seed in production refused (the guard's
"full seed refused" message is required; a run where Payload never initialized is inconclusive and retried, up to 3) →
`pnpm start` with `/api/health`, `/pl`, report-only CSP, no `X-Powered-By`, `/llms.txt` → `iapl-doctor --strict --offline`
(when shipped) → with the `nixpacks` CLI on PATH, the same seed inside the Nixpacks image. Each run packs to a new
file name and calls `dlx` with `--config.dlx-cache-max-age=0` (pnpm's dlx cache is keyed by the spec, so a reused path
would run the previous build), then checks the new site's `.iapl/starter.json` → `source` (the bundle's sha256 and the
plugin commit `build:starter` recorded) and the installed plugin against the packed tarball. Needs Docker;
`--keep` leaves `.starter-gate/` for inspection.
## Building blocks — `@intecion/ipal-kit/starter`
Node built-ins only, no Payload: script your own generator or check a reference tree with them.
| Export | What it does |
|---|---|
| `runCreateCli(args, log?)`, `CREATE_USAGE`, `parseCreateArgs(args)`, `normalizeDomain(input)`, `localEnv(example)` | the command and its pieces |
| `validateAnswers(input)`, `flagsFromAnswers(answers)`, `STARTER_TOPICS`, `askAnswers(ask)` | the questions as data, their validation, the flags they set, the prompts (any `ask` function) |
| `collectBundle(dir)`, `packBundle(bundle)`, `unpackBundle(buffer)`, `bundleFlags(bundle)` | a reference tree → the bundle and back; the flags its markers use |
| `renderSite(bundle, answers, ctx)`, `placeholderValues(answers, ctx)` | the new site's files (path → content), in memory |
| `applyVariants(text, flags, file?)`, `variantFlags(text)`, `applyPlaceholders(text, fakes, values)`, `leftoverFakes(text, fakes)` | the text transforms |
| `assertManifest(value)`, `fileRole(path, manifest)`, `matchGlob(path, glob)`, `ALWAYS_SKIPPED` | the manifest rules |
| `renderI18nConfig`, `renderTokens`, `renderDesignMd`, `renderAgentsMd`, `renderDecisions`, `renderDoctorConfig`, `rewriteFonts`, `fontExport`, `rewritePackageJson` | the files and sections written from the answers |
| `lockfileWithoutPlugin(lock)`, `secretFindings(files)` | the lockfile step and the secret check |
Types: `StarterAnswers`, `AnalyticsTool`, `ContentCollection`, `StarterBundle`, `StarterManifest`, `FileRole`,
`StarterFlags`, `SiteContext`.
## Turn off, override
- The command is optional: the manual path (`iapl-setup` stages 1–11) still sets up any site, including what this
version refuses (other default language, no URL prefix, Postgres).
- Every generated file belongs to the project afterwards — change it like any other file; `iapl-upgrade` and
`iapl-doctor` keep it in line with later plugin versions.
- `--no-install`, `--no-git`, `--dir`, `--plugin-spec` change the run; a different reference tree → your own
generator from the building blocks above.