Detectando Extremadura

Detectando Extremadura. “Detectando Extremadura” is published by Pedro Marín Muñoz.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Strict rules for new Angular project

Tutorial how to create and configure Angular project from the ground up

Article was updated on 29 February 2020 to follow best practices.

Very often I saw situations when project was not configured strictly enough, and it is a big mistake, because in future changing quality rules is a real pain. All team should spend 1–5 days fixing linter and typescript issues to be able pass new strict policies. So don’t make this common mistake and start you projects with maximum code quality checks.

Then we have to configure our git with our personal information. This information will be included in all your commits and anybody can identify author of each code line by this credentials.

3. Install latest LTS version of NodeJs.

4. Set this version as default.

2. Navigate to your projects path and create bare Angular project

We created bare project with configured directory apps for new applications. In other words we implemented foundation for monorepository.

3. Create and commit first application in your monorepository.

If you need to add more applications just repeat this step with different app name instead of website.

I suggest to create libraries in libs folder. To make it we have to change angular.json file and replace line:

To this one:

And execute creation command:

We added group-name for better grouping your libraries by domain or some scope and for modern naming conventions. If you want to publish your libs to some repository, for example npm, you have to create organisation with name of corresponding group-name and publish there. It is like a namespace for group of libs like:

I will write more information on publishing your libs to npm in future articles. But for now just use this convention.

And don’t forget to revert your angular.json to "newProjectRoot": "apps"

And I advise not to use default project in angular.json, later we will setup all scripts for each project individually, so just set it as empty:

Add .nvmrc file with lts/* in it. Or you can use exact version of node, for example 12.16.1. This version would be automatically enabled if you followed my instructions or you can enable it manually using command $ nvm use.

Add following rule to tsconfig.json to add strict null checks option to your compiler. It will protect you from very common mistakes of reading property of undefined or null.

Or better, if you want more strict rules you can apply all strict options and modify to your needs.

Enable all tslint rules to their strictest settings, just replace in tslint.json

To next line

And add this lines to disable some irrelevant rules

In process of developing disable or tune manually those rules you don’t like. And don’t forget to enable support of tslint in your IDE.

Add stylelint for checking quality of your scss code

And configure rules in .stylelintrc.json

In process of developing disable or tune manually those rules you don’t like. And don’t forget to enable support of stylelint in your IDE.

Prettier is an opinionated code formatter. Sometimes Prettier won’t give you the exact output you desire, however, the benefits it provides outweigh the flaws.

Add configuration to file .prettierrc

And configuration to file .prettierignore for ignoring directories and files

In order to run e2e tests in headless mode we need to do the following:

1. In the Karma configuration file, apps/website/karma.conf.js, add a custom launcher called ChromeHeadlessCI below browsers:

2. In the root folder of your e2e tests project, create a new file named apps/website/e2e/protractor-ci.conf.js. This new file extends the original apps/website/e2e/protractor.conf.js.

In order to run your linters, formatters or other scripts we can setup git hooks. We will use 2 packages for this purpose:

Configure lint-staged, just add in package.json

Next step to create our scripts for different hooks. I prefer to create folder tools for my shell scripts. We will setup 3 hooks:

Husky configuration in our package.json file:

Script ./tools/pre-commit.sh

Script ./tools/commit-msg.js

Script ./tools/pre-push.sh

We need to give proper file access to our tools

And finally add scripts to package.json for easy launch of commands:

Now you can run all this commands one by one and check if everything works correctly.

— — — — — — — — — — — — —

Add a comment

Related posts:

How You Can Get More Followers on Instagram in 2023

You are using those famous hashtags, editing your pictures like a pro, and trying to make your profile relevant to other peoples so they press that tiny “Follow” button. Follow all these tips. All…

Does Creatine Cause Hair Loss 2023

Hair loss is a common condition that affects millions of people around the world. Both men and women can experience hair loss, and it can be caused by a variety of factors. In this article, we will…