display message on angular cli consle on build of angular/typescript

235 Views Asked by At

I am creating a model with some static value, it has two array properties I want if length of these arrays not equal then a message should appear on angular cli while building the angular project. And build should be failed.

What I am doing now in the below exapmple will through an example on instantiation of model class.

Model example:

class ModelHomeSubMenu
{
  constructor()
  {
    if(this.linksText.length != this.routeToRedirect.length)  
    {
      throw('Message for CLi should be appear');
    }
  }                    

  linksText: string[] = ['Menu Item 1','Menu Item 2'];  
  routeToRedirect: string[] = ['javascript:void(0)'];
}
1

There are 1 best solutions below

0
On

One of the ways this can be achieved is through the use of a linter, such as ts-lint. As shown here, custom TSLint rules can be created to validate the code.
Creation of the rule that you need requires traversing the AST. The created custom rule would check the length of the two array properties and depending on their length throw a failure.
TSLint design example.