Preparation
Ensure that you have the following packages installed at a global level on your computer. Note that in a real-life development context, you should have some of these local to your project. But for the having well been stable development environment we will install them globally.
node v12.8.0 npm v.6.10.2 @angular-cli (core y cli) v.10 @schematics/angular @schematics/schematics@0.1000.5 Before getting a start, we need to install @angular-devkit/schematics-cli package to allow us to use the schematics command in our terminal. This command is quite similar to the well-known ng generate but the main benefit is that we can run it anywhere because it is totally independent from the Angular CLI.
This allows us to use the schematics command and specifically the blank schematics to generate a new schematics project where we can start implementing our custom schematics.
Go to the folder where you want to place your schematics to be at and type in your terminal:
$ schematics blank --name=indepth-dev-schematic
As you can already understand, we are basically invoking the schematics function to generate a blank schematic, and we are passing the name of the collection as an option.
If we inspect the generated folder, we can verify it is an npm package, featuring a package.json with needed dependencies, and the node_modules folder.
We will also find a tsconfig.json file and scr folder.
Let we focus on the contents of the src folder
+ src
+ indepth-dev-schematic
This file read once by the schematic-cli and the angular-schematic tool, at the time of the running schematics
Any successive schematics in the same package require to be added to the collection