@component-labs/cli
v0.0.6
Published
CLI for installing Component Labs components
Maintainers
Readme
@component-labs/cli
Command-line tool for installing Component Labs components into your project.
Installation
You don't need to install the CLI globally. Use npx to run it directly:
npx @component-labs/cli initCommands
init
Initialize Component Labs in your project.
npx @component-labs/cli initWhat it does:
- Creates
components.jsonconfiguration file - Detects your project structure (Next.js, Vite, etc.)
- Optionally injects CSS imports into your global stylesheet
- Sets up TypeScript path aliases
Interactive prompts:
- TypeScript support (required)
- Style preference
- Tailwind config location
- Global CSS file location
- CSS variables for theming
- Component import alias
- Utils import alias
Example configuration created:
{
"$schema": "https://componentlabs.dev/schema.json",
"style": "default",
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "app/globals.css",
"cssVariables": true
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui"
}
}add
Add components to your project.
# Add specific components
npx @component-labs/cli add button input dialog
# Interactive selection
npx @component-labs/cli add
# Skip confirmation prompts
npx @component-labs/cli add button --yes
# Specify working directory
npx @component-labs/cli add button --cwd ./my-projectWhat it does:
- Validates
components.jsonexists - Checks component availability in registry
- Installs npm dependencies
- Copies component files to your project
- Includes required utilities (e.g.,
lib/utils.ts) - Handles registry dependencies automatically
Options:
--yes, -y- Skip confirmation prompts--cwd <path>- Specify working directory (default:process.cwd())
Workflow
First Time Setup
# 1. Initialize in your project
npx @component-labs/cli init
# 2. Add your first components
npx @component-labs/cli add button input
# 3. Start using themimport { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
function MyForm() {
return (
<form>
<Input label="Email" type="email" />
<Button type="submit">Submit</Button>
</form>
);
}Adding More Components
# Add specific components
npx @component-labs/cli add dialog checkbox switch
# Or select interactively
npx @component-labs/cli addConfiguration
components.json
The components.json file stores your project configuration:
| Field | Description | Example |
|-------|-------------|---------|
| style | Component style variant | "default" |
| tsx | TypeScript usage (required) | true |
| tailwind.config | Tailwind config path | "tailwind.config.ts" |
| tailwind.css | Global CSS file path | "app/globals.css" |
| tailwind.cssVariables | Use CSS variables | true |
| aliases.components | Component import alias | "@/components" |
| aliases.utils | Utils import alias | "@/lib/utils" |
| aliases.ui | UI component alias | "@/components/ui" |
CSS Setup
After running init, your global CSS should contain:
@import "tailwindcss";
@import "@component-labs/ui/base";
/* Your custom styles */If you skipped automatic injection, add these imports manually.
TypeScript Setup
Update tsconfig.json to support path aliases:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Available Components
Run npx @component-labs/cli add to see the full list:
button- Interactive buttons with variantscheckbox- Accessible checkboxesinput- Text inputs with labelsdialog- Modal dialogsswitch- Toggle switchesmenu- Dropdown menuscombobox- Searchable selectsdata-table- Data tables with features
How It Works
Component Installation
When you run add button, the CLI:
- Validates - Checks
components.jsonexists - Resolves - Looks up component in registry
- Collects - Gathers dependencies and registry deps
- Installs - Runs
npm/yarn/pnpm installfor dependencies - Copies - Writes component files to your project
- Includes - Adds required utilities (like
cn())
File Structure Created
your-project/
├── components.json
├── src/
│ ├── components/
│ │ └── ui/
│ │ ├── button.tsx
│ │ ├── input.tsx
│ │ └── ...
│ └── lib/
│ └── utils.ts
└── app/
└── globals.css (updated with imports)Customization
Since components are copied to your project, you can:
Modify Components
// components/ui/button.tsx
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ variant, size, ...props }, ref) => {
// Add your custom logic
const customVariant = variant === 'custom' ? 'my-custom-class' : variant;
return (
<button
ref={ref}
className={cn(buttonVariants({ variant: customVariant, size }))}
{...props}
/>
);
}
);Extend Variants
const buttonVariants = cva(
"base-classes",
{
variants: {
variant: {
default: "...",
// Add your variant
brand: "bg-brand-600 hover:bg-brand-700"
}
}
}
);Override Styles
/* In your globals.css */
@import "tailwindcss";
@import "@component-labs/ui/base";
@theme {
/* Override Component Labs colors */
--color-primary-600: oklch(50% 0.2 250);
}Troubleshooting
"components.json not found"
Run npx @component-labs/cli init first to create the configuration.
"Unknown component: xyz"
The component doesn't exist in the registry. Run npx @component-labs/cli add to see available components.
"Could not find package.json"
Make sure you're running the CLI from your project root, or use --cwd to specify the path.
Import errors
Ensure your tsconfig.json has the correct path aliases:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Styling not applied
Make sure your global CSS has:
@import "tailwindcss";
@import "@component-labs/ui/base";Examples
Next.js Project
# In your Next.js project root
npx @component-labs/cli init
# Select: app/globals.css, @/components, @/lib/utils
npx @component-labs/cli add button input dialogVite Project
# In your Vite project root
npx @component-labs/cli init
# Select: src/index.css, @/components, @/lib/utils
npx @component-labs/cli add button inputComparison to NPM Installation
| Feature | CLI Installation | NPM Package |
|---------|-----------------|-------------|
| Setup | npx @component-labs/cli init | npm install @component-labs/ui |
| Updates | Manual re-add | npm update |
| Customization | Edit source directly | Override CSS vars |
| Import | @/components/ui/button | @component-labs/ui/button |
| Size | Only what you add | Tree-shaken |
| Best for | Full control | Quick setup |
License
MIT
