Gerard Sans
@gerardsans
Gerard Sans
@gerardsans
SANS
GERARD
Spoken at 112 events in 27 countries
900
1.6K
Scaffolding Tool
Code Generation
Independent from Angular
Configurable prompts
ng new myProject
ng add @angular/material
Angular updates
ng update @angular/cli @angular/core
> ng generate $type $options
> $type: store st, feature f, effect ef, container co
reducer r, action a, entity en
> $options: --flat (default) --group --spec
> $name: counter
// same folder no specs
> ng generate action $name
create src/app/counter.actions.ts
// separate actions folder + specs
> ng generate action $name --group --spec
create src/app/actions/counter.actions.ts
create src/app/actions/counter.actions.spec.ts
// same folder + specs
> ng generate action $name --spec
create src/app/counter.actions.ts
create src/app/counter.actions.spec.ts
Collection: Set of schematics (Rules)
@ngrx/schematics
Schematic (Rule): set of actions
ng new, ng update
Action: transform of the file tree
Source
Output
Action
Source
Output
Action
Source
Output
Action
Source
Output
Action
a
b
c
c'
npm install -g @angular-devkit/schematics
@angular-devkit/schematics-cli
schematics blank --name=basic
CREATE /basic/README.md
CREATE /basic/package.json
CREATE /basic/tsconfig.json
CREATE /basic/src/collection.json
CREATE /basic/src/basic/index.ts
CREATE /basic/src/basic/index_spec.ts
app/my.component.ts
schematics schematic --name=sample
CREATE /sample/src/collection.json
CREATE /sample/src/my-full-schematic/index.ts
CREATE /sample/src/my-full-schematic/schema.json
CREATE /sample/src/my-full-schematic/files/test2
CREATE /sample/src/my-full-schematic/files/test__INDEX__
CREATE /sample/src/my-other-schematic/index.ts
CREATE /sample/src/my-schematic/index.ts
app/my.component.ts
schematics blank --name=basic
cd basic
npm run build
npm run test
npm link
> usr/local/lib/node_modules/basic -> <path>/basic
schematics --help
schematics .:basic --dry-run=false
app/my.component.ts
ng new test-basic
cd test-basic
npm link basic
> /test-basic/node_modules/basic
-> usr/local/lib/node_modules/basic
-> /basic
ng config cli.defaultCollection basic
ng g basic
schematics basic:basic
app/my.component.ts
schematics schematic --name=sample
cd sample
npm i
npm run build
npm run test
npm link
> usr/local/lib/node_modules/sample -> <path>/sample
app/my.component.ts
ng new test-sample
cd test-sample
npm link sample
> /test-sample/node_modules/sample
-> usr/local/lib/node_modules/sample
-> /sample
ng config cli.defaultCollection sample
ng g my-schematic
schematics sample:my-schematic
app/my.component.ts
@hanslatwork
@filipematossilv
@Brocco
@jakeherringbone