Files
atomic-design-poc/plopfile.mjs
T
ehoandClaude Sonnet 5 7b6cabfc4a feat(dx): gen:context generator (WP-44)
npm run gen:context scaffolds a bounded context: folders + starter page, the @<ctx>/*
tsconfig alias, a dependency-cruiser boundary entry, and a lazy authGuard route.

Refactors .dependency-cruiser.js's per-context contextRule calls into a single
CONTEXT_ALLOWED map that every rule derives from, so adding a context is really one
config entry (verified behavior-preserving: same dep:check counts, same graph output).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-27 14:18:43 +02:00

137 lines
4.9 KiB
JavaScript

/**
* Runnable house-pattern generators (WP-43). `npm run gen <name>` or the `gen:*` scripts.
* These emit the boilerplate the skills used to describe by hand; each generated unit ships
* with its co-located spec so the "domain/pure logic must have a spec" rule holds by default.
*
* Generators here are the pure-TS patterns (no Angular-template escaping): value objects and
* form/wizard state machines. The UI-component and bff-endpoint patterns stay skill-driven —
* they span the template `{{ }}` syntax / the C# backend + `gen:api` regen, where a generator
* adds little over the recipe. `context` (WP-44) mechanises the `new-context` skill's manual
* multi-file edit: folders + tsconfig alias + boundary entry + lazy route.
*
* Positional args skip the prompts, e.g. `npx plop value-object registratie KvkNummer`.
*/
export default function (plop) {
const CONTEXT_PROMPT = {
type: 'input',
name: 'context',
message: 'Context (shared | auth | registratie | herregistratie | brief | beheer):',
};
const remindEnXlf = () =>
'⚠ The generated $localize id needs an English <target> in src/locale/messages.en.xlf before `npm run ci` (the localize gate fails otherwise).';
plop.setGenerator('value-object', {
description: 'Branded value object + parser + spec ("parse, don\'t validate")',
prompts: [
CONTEXT_PROMPT,
{ type: 'input', name: 'name', message: 'Name (PascalCase, e.g. KvkNummer):' },
],
actions: [
{
type: 'add',
path: 'src/app/{{context}}/domain/value-objects/{{kebabCase name}}.ts',
templateFile: 'plop-templates/value-object.hbs',
},
{
type: 'add',
path: 'src/app/{{context}}/domain/value-objects/{{kebabCase name}}.spec.ts',
templateFile: 'plop-templates/value-object.spec.hbs',
},
remindEnXlf,
],
});
plop.setGenerator('form-machine', {
description: 'Elm-style form/wizard state machine (Model/Msg/pure reduce) + spec',
prompts: [
CONTEXT_PROMPT,
{ type: 'input', name: 'name', message: 'Machine name (PascalCase, e.g. Adreswijziging):' },
],
actions: [
{
type: 'add',
path: 'src/app/{{context}}/domain/{{kebabCase name}}.machine.ts',
templateFile: 'plop-templates/form-machine.hbs',
},
{
type: 'add',
path: 'src/app/{{context}}/domain/{{kebabCase name}}.machine.spec.ts',
templateFile: 'plop-templates/form-machine.spec.hbs',
},
remindEnXlf,
],
});
plop.setGenerator('context', {
description:
'Scaffold a bounded context: folders + tsconfig alias + boundary entry + lazy route',
prompts: [
{
type: 'input',
name: 'name',
message: 'Context name (lowercase, single Dutch ubiquitous term, e.g. vergunning):',
},
],
actions: [
{
type: 'add',
path: 'src/app/{{kebabCase name}}/ui/{{kebabCase name}}.page.ts',
templateFile: 'plop-templates/context.page.hbs',
},
{
type: 'add',
path: 'src/app/{{kebabCase name}}/domain/.gitkeep',
templateFile: 'plop-templates/gitkeep.hbs',
},
{
type: 'add',
path: 'src/app/{{kebabCase name}}/application/.gitkeep',
templateFile: 'plop-templates/gitkeep.hbs',
},
{
type: 'add',
path: 'src/app/{{kebabCase name}}/infrastructure/.gitkeep',
templateFile: 'plop-templates/gitkeep.hbs',
},
{
type: 'add',
path: 'src/app/{{kebabCase name}}/contracts/.gitkeep',
templateFile: 'plop-templates/gitkeep.hbs',
},
{
// tsconfig path alias — inserted right after the `"paths": {` line so it's stable
// across repeated runs regardless of what's already been added.
type: 'modify',
path: 'tsconfig.json',
pattern: /"paths": \{\n/,
template: '"paths": {\n "@{{kebabCase name}}/*": ["src/app/{{kebabCase name}}/*"],\n',
},
{
// Boundary entry (WP-38's single source of truth) — inserted right before the
// `showcase: null` line, which never moves.
type: 'modify',
path: '.dependency-cruiser.js',
pattern: /(\s*)showcase: null,/,
template: "$1'{{kebabCase name}}': [],$1showcase: null,",
},
{
// Lazy route — inserted right before the catch-all, which never moves.
type: 'modify',
path: 'src/app/app.routes.ts',
pattern: " { path: '**', redirectTo: 'login' },",
template: ` {
path: '{{kebabCase name}}',
canActivate: [authGuard],
loadComponent: () =>
import('@{{kebabCase name}}/ui/{{kebabCase name}}.page').then(
(m) => m.{{pascalCase name}}Page,
),
},
{ path: '**', redirectTo: 'login' },`,
},
() =>
'Next: npm run dep:check && npm run lint && npm run build to verify, then build the first feature with the new-feature skill.',
],
});
}