laizy init
Initialize a new Laizy CMS project with authentication, project selection, and client configuration.
laizy init
The init command sets up a new Laizy CMS project in your current directory. It handles authentication, project creation or selection, and generates the configuration files you need to start building.
Usage
pnpm laizy initThis is an interactive command with no flags. It walks you through the full setup process step by step.
What It Does
Create Project Structure
The command creates the following directories and files:
| Path | Purpose |
|---|---|
laizy/ | Directory for your schema files |
laizy/schema.laizy | Example schema with BlogPost and Author models |
generated/ | Directory for generated TypeScript client output |
If a laizy/schema.laizy file already exists, it is not overwritten.
Configure Base URL
You are prompted for the Laizy CMS base URL:
? Laizy CMS base URL: (http://localhost:3000)The default is http://localhost:3000 for local development. For production, use your deployed Laizy CMS URL (e.g., https://laizycms.com).
Authenticate
The CLI opens your browser for authentication. You sign in through the standard Laizy dashboard login flow, and the CLI receives an API token automatically.
Starting authentication...
Authentication successful!No need to manually copy and paste tokens. The browser-based auth flow handles everything.
Configure Output Path
You are prompted for the generated client output directory:
? Where should we generate your client? (directory) (./generated/laizy)The default is ./generated/laizy. This is where laizy generate will write the TypeScript client files.
Select or Create a Project
If you have existing projects, you can select one from a list:
? Select a project or create a new one:
My Website (my-website)
Blog Platform (blog-platform)
+ Create new projectIf you have no projects yet, the CLI walks you through creating your first one:
? Project name: My First Project
? Project slug (URL-friendly): my-first-project
? Project description (optional):The project is saved to .laizy/project.json for local context.
Generate Frontend Token
The CLI automatically generates a frontend content token for your project. This read-only token is written to your .env.local file:
NEXT_PUBLIC_LAIZY_TOKEN=laizy_eyJ...
NEXT_PUBLIC_LAIZY_BASE_URL=http://localhost:3000If token generation fails, the CLI continues with a placeholder value that you can replace later from the dashboard.
Save Configuration
The global configuration is saved to ~/.laizyrc:
{
"baseUrl": "http://localhost:3000",
"apiToken": "laizy_eyJhbGciOiJI...",
"organizationId": "org_abc123",
"schemaPath": "./laizy/schema.laizy",
"outputPath": "./generated/laizy"
}The local project context is saved to .laizy/project.json:
{
"projectId": "abc123",
"projectSlug": "my-first-project",
"projectName": "My First Project",
"linkedAt": "2024-01-15T10:30:00.000Z"
}Files Created
After running laizy init, your project will have these new files:
your-project/
laizy/
schema.laizy # Schema file with example models
generated/ # Output directory for generated client
.laizy/
project.json # Project context (auto-added to .gitignore)
.env.local # Updated with frontend token and base URL
~/.laizyrc # Global config (in your home directory)Example Schema
The generated laizy/schema.laizy file contains a working example:
model BlogPost {
title: String {
required: true
maxLength: 200
}
content: String {
required: true
}
status: String {
default: "draft"
}
}
model Author {
name: String {
required: true
maxLength: 100
}
email: String {
required: true
unique: true
}
bio: String
}This example demonstrates all constraint types and gives you a working schema to sync and generate a client from.
Re-initialization
If you run laizy init in a directory that already has a .laizyrc config, the CLI asks if you want to reinitialize:
Project is already initialized (.laizyrc exists)
? Do you want to reinitialize the project? (y/N)Re-initializing overwrites your configuration and project link but does not delete your schema files or generated code.
Gitignore
The init command automatically ensures that .laizy/ is added to your .gitignore file. This prevents project-specific context (like project IDs) from being committed, which is important when team members work on different projects.
The ~/.laizyrc file stores your API token. It lives in your home directory, not in the project, so it is never committed to version control.
Troubleshooting
Authentication failed:
- Ensure the base URL is correct and the server is running
- Check that you have an active Laizy CMS account
- Try running
laizy initagain to restart the auth flow
Connection failed:
- Verify the base URL is accessible from your machine
- Check if a firewall or proxy is blocking the connection
- For local development, ensure
pnpm run devis running
Next Steps
After initialization, follow these steps:
- Edit your schema: Modify
laizy/schema.laizywith your content models - Sync to database: Run
pnpm laizy syncto apply your schema - Generate client: Run
pnpm laizy generateto create the TypeScript client
- Sync Command -- Apply your schema to the database
- Generate Command -- Create a TypeScript client from your schema
- Schema Syntax -- Full reference for the schema language