Skip to content

Commit

Permalink
feat: add commitlint, lint-staged and husky
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromonad committed Oct 29, 2024
1 parent ccc5172 commit 33ccbcc
Show file tree
Hide file tree
Showing 13 changed files with 958 additions and 80 deletions.
4 changes: 4 additions & 0 deletions .cz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "node_modules/cz-git",
"useEmoji": true
}
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ jobs:
- uses: nrwl/nx-set-shas@v4

# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
# - run: npx nx-cloud record -- echo Hello World
- run: npx nx-cloud record -- nx format:check
- run: npx nx affected -t lint test build
- run: npx nx affected --parallel 1 -t e2e-ci
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx commitlint --edit $1
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged --relative --concurrent false
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx nx affected -t test && npx nx affected -t component-test
4 changes: 4 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.ts": ["nx affected:lint --fix --files"],
"*": ["npx nx format:write --files"]
}
38 changes: 37 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
{
"singleQuote": true
"tabWidth": 2,
"endOfLine": "lf",
"useTabs": false,
"printWidth": 120,
"semi": true,
"trailingComma": "none",
"bracketSpacing": true,
"proseWrap": "always",
"bracketSameLine": true,
"singleQuote": true,
"arrowParens": "avoid",
"singleAttributePerLine": true,
"htmlWhitespaceSensitivity": "strict",
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"importOrder": [
"^@angular/(.*)$",
"^rxjs|rxjs/(.*)$",
"<THIRD_PARTY_MODULES>",
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"importOrderParserPlugins": ["typescript", "decorators-legacy"],
"overrides": [
{
"files": ["**/*.html"],
"options": {
"printWidth": 120
}
},
{
"files": "*.{yaml,yml}",
"options": {
"singleQuote": false
}
}
]
}
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
# angular-nx-firebase-monorepo

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>
This is a basic structure of Angular mono repo using Nx to configure, maintain, and especially integrate various tools
and frameworks.

**This workspace has been generated by [Nx, a Smart, fast and extensible build system.](https://nx.dev)**
## Features

- 🎈 Syntax Highlighting
- 💎 Responsive design
- 🚀 Production-ready

### Technologies:

- 🔥 Nx & Angular
- 🎨 Material
- 🎉 TypeScript
- ✏️ ESLint (Airbnb styled guide, Automatically remove unused imports and, etc.) Import sorting)
- 🛠 Prettier
- 🚫 lint-staged
- 🚨 Commitlint & commitizen
- 🐶 Husky - Run scripts on your staged files before they are committed.

## Start the app

First of all, create a firebase project and config the `apps/coins/src/environments/environment.development.ts`. Don't forget to enable the authentications!
First of all, create a firebase project and config the `apps/coins/src/environments/environment.development.ts`. Don't
forget to enable the authentications!

To start the development server run `nx serve coins`. Open your browser and navigate to http://localhost:4200/. Happy coding!
To start the development server run `nx serve coins`. Open your browser and navigate to http://localhost:4200/. Happy
coding!

## Generate code

If you happen to use Nx plugins, you can leverage code generators that might come with it.

Run `nx list` to get a list of available plugins and whether they have generators. Then run `nx list <plugin-name>` to see what generators are available.
Run `nx list` to get a list of available plugins and whether they have generators. Then run `nx list <plugin-name>` to
see what generators are available.

Learn more about [Nx generators on the docs](https://nx.dev/plugin-features/use-code-generators).

Expand All @@ -38,15 +57,18 @@ nx run-many -t <target1> <target2>
nx run-many -t <target1> <target2> -p <proj1> <proj2>
```

Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/core-features/run-tasks).
Targets can be defined in the `package.json` or `projects.json`. Learn more
[in the docs](https://nx.dev/core-features/run-tasks).

## Want better Editor Integration?

Have a look at the [Nx Console extensions](https://nx.dev/nx-console). It provides autocomplete support, a UI for exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.
Have a look at the [Nx Console extensions](https://nx.dev/nx-console). It provides autocomplete support, a UI for
exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.

## Ready to deploy?

Just run `nx build demoapp` to build the application. The build artifacts will be stored in the `dist/` directory, ready to be deployed.
Run `npx nx build coins` to build the application. The build artifacts are stored in the output directory (e.g. `dist/`
or `build/`), ready to be deployed.

## Set up CI!

Expand All @@ -55,9 +77,3 @@ Nx comes with local caching already built-in (check your `nx.json`). On CI you m
- [Set up remote caching](https://nx.dev/core-features/share-your-cache)
- [Set up task distribution across multiple machines](https://nx.dev/nx-cloud/features/distribute-task-execution)
- [Learn more how to setup CI](https://nx.dev/recipes/ci)

## Connect with us!

- [Join the community](https://nx.dev/community)
- [Subscribe to the Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
- [Follow us on Twitter](https://twitter.com/nxdevtools)
16 changes: 6 additions & 10 deletions apps/coins/src/app/features/user-coins/user-coins.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { CommonModule } from '@angular/common';
import { Component, OnInit, inject } from '@angular/core';
import { Auth } from '@angular/fire/auth';
import {
FormControl,
FormGroup,
FormsModule,
ReactiveFormsModule,
} from '@angular/forms';
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { Store } from '@ngrx/store';

import { UserQueries } from '@angular-nx-firebase-monorepo/firestore/queries';
import { Store } from '@ngrx/store';

import { UserCoinsActions } from './store/user-coins.actions';
import { selectAll } from './store/user-coins.reducer';
Expand All @@ -29,14 +25,14 @@ import { selectAll } from './store/user-coins.reducer';
MatFormFieldModule,
MatCardModule,
MatButtonModule,
MatInputModule,
MatInputModule
],
templateUrl: './user-coins.component.html',
styleUrl: './user-coins.component.scss',
styleUrl: './user-coins.component.scss'
})
export class UserCoinsComponent implements OnInit {
form = new FormGroup({
coin: new FormControl('', { nonNullable: true }),
coin: new FormControl('', { nonNullable: true })
});
userQueries = inject(UserQueries);
auth = inject(Auth);
Expand Down
109 changes: 109 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const fs = require('node:fs');
const path = require('node:path');
const apps = fs.readdirSync(path.resolve(__dirname, 'apps'));
/** @type {import('cz-git').UserConfig} */
module.exports = {
extends: ['@commitlint/config-conventional', '@commitlint/config-nx-scopes'],
prompt: {
messages: {
type: "Select the type of change that you're committing:",
scope: 'Denote the SCOPE of this change (optional):',
customScope: 'Denote the SCOPE of this change:',
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
breaking: 'List any BREAKING CHANGES (optional). Use "|" to break new line:\n',
footerPrefixesSelect: 'Select the ISSUES type of changeList by this change (optional):',
customFooterPrefix: 'Input ISSUES prefix:',
footer: 'List any ISSUES by this change. E.g.: #31, #34:\n',
generatingByAI: 'Generating your AI commit subject...',
generatedSelectByAI: 'Select suitable subject by AI generated:',
confirmCommit: 'Are you sure you want to proceed with the commit above?'
},
types: [
{
value: 'feat',
name: 'feat: ✨ A new feature',
emoji: '✨'
},
{
value: 'fix',
name: 'fix: 🐛 A bug fix',
emoji: '🐛'
},
{
value: 'docs',
name: 'docs: 📝 Documentation only changes',
emoji: '📝'
},
{
value: 'style',
name: 'style: 💄 Changes that do not affect the meaning of the code',
emoji: '💄'
},
{
value: 'refactor',
name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature',
emoji: '♻️'
},
{
value: 'perf',
name: 'perf: ⚡️ A code change that improves performance',
emoji: '⚡️'
},
{
value: 'test',
name: 'test: 🧪 Adding missing tests or correcting existing tests',
emoji: '🧪'
},
{
value: 'build',
name: 'build: 📦️ Changes that affect the build system or external dependencies',
emoji: '📦️'
},
{
value: 'ci',
name: 'ci: 👷 Changes to our CI configuration files and scripts',
emoji: '👷'
},
{
value: 'chore',
name: "chore: 🔨 Other changes that don't modify src or test files",
emoji: '🔨'
},
{
value: 'revert',
name: 'revert: ⏪️ Reverts a previous commit',
emoji: '⏪️'
}
],
useEmoji: true,
emojiAlign: 'center',
useAI: false,
aiNumber: 1,
themeColorCode: '',
scopes: [...apps],
allowCustomScopes: true,
allowEmptyScopes: true,
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
markBreakingChangeMode: true,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
breaklineChar: '|',
skipQuestions: [],
issuePrefixes: [{ value: 'closed', name: 'closed: ISSUES has been processed' }],
customIssuePrefixAlign: 'top',
emptyIssuePrefixAlias: 'skip',
customIssuePrefixAlias: 'custom',
allowCustomIssuePrefix: true,
allowEmptyIssuePrefix: true,
confirmColorize: true,
scopeOverrides: undefined,
defaultBody: '',
defaultIssues: '',
defaultScope: '',
defaultSubject: ''
}
};
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
"name": "@angular-nx-firebase-monorepo/source",
"version": "0.0.0",
"license": "MIT",
"scripts": {},
"scripts": {
"prepare": "is-ci || husky install",
"format": "prettier --write \"**/*.{ts,js,scss,css,html,md,json,yml}\"",
"cm": "git cz",
"clean:repo": "git clean -fd",
"clean:repo:remote": "git remote prune origin",
"clean:repo:old:branches": "git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D"
},
"private": true,
"dependencies": {
"@angular/animations": "~18.2.9",
Expand Down Expand Up @@ -46,6 +53,10 @@
"@angular/cli": "~18.2.10",
"@angular/compiler-cli": "~18.2.9",
"@angular/language-service": "~18.2.9",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@commitlint/config-nx-scopes": "^19.5.0",
"@commitlint/cz-commitlint": "^19.5.0",
"@ngrx/schematics": "~18.1.0",
"@nrwl/nx-cloud": "^19.1.0",
"@nx/devkit": "20.0.6",
Expand All @@ -61,20 +72,26 @@
"@swc-node/register": "~1.10.9",
"@swc/cli": "~0.4.0",
"@swc/core": "~1.7.40",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/express": "5.0.0",
"@types/jest": "^29.5.14",
"@types/node": "22.8.1",
"@typescript-eslint/eslint-plugin": "^8.11.0",
"@typescript-eslint/parser": "^8.11.0",
"commitizen": "^4.3.1",
"cz-git": "^1.10.1",
"eslint": "~9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-playwright": "^2.0.0",
"husky": "^9.1.6",
"is-ci": "^3.0.1",
"jasmine-marbles": "~0.9.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-node": "^29.7.0",
"jest-preset-angular": "~14.2.4",
"jsonc-eslint-parser": "^2.4.0",
"lint-staged": "^15.2.10",
"nx": "20.0.6",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
Expand Down
20 changes: 5 additions & 15 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,12 @@
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@angular-nx-firebase-monorepo/firestore/models": [
"firestore/models/src/index.ts"
],
"@angular-nx-firebase-monorepo/firestore/queries": [
"firestore/queries/src/index.ts"
],
"@angular-nx-firebase-monorepo/firestore/schemas": [
"firestore/schemas/src/index.ts"
],
"@angular-nx-firebase-monorepo/firestore/validators": [
"firestore/validators/src/index.ts"
],
"@angular-nx-firebase-monorepo/firestore/models": ["firestore/models/src/index.ts"],
"@angular-nx-firebase-monorepo/firestore/queries": ["firestore/queries/src/index.ts"],
"@angular-nx-firebase-monorepo/firestore/schemas": ["firestore/schemas/src/index.ts"],
"@angular-nx-firebase-monorepo/firestore/validators": ["firestore/validators/src/index.ts"],
"@angular-nx-firebase-monorepo/plugins": ["plugins/src/index.ts"],
"@angular-nx-firebase-monorepo/utils/errors": [
"utils/errors/src/index.ts"
],
"@angular-nx-firebase-monorepo/utils/errors": ["utils/errors/src/index.ts"],
"@angular-nx-firebase-monorepo/utils/rxjs": ["utils/rxjs/src/index.ts"],
"@angular-nx-firebase-monorepo/utils/ui": ["utils/ui/src/index.ts"]
}
Expand Down
Loading

0 comments on commit 33ccbcc

Please sign in to comment.