CLI Reference
Build, validate, test, and manage your design system from the command line.
The Fragments CLI is a design system CLI that compiles your component metadata into fragments.json, a structured file that powers the MCP server, the static HTML viewer (fragments view), and AI tooling. It also provides commands for visual testing, accessibility audits, Storybook integration, and more — over whatever React components you point it at. The Fragments component docs (66 components) are one worked example of the metadata format it produces — your own catalog is the real source of truth.
CLI Workflows for Component Libraries
The common workflow is: initialize configuration, build compiled Fragments data, run local dev previews, and verify quality checks in CI. If you are setting up Fragments for the first time, start with Install & Theming and return here for the command-level reference.
The compiled output is shared with MCP tools, documentation pages, and automated checks, so the CLI becomes the backbone of your AI-ready component workflow. It powers 4 MCP tools and token metadata used across theming and generation flows.
Setup
Install as a dev dependency. You can also run commands without installing via npx fragments.
npm install -D @fragments-sdk/cliHow It Works
Every component in your design system can have a .contract.json file alongside it. These files define metadata that AI agents and tools can query: component descriptions, prop documentation, usage guidelines, accessibility rules, and code examples.
{
"$schema": "https://usefragments.com/schemas/contract.v1.json",
"name": "Button",
"description": "Interactive element for user actions",
"category": "forms",
"status": "stable",
"sourcePath": "src/components/Button/index.tsx",
"exportName": "Button",
"propsSummary": ["variant: primary|secondary|ghost", "size: sm|md|lg"],
"usage": {
"when": ["Triggering actions", "Form submission"],
"whenNot": ["Navigation (use Link)", "Toggling state (use Switch)"]
},
"provenance": { "source": "extracted", "verified": true }
}Running fragments build compiles all fragment files into a single fragments.json file. This is consumed by the MCP server (so AI assistants can query your components), the static HTML viewer from fragments view (for browsing locally), and CI pipelines (for compliance checks).
Configuration
Running fragments init creates a fragments.config.ts file in your project root. This tells the CLI where to find your fragment files and where to write the compiled output:
import type { FragmentsConfig } from '@fragments-sdk/cli';
const config: FragmentsConfig = {
// Glob patterns for finding .contract.json files
include: ['src/components/**/*.contract.json'],
// Output path for compiled fragments.json
outFile: 'fragments.json',
// Glob patterns for component source files (for coverage validation)
components: ['src/components/**/index.tsx'],
// Design token discovery
tokens: {
include: ['src/styles/**/*.scss'],
},
};
export default config;Quick Start
The typical workflow after installation:
fragments init # Create fragments.config.ts and scaffold files
fragments build # Compile .contract.json files into fragments.json
fragments view # Generate a static HTML viewer to browse components
fragments verify --ci # Run compliance checks in CIpackage.json for convenience: "fragments:build": "fragments build", "fragments:view": "fragments view"Commands
Setup
Initialize and scaffold your design system project.
Build & Compile
Compile fragment files into machine-readable output.
Inspect & List
List discovered fragments and design tokens.
Quality & Compliance
Validate, audit, and verify design system compliance.
Visual Testing
Screenshot capture, diff, and visual regression testing.
AI & Context
Generate AI-ready context and enhance documentation.
Integrations
Link Figma designs, Storybook stories, and external tools.
Utilities
Miscellaneous helpers and viewers.