Skip to content

actionanand/ng16-signal-milestone-release

Repository files navigation

Ng16SignalMilestoneRelease

This project was generated with Angular CLI version 16.0.0.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The application will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.

Cloning Guide

  1. Clone only the remote primary HEAD (default: origin/master)
git clone <url> --single-branch
  1. Only specific branch
git clone <url> --branch <branch> --single-branch [<folder>]
git clone <url> --branch <branch>
  1. Cloning repositories using degit

    • master branch is default.
npx degit github:user/repo#branch-name <folder-name>
  1. Cloning this project with skeleton
git clone https://github.com/actionanand/ng16-signal-milestone-release.git --branch 1-skeleton-ngv16 angular-proj-name
npx degit github:actionanand/ng16-signal-milestone-release#1-skeleton-ngv16 angular-proj-name

Automate using Prettier, Es Lint and Husky

  1. Install the compatible node version
  nvm install v16.20.0
  1. Install and Configure Prettier

    • Install prettier as below:
      yarn add prettier -D
    • Create a .prettierrc file and write down the format as below: - online ref
    trailingComma: 'all'
    tabWidth: 2
    useTabs: false
    semi: true
    singleQuote: true
    bracketSpacing: true
    bracketSameLine: true
    arrowParens: 'avoid'
    printWidth: 120
    overrides:
      - files:
          - '*.js'
          - '*.jsx'
        options:
          bracketSpacing: true
          jsxSingleQuote: true
          semi: true
          singleQuote: true
          tabWidth: 2
          useTabs: false
      - files:
          - '*.ts'
        options:
          tabWidth: 2
    • Create a .prettierignore file and write as below(sample)
    # Ignore artifacts:
    build
    coverage
    e2e
    node_modules
    dist
    dest
    reports
    
    # Ignore files
    *.lock
    package-lock.json
    yarn.lock
  2. Install Es Lint, if not installed

ng add @angular-eslint/schematics
  1. Configure pre-commit hooks

Pre-commit hooks are a nice way to run certain checks to ensure clean code. This can be used to format staged files if for some reason they weren’t automatically formatted during editing. husky can be used to easily configure git hooks to prevent bad commits. We will use this along with pretty-quick to run Prettier on our changed files. Install these packages, along with npm-run-all, which will make it easier for us to run npm scripts:

yarn add husky pretty-quick npm-run-all -D

To configure the pre-commit hook, simply add a precommit npm script. We want to first run Prettier, then run TSLint on the formatted files. To make our scripts cleaner, I am using the npm-run-all package, which gives you two commands, run-s to run scripts in sequence, and run-p to run scripts in parallel:

  "precommit": "run-s format:fix lint",
  "format:fix": "pretty-quick --staged",
  "format:check": "prettier --config ./.prettierrc --list-different \"src/{app,environments,assets}/**/*{.ts,.js,.json,.css,.scss}\"",
  "format:all": "prettier --config ./.prettierrc --write \"src/{app,environments,assets}/**/*{.ts,.js,.json,.css,.scss}\"",
  "lint": "ng lint",
  1. Initialize husky

    • Run it once
      npm pkg set scripts.prepare="husky install"
      npm run prepare
    • Add a hook
      npx husky add .husky/pre-commit "yarn run precommit"
      npx husky add .husky/pre-commit "yarn test"
      git add .husky/pre-commit
    • Make a commit
      git commit -m "Keep calm and commit"
      # `yarn run precommit and yarn test` will run every time you commit
  2. How to skip prettier format only in particular file

    1. JS
    matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
    
    // prettier-ignore
    matrix(
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
      )
    1. JSX
    <div>
      {/* prettier-ignore */}
      <span     ugly  format=''   />
    </div>
    1. HTML
    <!-- prettier-ignore -->
    <div         class="x"       >hello world</div            >
    
    <!-- prettier-ignore-attribute -->
    <div (mousedown)="       onStart    (    )         " (mouseup)="         onEnd      (    )         "></div>
    
    <!-- prettier-ignore-attribute (mouseup) -->
    <div (mousedown)="onStart()" (mouseup)="         onEnd      (    )         "></div>
    1. CSS
    /* prettier-ignore */
    .my    ugly rule
      {
    
      }
    1. Markdown
      <!-- prettier-ignore -->
    
    Do not format this
    1. YAML
    # prettier-ignore
    key  : value
      hello: world
    1. For more, please check

Resources

  1. Angular v16 is here! - Official
  2. What's new in Angular 16
  3. Angular 16 previews new reactivity model
  4. 🅰️ New Angular 16 is Going Big in 2023: Everything You Need to Know
  5. Lazy loading services in Angular. What?! Yes, we can.
  6. Angular 🚦 Signals 📡 (The future of Angular)
  7. Signals in Angular – How to Write More Reactive Code
  8. Upgrading an enterprise app to Angular 16

image

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI Overview and Command Reference page.

Angular compatibility list

  npx ngvm compat
  1. Is there a compatibility list for Angular / Angular-CLI and Node.js? - stackoverflow
  2. Version compatibility - Angular official
  3. Angular version node compatibility - gist