The Angular CLI is a powerful tool that makes it easy to build Angular applications. With the Angular CLI, we can scaffold, develop, test, and build our applications. It's the best starter kit for Angular projects.
Since version 6, more powerful and more generic, the Angular CLI has introduced plenty of great features like workspaces, architects, builders, library support, and my preferred, schematics. Angular Schematics are the main focus of this presentation. It allows us to create our custom blueprints, add a framework and its setup to our application via a single command, and to update/migrate our application.
After this session, you will have a big picture of the new Angular CLI features including:
• workspaces,
• library support,
• architects,
• builders,
• how to create your own Schematics,
18. Generating a Library
ng generate library <library_name>
Scaffolds a library
Updates our tsconfig.json file to add paths mapping
18
19. Building a Library
ng build <library_name>
Outputs the build artifacts to dist/<library_name>
19
20. Using Your Library
import { MakeItAwesomeModule } from 'make-it-awesome';
First it looks in the tsconfig paths
Then it looks in the node_modules folder
20
21. Publishing Your Library
ng build <library_name>
cd dist/<library_name>
npm adduser
npm publish –-access=public
Let’s share the library with the world
21
22.
23. Tips and Tricks
Use the watch flag to always rebuild your library
ng b <library_name> --watch
23
30. The ng run Command to Rule Them All
ng run <project>:<target>[:configuration]
Runs an Architect target
30
31. The ng run command
Predefined Commands
ng build <project>
ng test <project>
ng lint <project>
...
Using ng run
ng run <project>:build
ng run <project>:test
ng run <project>:lint
...
31
41. Why Create Our Custom Schematics
Our starter kit can be replaced by a single command
Building solid foundations
Enforcing best practices across the company
Startup mode
Automate all things!
41
42. Getting Started
> yarn global add @angular-devkit/schematics-cli
> schematics blank –name=simple
> schematics schematic –name=advanced
42
50. Rule
Takes in a Tree and
outputs a modified
Tree
Applies actions to a
Tree
50
51. Tree
A staging area for
changes
Contains:
• a file system,
• and a list of changes
to apply to it
51
52. Working on a Tree
function do(tree: Tree, context: SchematicContext) {
tree.create('hello.txt', 'Bonjour GDG Toulouse’);
tree.read('file.txt');
tree.rename('hello.txt’, 'salut.txt');
tree.delete('salut.txt');
return tree;
}
52
53. Running a Schematic
> ng generate @ahasall/schematics:first <name>
> schematics @ahasall/schematics:first <name>
53