5.3 KiB
CLI scaffolding (hivegrid create / hivegrid add)
The operator CLI under packages/cli/ ships scaffolding generators that
emit minimal, opinionated skeletons for the most common boilerplate
chores. Each generator writes to new paths only and supports a
--dry-run flag for testability.
Quickstart
# from the repo root, after `pnpm install`
pnpm --filter @hivegrid/cli build
# show the full command tree
node packages/cli/bin/hivegrid-cli.mjs --help
Command reference
hivegrid create module <name>
Scaffolds a feature-module skeleton under apps/web/app/modules/<name>/:
db/<name>.db.server.ts— tenant-scoped CRUD helpersservices/<Name>Service.ts— service layer with tenant guardscomponents/<Name>List.tsx— list UI stub<name>.db.server.test.ts— vitest smoke testREADME.md— manual follow-up checklistapps/web/app/routes/app.$tenant.<name>.tsx— React-Router-v7 tenant route
Flags:
--permission-prefix <prefix>— override the permission key prefix.--dry-run— print the would-be writes without touching the filesystem.
Example:
node packages/cli/bin/hivegrid-cli.mjs create module inventory
Manual follow-up (the README in the generated module repeats this):
- Add a Prisma model and run
pnpm prisma migrate dev. - Replace the
TODOmarkers in the db layer. - Add the permission keys to
packages/db/src/permissions-seed.server.ts(seehivegrid add permissionbelow). - Run
pnpm typecheckto generate the route types.
hivegrid create route <filename>
Scaffolds a single React-Router-v7 route file at
apps/web/app/routes/<filename>.tsx plus a co-located vitest stub.
Flags:
--top-level— generate a route without the:tenantparam.--dry-run— print the would-be writes without touching the filesystem.
Example:
node packages/cli/bin/hivegrid-cli.mjs create route app.\$tenant.dashboard
The generated file imports Route types from ./+types/<filename>
(NEVER relative paths) and contains loader, action, default component
and an ErrorBoundary export. Run pnpm typecheck after generation
to populate the ./+types/ directory.
hivegrid create entity <name>
Emits a Prisma model snippet plus a timestamped migration directory:
prisma/_generated/<name>.prisma— model snippet to paste intoprisma/schema.prismaprisma/migrations/<timestamp>_create_entity_<name>/migration.sql— placeholder SQLprisma/migrations/<timestamp>_create_entity_<name>/README.md— step-by-step apply instructions
The generator does NOT modify prisma/schema.prisma automatically.
After generation:
# paste the model from prisma/_generated/<name>.prisma into prisma/schema.prisma
pnpm prisma migrate dev --name create_entity_<name>
pnpm prisma generate
hivegrid add hook <name>
Scaffolds a plugin-hook registration file under
apps/web/app/hooks/_generated/. The output is a forward-compatible
stub for generated hook registration. The plugin runtime and
@hivegrid/plugin-sdk now exist; keep generated hooks on the scaffolded
no-op shape until a focused task wires that specific hook into the runtime.
Example:
node packages/cli/bin/hivegrid-cli.mjs add hook onContactCreated
hivegrid add event-type <name>
Scaffolds an EntityWebhook event-type definition with a zod schema, an
example payload, and an async handler stub under
apps/web/app/modules/workflowEngine/eventTypes/_generated/. Event
names MUST be dotted lowercase, e.g. crm.contact.created.
Example:
node packages/cli/bin/hivegrid-cli.mjs add event-type crm.contact.created
hivegrid add permission <name>
Scaffolds two fragments for a new permission key:
packages/db/src/_generated-permissions/<key>.ts— seed fragment (paste intodefaultPermissionSeeds).apps/web/app/utils/permissions/_generated/<key>.ts— frontend permission-mapper stub.
The generator intentionally does NOT patch the hand-curated
defaultPermissionSeeds array in permissions-seed.server.ts. The
README notes spell out the manual paste step.
Example:
node packages/cli/bin/hivegrid-cli.mjs add permission app.inventory.view
Safety guarantees
- Generators never overwrite existing files. Re-running a generator with the same name throws and exits non-zero.
- All generators support
--dry-run, which prints the would-be writes without touching the filesystem. - Generators only produce new paths inside the repo (or
prisma/_generated/snippets that you paste in by hand). The hand-curated source-of-truth files (schema.prisma,permissions-seed.server.ts,routes.ts) are never patched automatically.
Adding a new generator
- Create
packages/cli/src/commands/{create,add}/<command>.tswith agenerate<Name>function and adefineCommandexport. - Re-use the helpers from
_lib/scaffold.ts:validateIdentifier,pascalCase,kebabCase,snakeCasecreateScaffoldResult+writeScaffoldFile
- Add a vitest suite next to the command file that asserts:
- The expected file paths (in dry-run mode).
- Content invariants (e.g. correct import paths).
- Refuses to overwrite existing files.
- Register the command in the relevant
create/index.tsoradd/index.tsand update the rootindex.test.tsto keep the registry shape pinned.