Skip to content

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

Creation of schematic library project
builder new <project-name> [author] --bundler <bundler-name> --package-manager <manager> --skip-installation --dry-run --help

Execute schematics

builder exec | g is a command that allows you to execute any schematics, whether they are installed or not.

OptionDescription
—dry-runReport actions that would be taken without writing out results. (default: false)
—registry The NPM registry to use.
—keep-installedIf 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-pmSend the package manager to the schematic (default: false)
—send-registrySend the registry to the schematic (default: false)
-h, —helpdisplay help for command

Local schematic

If you have created schematics within your project and want to build and test them, use the following command:

Terminal window
builder exec ./dist/collection.json my-schematic

Published schematics

For executing schematics from a published collection, use this command:

Terminal window
builder g [collection-name] [schematic-name] [options]

Private packages

To execute schematics from private packages, specify the registry with the following command:

Terminal window
builder exec [collection-name] [schematic-name] [options] --registry="http://localhost:4873"

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:

Terminal window
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:

Terminal window
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:

Terminal window
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!