How to use the schematics CLI?
Introduction
@pbuilder/cli is designed to assist with everything related to schematics. To fully benefit from the CLI, it is essential to understand its useful commands. The CLI is agnostic of any JavaScript framework, so if you need to create a set of schematics for a specific framework or solution, consider developing your own CLI to handle those schematics.
Create a Schematic Project
builder new <project-name> [author] --bundler <bundler-name> --package-manager <manager> --skip-installation --dry-run --helpExecute schematics
builder exec | g is a command that allows you to execute any schematics, whether they are installed or not.
| Option | Description |
|---|---|
| —dry-run | Report actions that would be taken without writing out results. (default: false) |
| —registry | The NPM registry to use. |
| —keep-installed | If the collection is not install you could keep installed (default: false) |
| —package-manager | The package manager used to install dependencies. [string] [choices: “npm”, “yarn”, “pnpm”, “cnpm”, “bun”] (default: “npm”) |
| —send-pm | Send the package manager to the schematic (default: false) |
| —send-registry | Send the registry to the schematic (default: false) |
| -h, —help | display help for command |
Local schematic
If you have created schematics within your project and want to build and test them, use the following command:
builder exec ./dist/collection.json my-schematicPublished schematics
For executing schematics from a published collection, use this command:
builder g [collection-name] [schematic-name] [options]If the collection is not installed, the CLI will install it temporarily. To keep it installed, you can use the --keep-install option:
builder g [collection-name] [schematic-name] [options] --keep-installPrivate packages
To execute schematics from private packages, specify the registry with the following command:
builder exec [collection-name] [schematic-name] [options] --registry="http://localhost:4873"📦 builder config Command
The builder config command allows you to read, write, delete, and list configuration values used by the CLI.
🧠 How Configuration Works
-
Local Config (
./builder.config.json)- If found, it overrides global config.
- Project-specific settings.
-
Global Config (
~/.config/builder-cli/config.json)- Loaded when no local config exists.
- Used for user-wide settings.
-
Default Config (applied automatically if no config exists):
const DEFAULT_CONFIG = { cli: { showBanner: true, },};Get info about a schematic
Before using a new set of schematics, it’s important to gather information about them. This helps you understand what each schematic does and the options it offers.
Get all the schematics of a collection
To list all schematics available in a collection, use this command:
builder info [collection-name]Get all the options of a schematic
To get detailed information about the options for a specific schematic, use the following command:
builder info [collection-name] [schematic-name]Builder add
Some schematic projects have a special schematic named builder-add or ng-add. This schematic is automatically executed after the collection is installed. To trigger this, use the following command:
builder add [collection-name]This completes our basic introduction to using the CLI for schematics. With these commands, you are well-equipped to start working with schematics effectively. Happy coding!