Prerequisites:
npm install -g @angular-devkit/schematics-cli
This repository is a basic Schematic implementation that serves as a starting point to create and publish Schematics to NPM created by the following command:
schematics blank --name=ricardo-schematics
To test locally, install @angular-devkit/schematics-cli
globally and use the schematics
command line tool. That tool acts the same as the generate
command of the Angular CLI, but also has a debug mode.
Check the documentation with
schematics --help
npm run test
will run the unit tests, using Jasmine as a runner and test framework.
To publish, simply do:
npm run build
npm publish
Here you can find the necessary steps to use and develop new schemas
In the root of the project run
npm install && npm run build
In the root of the Angular project run:
ng generate ricardo-schematic:schemaName --options
This schema builds the basic template for the following utils:
- Model
--name=modelName
--path=path/from/src
Before to run the generate command you must create a json file with the properties and types (see example below)
1.- The json must be in the same model folder where we want to place our new model
2.- The json name must be the dasherize name of our new model.
json example:
{ "data": [ { "name": "id", "type": "number" }, { "name": "title", "type": "string" }, ] }
Desired model:
src/app/modules/home/models/new-model/new-model.ts
Step 1:
Create the following json:
src/app/modules/home/models/new-model/new-model.json
Step 2:
Run the following command:
ng generate ricardo-schematic:model --name=newModel --path=src/app/modules/home
In case you forget to add the mentioned json an explained error will be throw:
Error: new-model.json file configuration not found in src/app/modules/home/models/new-model/new-model.json, please create it.
If you need help, follow the readme for more instructions:
https://github.com/RicardoR/ricardo-schematics
Nice because we need you! Please continue reading the next steps to start collaborating
In order to develop schematics you have to install the following global packages:
npm install -g @schematics/schematics
npm install -g @angular-devkit/schematics-cli
npm install -g @angular-devkit/schematics
npm install -g @angular-devkit/core
In the root of the project run the following command
schematics blank --name=schemaName
In order to develop quickly you can use the watcher option
npm run build:watch
Instead of testing inside of angular project you can test it locally. Example of model schema:
schematics .:model --name=modelDemo --path="." --debug=false
NOTE: if you dont use --debug=false
files are not going to be created, actions are only logged by default
Simply run the following command: npm publish
https://github.com/angular/schematics-angular-builds https://github.com/angular/angular-cli/tree/master/packages/angular_devkit/core/src/utils