# mina-sidor-fa

The project was generated using [Nx](https://nx.dev).

## Quick Start & Documentation

For all commands we will refer to the `npm scripts` located inside [package.json](./package.json). When using these commands, you do not need to have `@angular/cli` installed globally on your computer.

To get started, clone the repository and run `npm install` in the root of the project, this will install all dependencies.

### Development server mina-sidor-fa

Run `npm start` for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

#### Dotnet API

Run `npm run start:api` to run against the Dotnet API.

### Generate an application

Run `npm run new-app my-app` to generate an application. When using Nx, you can create multiple applications and libraries in the same workspace.

### Generate a library

Run `npm run new-lib my-lib` to generate a library. Libraries are shareable across libraries and applications. They can be imported from `@mina-sidor-fa/mylib`.

### Code scaffolding

Run `npm run new-component my-component --project=my-app` to generate a new component.

### Build mina-sidor-fa

Run `npm run build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.

#### Mock-api

If you want to use the mock-api, read the README [here](./mock-api/mina-sidor-fa).

#### Dotnet API

Run `npm run build:api` to build the project using the Dotnet API.

### Running unit tests on mina-sidor-fa

Run `npm run test` to execute the unit tests via [Jest](https://jestjs.io).

Run `npm run nx affected:test` to execute the unit tests affected by a change.

### Running end-to-end tests on mina-sidor-fa

Run `npm run e2e` to execute the end-to-end tests via [Cypress](https://www.cypress.io).

Run `npm run nx affected:e2e` to execute the end-to-end tests affected by a change.

### Understand your workspace

Run `npm run nx dep-graph` to see a diagram of the dependencies of your projects.

## Git workflow

- Use branching model [Gitflow](http://nvie.com/posts/a-successful-git-branching-model/).
  - Example: `feature/TV-XXXX` or `bugfix/TV-XXXX`
  - A useful CLI helper tool can be used: [gitflow-avh](https://github.com/petervanderdoes/gitflow-avh).
- Clone origin, create feature/bugfix branches and push back to origin.
- Don't forget to commit and push your changes regulary!
- Create a pull request for each feature branch.
- When merging the pull request, follow [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) structure inside the merge message.

  - The merge-message, which follows conventional commits, will be added to the CHANGELOG after a release is made.
  - A commit message could look like this: `feat(startpage): Added headings and description to the startpage (TV-1234)`.
  - The changelog would look something like this:

    ```md
    ### Features

    - **startpage:** Added headings and description to the startpage ([TV-1234](https://jira.arbetsformedlingen.se/browse/TV-1234)) ([commit-hash](https://bitbucket.arbetsformedlingen.se/projects/tea/repos/mina-sidor-fa-web/commits/commit-hash))
    ```

- Upon merge, Open Shift will deploy the application to [AUTO](http://mina-sidor-fa-auto.tocp.arbetsformedlingen.se) and [SYS](http://mina-sidor-fa-sys.tocp.arbetsformedlingen.se).

## Release and deploy

We use a semi-automated release and deploy to different test-enviroments. A release script is used in combination with [semantic-release](https://semantic-release.gitbook.io/semantic-release/) to add the correct version of the application and changes to the changelog. The deployments are made depending on which branches are updated:

- `develop` is automatically deployed to [AUTO](http://mina-sidor-fa-auto.tocp.arbetsformedlingen.se) and [SYS](http://mina-sidor-fa-sys.tocp.arbetsformedlingen.se).
- `next` is automatically deployed to [TEST](http://mina-sidor-fa-test.tocp.arbetsformedlingen.se).
- `main` is automatically deployed to [ACC](http://mina-sidor-fa-acc.tocp.arbetsformedlingen.se). After this is completed, a question needs to be answered whether the image should be deployed to PROD.

### Deploy to TEST

To deploy the application to TEST you need to create a release. Make sure you are in the `develop` branch and are up-to-date with origin. Then run `npm run release`. This will:

- Update the [CHANGELOG.md](CHANGELOG.md) and copies the CHANGELOG to assets.
- Bump the applications version according to semantic versioning.
- Commits the CHANGELOG to `develop` and pushes it to origin.
- Merge `develop` into `next` and pushes `next` to origin.

Open Shift will deploy the application to [TEST](http://mina-sidor-fa-test.tocp.arbetsformedlingen.se).

### Release to ACC and PROD

To release the latest version of `next` to ACC and eventually to PROD; a pull request should be created to merge `next` into `main`. The `next` branch is protected and will not be deleted upon merge.

Open Shift will deploy the application to [ACC](http://mina-sidor-fa-acc.tocp.arbetsformedlingen.se) and a question inside the pipeline is asked if the application also should be deployed to PROD. This question will persist for 24 hours.

## General Nx documentation

[Nx Documentation](https://nx.dev/angular)

[10-minute video showing all Nx features](https://nx.dev/angular/getting-started/what-is-nx)

[Interactive Tutorial](https://nx.dev/angular/tutorial/01-create-application)
