Project Setup
Initialize Prism in an existing React or Next.js project with the prismrepo CLI.
The Quick Start wrote a field component by hand. In practice, most consumers start from Prism's own copy-in primitives and field components, installed once and then edited freely. This page covers that path.
Initialize your project
From the root of an existing React or Next.js project (anywhere with a package.json):
npx prismrepo initThis writes:
prism.json, Prism's own config (not shadcn/ui'scomponents.json): the import aliasaddrewrites templates to (default@/components/prism), where Layer 1 primitives and Layer 2 field components go, and which global CSS file received Prism's design tokens.components/prism/fields/registry.ts, a starting, emptydefineRegistry({})call, only if you don't already have one.- Prism's CSS variable tokens, appended to your detected global stylesheet (
app/globals.cssfor a Next.js App Router project; a few other common locations are checked too), wrapped in marker comments so re-runninginitnever duplicates them.
Re-running init without --force when prism.json already exists is a no-op: it prints a
message and changes nothing. Your installed components and registry.ts are never touched.
Add a field component
npx prismrepo add text-fieldThis installs text-field.tsx into components/prism/fields/, and automatically installs the
Layer 1 primitives it depends on (label.tsx, input.tsx) into components/prism/ui/, each
with its import alias rewritten to your configured path. It then updates registry.ts for you
through an AST-aware edit, not a text rewrite, adding the import and the text: TextField entry
without touching anything else already in the file.
Finally, it reports (and, by default, installs) whatever npm dependencies are missing:
@prismrepo/core, @prismrepo/react, @prismrepo/forms, @prismrepo/adapter-rhf, and
react-hook-form. Pass --no-install to only see the command instead of running it, or
--dry-run to preview every file and dependency change with nothing actually written.
Install several items at once:
npx prismrepo add number-field select-field checkbox-field date-fieldIt's yours
Every installed file is a real, editable file in your project, not a reference to a package.
Edit components/prism/ui/input.tsx to change how every field built on it looks; edit
components/prism/fields/text-field.tsx to change what TextField does. Re-running
prismrepo add text-field later is always safe:
- If you never touched the installed files, it's a no-op, or a clean update if Prism shipped a newer template.
- If you edited them,
prismrepodetects that and refuses to overwrite your changes, explaining exactly which file and why. Pass--forceonly if you actually want to discard your edits.
Checking what's installed
npx prismrepo listShows every installable Layer 1 primitive and Layer 2 field component, and whether each is currently installed in your project.
See CLI for the complete command reference, and Your First Form to put the installed components to use.