paint-brush
Continuous Integration with Angular CLIby@charpeni
18,378 reads
18,378 reads

Continuous Integration with Angular CLI

by Nicolas CharpentierJuly 8th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Angular CLI is a powerful tool to scaffold and build Angular apps. Not only it provides you scalable project structure, instead, it handles all common tedious tasks for you out of the box and it already follows the Angular best practices.

Company Mentioned

Mention Thumbnail
featured image - Continuous Integration with Angular CLI
Nicolas Charpentier HackerNoon profile picture

Angular CLI is a powerful tool to scaffold and build Angular apps. Not only it provides you scalable project structure, instead, it handles all common tedious tasks for you out of the box and it already follows the Angular best practices.

Build and test your application in a minute

As tasks, we’ve common commands like:

  • ng new to initialize a new Angular project with a lot of settings.
  • ng generate to generate something from a blueprint.
  • ng serve to build the application and starts a web server.
  • ng build to compile the application into an output directory.
  • ng test to run your unit tests with Karma the provided test runner.
  • ng lint to lint you app code using tslint to ensure best practices of Angular.

With these commands, you can easily create a new Angular app, generate some components following blueprints and build it in few minutes. Even that, you can ensure everything is still functional with the test runner and if you still respect the style and best practices from Angular with the linter. And this, without any configuration necessary, everything is already ready so you can run test without any further configuration. However, these tools are only effective if you run the command, otherwise, it’s a wasted potential.

Continuous Integration

To use it at its full potential, we can automatically execute these commands into a continuous integration tool such as CircleCI, Travis, AppVeyor, Jenkins, Bamboo, and a lot more, hooked with your source control on each commit, pull request and even prevent merge if these commands fail. In that way, this will prevent someone from merging if his code doesn’t match with your or Angular style and breaking your project with unbuildable code. You’ve probably already heard “but it’s working on my computer“ that’s exactly what we want to prevent here.

All you have to do is to setup the environment and executes these previous pre-chewed commands.

First, let’s build our angular application in production and AoT to be sure everything is alright, then test it and finally lint it. It can be executed on multiple tools, but let’s do examples for a few, at least my favorites.

We will use Yarn as a fast and secure package manager to cache our dependencies between builds, for more information refer to this article:


Reliable Continuous Integration in JavaScript_When you build a piece of software you want to build a reliable one, so often you’re using various continuous…_medium.com

CircleCI 2.0

Version 2.0 has been rolled out few days ago, enjoy this updated config.

AppVeyor

For more information, feel free to checkout the repository that was used to experiment this :


charpeni/angular-cli-circleci_angular-cli-circleci - 🔧 📚 This repository was used to determine the best way to test a project generated…_github.com