Slide 1

Slide 1 text

beyond ngnew Go http://cnun.es/beyond-ngnew

Slide 2

Slide 2 text

Ciro Nunes Brought to you by @cironunesdev cironunes.com

Slide 3

Slide 3 text

Ciro Nunes Brought to you by @cironunesdev cironunes.com

Slide 4

Slide 4 text

Ciro Nunes Brought to you by @cironunesdev cironunes.com

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

The CLI

Slide 7

Slide 7 text

I ❤ CLI

Slide 8

Slide 8 text

Agenda Basics 1 Unlock the ultimate productivity 2 Tips & tricks 3

Slide 9

Slide 9 text

Agenda Basics 1 Unlock the ultimate productivity 2 Tips & tricks 3

Slide 10

Slide 10 text

" Start # projects

Slide 11

Slide 11 text

ng new gdg-devfest --routing --prefix gdg Start new projects Include routing module and prefix all components with gdg-

Slide 12

Slide 12 text

--dry-run (-d) Pro tip! Do not modify the file system

Slide 13

Slide 13 text

$ Add capabilities

Slide 14

Slide 14 text

ng add @angular/material Add libraries

Slide 15

Slide 15 text

ng add @angular/material Add libraries Install the official material packages and schematics to generate material components

Slide 16

Slide 16 text

ng add @angular/material Add libraries Install the official material packages and schematics to generate material components ng g @angular/material:dashboard --name my-dash

Slide 17

Slide 17 text

ng add @angular/material Add libraries Install the official material packages and schematics to generate material components ng g @angular/material:dashboard --name my-dash Generate the dashboard component using @angular/material schematics

Slide 18

Slide 18 text

ng add @angular/pwa Add PWA features

Slide 19

Slide 19 text

ng add @angular/pwa Add PWA features Get 100/100 PWA score in lighthouse

Slide 20

Slide 20 text

% Keep your & dependencies ☝ up-to-date

Slide 21

Slide 21 text

ng update --all --next -d Update packages (

Slide 22

Slide 22 text

ng update --all --next -d Update packages ( All packages to latest versions including betas and RCS

Slide 23

Slide 23 text

) Scaffold anything

Slide 24

Slide 24 text

ng generate (g) guard (g) appShell component (c) directive (d) service (c) … Scaffold anything! )

Slide 25

Slide 25 text

ng generate universal --client-project ang-conf Server-side rendering

Slide 26

Slide 26 text

ng generate universal --client-project ang-conf Scaffold server-side Angular with Universal Server-side rendering

Slide 27

Slide 27 text

ng generate library tooltip Scaffold libraries &

Slide 28

Slide 28 text

ng generate library tooltip Scaffold libraries & Scaffold libraries using ng-packgr

Slide 29

Slide 29 text

Create libraries for your components Pro tip! It’s a good way to check if their APIs are well designed

Slide 30

Slide 30 text

ng xi18n i18n

Slide 31

Slide 31 text

ng xi18n i18n Extract text marked with the i18n pipe into a translation file

Slide 32

Slide 32 text

ng eject Gain more control

Slide 33

Slide 33 text

ng eject Gain more control When you need more customisation or just want to learn more

Slide 34

Slide 34 text

OnCe you eject you can ’ t go back!

Slide 35

Slide 35 text

Memorise the shortcuts, type less! Usually you just have to type the first letter of a command

Slide 36

Slide 36 text

ng n new ng g generate ng s serve Shortcuts

Slide 37

Slide 37 text

Ask for help

Slide 38

Slide 38 text

ng help or just ng Need help?

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

ng g universal --help Need help per command?

Slide 41

Slide 41 text

ng g universal --help Need help per command? Help info for the universal schematic

Slide 42

Slide 42 text

Learn from the docs!

Slide 43

Slide 43 text

ng doc term in the API -s everywhere Search

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Play around, have fun

Slide 46

Slide 46 text

Agenda Basics 1 Unlock the ultimate productivity 2 Tips & tricks 3

Slide 47

Slide 47 text

Share Learn Create

Slide 48

Slide 48 text

Schematics

Slide 49

Slide 49 text

Apply transformations to your project

Slide 50

Slide 50 text

Just like the CLI does

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Rules

Slide 53

Slide 53 text

Rules Trees

Slide 54

Slide 54 text

Rules Takes a tree and returns a tree Trees

Slide 55

Slide 55 text

Rules Takes a tree and returns a tree Trees Existing files + stage area

Slide 56

Slide 56 text

Modifies trees instead of the filesystem directly

Slide 57

Slide 57 text

Dry runs Reusability Extensibility That allows for

Slide 58

Slide 58 text

Creating schematics

Slide 59

Slide 59 text

npm i -g @angular-devkit/schematics-cli Install it

Slide 60

Slide 60 text

schematics blank --name=my-component Generate a blank schematic

Slide 61

Slide 61 text

Rules

Slide 62

Slide 62 text

z import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; export function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { return tree; }; }

Slide 63

Slide 63 text

z import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; export function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { return tree; }; }

Slide 64

Slide 64 text

z import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; export function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { tree.create(options.name || 'hello', 'world'); return tree; }; } Create and modify files

Slide 65

Slide 65 text

z import { Rule, SchematicContext, Tree, chain, externalSchematic } from '@angular-devkit/schematics'; export function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { tree.create(options.name || 'hello', 'world'); return chain(tree, externalSchematic(...)); }; } Chain external schematics

Slide 66

Slide 66 text

Collections

Slide 67

Slide 67 text

z { "$schema": “.../@angular-devkit/schematics/ collection-schema.json", "schematics": { "my-component": { "description": "A blank schematic.", "factory": "./my-component/index#myComponent" } } } Schematics collection collection.json

Slide 68

Slide 68 text

npm run build Build and test it schematics .:my-component --name=test --dry-run=false

Slide 69

Slide 69 text

node --inspect-brk $(which schematics) .:myComponent --name=test Debug it

Slide 70

Slide 70 text

ng new myapp Use it with the CLI npm link $PATH_TO_my-component ng g my-component:my-component someName

Slide 71

Slide 71 text

* Remember to publish on NPM ⚓ when you’re happy with the results!

Slide 72

Slide 72 text

Learn more, for free! https://leanpub.com/angular-schematics/read_full

Slide 73

Slide 73 text

Agenda Basics 1 Unlock the ultimate productivity 2 Tips & tricks 3

Slide 74

Slide 74 text

Now the , of the -

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

Monorepo structure enterprise ready! .

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

/ Practice the commands, use dry runs 0 Use, create and share schematics 1 Use the help command and the docs Takeaways 2 Embrace the ecosystem

Slide 80

Slide 80 text

Stay curious, explore the opportunities, use your creativity!

Slide 81

Slide 81 text

Thank you! I hope you enjoyed it @cironunesdev