Built.js CLI
The Built.js CLI is a powerful command-line tool for creating and managing Built.js applications, themes, and plugins. This document provides an overview of available commands and their usage.
Usage
Many of the commands of the Built.js CLI require your Built.js API key. You can find this in Build Studio by clicking your profile picture in the header and selecting "API Key".
Available Commands
new
Creates new Built.js resources.
Supported types:
theme
: Create a new themeplugin
: Create a new pluginsite
: Create a new site from an existing theme
Regular Theme Creation:
Creates a theme from scratch using AI prompts. You'll be prompted for:
- Theme name
- Theme description (used as AI prompt in the
define
anddesign
commands and if using--fromUrl
) - Username (must be alphanumeric with hyphens)
URL-Based Theme Creation:
Creates a theme by analyzing an existing website. You'll be prompted for:
- Theme name
- Username (must be alphanumeric with hyphens)
When to use each approach:
- Regular creation: When you have a clear vision and want to describe your theme concept
- URL-based creation: When you want to replicate or adapt an existing website's design
Creating a Plugin
When creating a plugin, you'll be prompted for:
- Plugin name
- Plugin description (used as AI prompt)
- Username (must be alphanumeric with hyphens)
Creating a Site from Theme
Creates a new site by downloading site files from the Built.js based on an existing theme project.
Requirements:
- Must be run from a directory containing a theme project
- Theme project must have
public/data/theme.json
with a valid namespace - Valid API key for Built.js
Output:
Creates a directory named built-site-<kebab-case-name>
(e.g., "My Site" → built-site-my-site
) containing the downloaded site files.
define
Creates a mermaid sitemap in the root of your project. This sitemap will be used by the AI model to create files and templates for the theme or plugin in the design
command.
Options:
--url <url>
: Generate sitemap from a URL using vision AI--from-config
: Generate sitemap from existing config files
design
Creates data files and templates using the mermaid sitemap in the root of the project. This command has several options to run specific tools:
Options:
--templates
: Run only the templates tool--collections
: Run only the collections tool--global
: Run only the global tool--layout
: Run only the layout tool--modules
: Run only the modules tool--sections
: Run only the sections tool--schemas
: Run only the schemas tool--page-content-types
: Run only the pageContentTypes tool--template-descriptions
: Run only the templateDescriptions tool--pages
: Run only the pages tool
publish
Imports your theme or plugin into Built Studio where they can be used to create sites.
Options:
-t, --type <type>
: Type of project (theme or plugin), defaults to 'theme'
init
Creates the necessary files in a fresh Next.js app, used for themes, plugins and sites.
This command is run on the parent directory of a Next.js app. This directory must have been created either by export of the theme or plugin from Built Studio, or by creating a new theme or plugin using the new
command (see below).
setup
Sets up your site with Sanity data.
The setup
command is not used for themes and plugins, only sites.
update
Updates your theme or plugin. To be run whenever updates are made to data in the public/data
directory.
Options:
--plugins
: Include plugins in the update--screenshots
: Update screenshots for all sections-p, --port <number>
: Specify the port number of the Next.js app
create
Creates templates for specific sections.
Options:
--all
: Create templates for all sections
Environment Setup
Here are the environment variables required for specific commands:
Required Environment Variables
For define
and design
commands to create themes and plugins using your own AI model:
OPENAI_API_KEY
: Your OpenAI API key for AI-powered template generationUNSPLASH_ACCESS_KEY
: Your Unsplash API key for image generation (optional)
For set up of Sanity data for a site:
NEXT_PUBLIC_SANITY_PROJECT_ID
: The Sanity project IDNEXT_PUBLIC_SANITY_WRITE_TOKEN
: The Sanity project's write token
These credentials can be found on the Sanity project management dashboard
Never commit your .env
file to version control. It should be listed in your .gitignore
file.
Best Practices
- Use the
--help
flag to see command-specific options - When creating new resources, provide detailed descriptions for better AI-generated results
- Keep your project data up to date using the
update
command - Use the
publish
command to make your theme or plugin available in Built Studio - When creating sites, ensure you're in the correct directory with a valid theme project
- Use descriptive site names that will work well when converted to directory names
Examples
Create a theme from a prompt
The define
and design
commands require OPENAI_API_KEY
in the project's .env
file.