create-reactbricks-app
v1.5.1
Published
Scaffold a React Bricks project
Downloads
577
Readme
React Bricks CLI
The command-line interface tool for creating React Bricks apps with a starter templates and API validation rewritten in Clack.
Overview
The React Bricks CLI (create-reactbricks-app) is a comprehensive tool that streamlines the process of creating new React Bricks projects. It provides an interactive setup experience that guides users through authentication, app selection/creation, project configuration, and starter template selection.
What is React Bricks?
React Bricks is a CMS with visual editing based on React components. It allows developers to create websites and applications with a visual editing interface while maintaining full control over the codebase.
Features
- 🔐 Authentication System: Secure login with session management
- 📱 Multi-App Support: Create or select from existing React Bricks apps
- 🎨 Multiple Framework Support: Next.js (App Router & Pages Router), Astro, Remix, and Gatsby
- 🌐 Template Varieties: Choose from "Website and Blog with Tailwind" or "Empty project" starters
- 📦 Package Manager Detection: Automatically detects and uses npm, yarn, or pnpm
- 🛠️ Environment Setup: Automatic environment variable configuration
- 📄 Content Seeding: Optional default content and image setup
- 🔧 Git Integration: Automatic git repository initialization
- 📊 Error Tracking: Built-in Sentry integration for monitoring
Technology Stack
- Language: TypeScript
- Runtime: Node.js (>=20.18.0)
- Build Tool: unbuild
- Package Manager: pnpm (with workspace support)
- CLI Framework: @clack/prompts for interactive prompts
- HTTP Client: axios for API communications
- Process Management: execa for running shell commands
- Authentication: configstore for persistent login sessions
- Monitoring: @sentry/node for error tracking
Installation
The CLI is designed to be used with npx (no installation required):
npx create-reactbricks-appOr install globally:
npm install -g create-reactbricks-app
# or
yarn global add create-reactbricks-app
# or
pnpm add -g create-reactbricks-appUsage
Simply run the command and follow the interactive prompts:
npx create-reactbricks-appInteractive Flow
- Authentication: Login with your React Bricks account credentials
- App Selection: Choose an existing app or create a new one
- Environment Selection: Select the environment (main, staging, etc.)
- Project Configuration: Set project name and folder
- Starter Template: Choose from available frameworks and templates
- Content Setup: Optionally load default content and images
- Installation: Automatic dependency installation and git initialization
Supported Frameworks and Templates
Next.js with App Router
- Website and Blog with Tailwind (recommended)
- Empty project
Next.js with Pages Router
- Website and Blog with Tailwind (recommended)
- Empty project
Astro (Node.js v22 required)
- Website and Blog with Tailwind (recommended)
- Empty project
Remix
- Website and Blog with Tailwind (recommended)
- Empty project
Gatsby
- Website and Blog with Tailwind (recommended)
- Empty project
Project Structure
src/
├── index.ts # Main CLI entry point
├── starters.json # Template configurations
└── helpers/
├── api.ts # React Bricks API interactions
├── auth.ts # Authentication prompts and logic
├── fs.ts # File system utilities
├── starters.ts # Starter template types and utilities
├── tasks.ts # Project creation tasks (git, dependencies, etc.)
└── utils.ts # General utility functionsDevelopment
Prerequisites
- Node.js >= 20.18.0 (Astro starter requires >= 22.0.0)
- pnpm >= 10.7.0
Setup
- Clone the repository:
git clone https://github.com/ReactBricks/create-reactbricks-app.git
cd create-reactbricks-app- Install dependencies:
pnpm install- Build the project:
pnpm buildScripts
pnpm build- Build the project using unbuildpnpm copy:starters- Copy starters.json to dist directorypnpm prepack- Run build before packaging
Build Process
The project uses unbuild for building:
- Compiles TypeScript to JavaScript (ESM)
- Generates type declarations
- Copies
starters.jsonto the dist directory - Creates a single
index.mjsentry point
Configuration
Environment Variables
The CLI creates environment files based on the selected starter template:
- Next.js:
.env.local - Astro:
.env - Remix:
.env - Gatsby:
.env.production
Starter Configuration
Each starter template in starters.json contains:
{
"framework": "Framework name",
"starterProject": "Project type",
"language": "TypeScript",
"repoUrl": "GitHub repository URL",
"startYarnCommand": "yarn dev",
"startPnpmCommand": "pnpm dev",
"startNpmCommand": "npm run dev",
"envVariables": {
"apiKey": "API_KEY",
"appId": "APP_ID",
"appEnv": "ENVIRONMENT"
},
"envFile": ".env.local",
"importRbUI": false,
"defaultImages": [...],
"defaultContent": [...],
"minimalImages": [...],
"minimalContent": [...]
}API Integration
The CLI integrates with the React Bricks API for:
- User authentication and session management
- App creation and retrieval
- Environment management
- Content and media upload
- Admin operations for default content setup
API Endpoints Used
POST /v2/account/session- AuthenticationGET /v2/account/apps- Retrieve user appsPOST /v2/account/apps- Create new appPOST /v2/admin/session- Admin authenticationPOST /v2/admin/pages- Create pagesPOST /v2/admin/media/images/create_from_url- Upload images
Error Handling
The CLI includes comprehensive error handling:
- Network connectivity issues
- Authentication failures
- File system permissions
- Git configuration problems
- Package installation errors
Errors are automatically reported to Sentry for monitoring and improvement.
Code Style
- TypeScript with strict mode enabled
- ESM modules
- Async/await for asynchronous operations
- Comprehensive error handling
- Clear, descriptive variable and function names
