Skip to content

My first schematic

Getting started with Schematics

If you are using VSCode and encounter issues loading schemas, check this article: https://bobbyhadz.com/blog/unable-to-load-schema-from-vscode-cannot-open.

Goals for this section

  • Create our first Schematics project.
  • Set up basic configurations to use our first schematic.
  • Create our first schematic.

Prerequisites

  • NodeJS 20+.
  • Install npm i -g @pbuilder/cli or use npx @pbuilder/cli.

Create a schematic project

Execute:

Terminal window
builder new <library-name> [author]

Builder-add schematic

The CLI already create a schematics called: builder-add. After you publish your package and the any user execute: builder add [your-package-name], the library will be installed and then builder-add schematic will be called.

Create the first schematic

1. To create a schematic, execute this:

Terminal window
builder exec @pbuilder/sm sc --name="my-schematic"

2. We are ready to test our first schematic, run:

Terminal window
npm run build

6. To test it we can run:

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

Congratulations! 🚀 You’ve successfully run your first schematic!