The Different Types of Angular CLI Commands

In this article, we are going to learn what the different types of Angular CLI commands are, and the tools that power them. Let's get started.

There are three types of Angular CLI commands:

  • schematics commands:ng add,ng generate,ng new,ng update;
  • architect commands:ng build, ng deploy, ng e2e,ng lint,ng run,ng serve,ng test,ng xi18n;
  • and native commands:ng config,ng doc,ng version, ng analytics, ng help.

Schematics commands

Schematics commands are based on a tool called Schematics that comes from the @angular-devkit/schematics package. Schematics is the underlying tool the Angular CLI uses to scaffold a new Angular workspace (ng new), generate blueprints (ng generate), update/migrate existing code (ng update), and add some frameworks support to an Angular application (ng add). It's all about code generation.

The nice thing about Schematics is that it allows us to extend the CLI's scaffolding capabilities.

Learn how Air France-KLM is leveraging schematics in another blog post– The Angular CLI at Air France-KLM.

Architect commands

Architect commands are based on a tool called Architect that is published under the @angular-devkit/architect package name. Architect helps the Angular CLI lint (ng lint), test (ng test, ng e2e), serve (ng serve), build (ng build), and deploy (ng deploy) our Angular applications. It's all about running complex tasks.

With the Architect tool, we can now create custom tasks for the Angular CLI. Previously, one would eject the Webpack configuration of the Angular CLI–using the now deprecated ng eject command–to be able to tweak the build process. Now every customization can be done using Architect. That's why, the ng eject command was removed in Angular CLI v8.

Native commands

Native commands are general Angular CLI commands. They are native to the Angular CLI in the sense that they don't rely on other tools/packages to be executed. Displaying our packages' versions (ng version), opening the official documentation (ng doc), reading and setting some values in the angular.json file (ng config), or displaying the list of available commands and their description (ng help) do not require the use of any specific tool.

Conclusion

In this article, we learned that they were three types of Angular CLI commands: native commands, schematics commands, and architect commands. Schematics and Architect are tools from the @angular-devkit packages that make the Angular CLI generic, extensible, and so powerful.