# Contributing to Cardinal

## About

## General Contribution

## Design Contribution

## Developer Contribution

### Running Cardinal Locally

<ol class="-ordered">

<li> Clone Cardinal from our <a href="http://bitbucket.us.aegon.com/projects/TAUI/repos/digital-design-system/browse" target="_blank"> bitbucket repo </a>.</li>

<li> Create a <code>.npmrc</code> file at the root of your application. Include the nexus link provided in the <a href="http://dds.us.aegon.com/implementation" target="_blank"> implementation documentation </a> into the  <code>.npmrc</code> file. </li>

<p><span>Note:</span>Cardinal's local environment points to <code>.snapshot</code> for the latest code in development. <code>.release</code> is code readily available to all teams as official releases in accordance to our road-map. </p>

<li> In your terminal,</li>
<p> <code> npm i </code> </p>
<p> <code>npm start</code> </p>

<br>

<p class="note"><span>Note;</span>If your default browser doesn't open automatically, navigate in you preferred browser to `localhost:4200`. Make sure you are not running another developer environment on `4200`, you may need to adjust close other projects on this.</p>

</ol>

### Code Contribution

#### Developing an Element with Cardinal

---
We are not currently using the Angular CLI for building our [Angular Elements](https://angular.io/guide/elements). We will be improving our development process in the very near future with [Angular Schematics](https://angular.io/guide/schematics) and other tools. Until then, here is the current set up for getting started with developing a custom web component.

<br>

<ol class="-ordered">
  <li> Follow the steps found above in "Running Cardinal Locally"</li>
  <li> From the root of the directory, go to <code>projects/cardinal/src</code>.</li>
  <p><span class="note">This is where our Angular Elements, shared js, config assets and Core Styles live.</p>
  <li>Duplicate components folder and rename it to your component. We use the example of duplicating our hero web component.</li>
  <li> In your newly duplicated file, replace the use of "hero" in all child and relative files and folders to your component name.</li>
  <li> In the root of the Cardinal app, in the <code>angular.json</code> file, create a new section under the hero component section. </li>

<p class="note"><span>Note:</span>The structure should look like:</p>

```json
"<your-component-name>": {
  "root": "projects/cardinal/src/components/<your-component-name>",
  "sourceRoot": "projects/cardinal/src/components/<your-component-name>/src",
  "projectType": "application",
  "architect": {
    "build": {
      "builder": "@angular-builders/custom-webpack:browser",
      "options": {
        "customWebpackConfig": {
          "path": "projects/cardinal/src/components/<your-component-name>/<your-component-name>-webpack.config.js",
          "mergeStrategies": {
            "externals": "replace"
          }
        },
        "outputPath": "tmp/<your-component-name>",
        "index": "src/index.html",
        "main": "./projects/cardinal/src/components/<your-component-name>/main.ts",
        "tsConfig": "./projects/cardinal/src/components/<your-component-name>/tsconfig.json",
        "styles": [
          "projects/cardinal/src/styles/components/<your-component-name>/<your-component-name>.component.scss"
        ],
        "stylePreprocessorOptions": {
          "includePaths": [
            "projects/cardinal/src/styles/components/"
          ]
        }
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "./projects/cardinal/src/components/environments/environment.ts",
              "with": "./projects/cardinal/src/components/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "aot": true,
          "sourceMap": false,
          "buildOptimizer": true
        }
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "projects/cardinal/src/components/<your-component-name>/test.ts",
        "polyfills": "projects/cardinal/src/components/<your-component-name>/polyfills.ts",
        "tsConfig": "projects/cardinal/src/components/<your-component-name>/tsconfig.spec.json",
        "karmaConfig": "src/karma.conf.js",
        "styles": [
          "projects/cardinal/src/styles/components/<your-component-name>/<your-component-name>.component.scss"
        ],
        "stylePreprocessorOptions": {
          "includePaths": [
            "projects/cardinal/src/styles/components/"
          ]
        }
      }
    }
  }
},
```

<br>

<li> Create a file with your component's name in the packages folder <code>projects/cardinal/packages/<"your-component"></code> </li>

<li> Create a <code>package.json</code> file in your new package folder.</li>

<p class="note"><span>Note:</span>Your file should look like: </p>

```json
{
  "name": "@cardinal/<your-component-name>",
  "version": "0.0.1",
  "type": "component",
  "files": ["<your-component-name>.js", "<your-component-name>.scss"],
  "dependencies": {
    "@cardinal/some-cardinal-dependency": "that dependencies version",
  }
}
```

<br>

<li>In your terminal, </li>
<ol class="-ordered">
  <li><code>npm run dist-components</code></li>
  <li><code>npm run develop-component <"component-name"></code> to begin the angular element</li>
</ol>

<li> In the root angular.json file, find the <code>scripts</code> array via <code>digital-design-system</code> > <code>architect</code> > <code>build</code> >  <code>options</code> >  <code>scripts</code>, and the route to your new component. Then insert this <code>"dist/cardinal/<your-component>/<"your-component.js">"</code>.</li>

<li> Place your component in the  <code>src/app/pages/staging/component-staging/component-staging.page.html</code> html. You should see your element at <a href="/component-staging">/component-staging</a>. </li>

<li>Run `npm run test` to execute the unit tests via <a href="https://karma-runner.github.io)" target="_blank">Karma</a>. Tests should cover 100% of your component. We do understand some component functionality is challenging to test, 80% as the Transamerica Digital Guidelines suggest is appropriate. </li>

<li>Provide documentation of how your component works and any nuances we need to know. We are happy to sit with you and note this during a walk through to assist in documentation creation.</li>

<li>Once you have completed development, create a ***pull request*** to merge into Cardinal</li>

#### Expectations

Our expectations are...

<br>

### Developing an Angular Component with Cardinal

---

Cardinal's Angular components library utilizes [Angular Libraries](https://angular.io/guide/creating-libraries) and generated with the [Angular CLI](https://github.com/angular/angular-cli).

<br>

#### Generating components

<br>

Run `ng g c <your-component-name> --project=cardinal-ng` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project=cardinal-ng`.

> Note: Don't forget to add `--project=cardinal-ng` or else it will be added to the default project in your `angular.json` file.

<br>

#### Build & Display

<br>

There are a few steps to this. In your terminal:

1. `npm run dist-components` to build a `dist/` directory at the root of the application.
2. `npm run develop-cardinal-ng` to build the project and watch for changes. The build artifacts will be stored in the `dist/` directory.
3. Declare and export your new angular component in the `projects/cardinal-ng/src/lib/cardinal-ng.module.ts` file.
4. Import component via npm locally `npm install dist/cardinal-ng --save-optional`
5. Uncomment the import statement in of the npm package into the `app.module.ts` file.
6. Place your component in the `src/app/pages/staging/component-staging/component-staging.page.html` html. You should see your element at [/component-staging](/component-staging).

<br>

#### Publishing

<br>

Only Cardinal developers will publish components or other assets to NPM. This is how we maintain and act as gatekeepers to provide feedback, recommendations and or implement your feedback immediately.

<br>

#### Running unit tests

<br>

Run `ng test cardinal-ng` to execute the unit tests via [Karma](https://karma-runner.github.io). Tests should cover 100% of your component. We do understand some component functionality is challenging to test, 80% as the Transamerica Digital Guidelines suggest is appropriate.

---

## Need Assistance?

Contact the Cardinal team on [MS Teams](https://teams.microsoft.com/l/channel/19%3a44212ebbbc624d28b6900491bf973caa%40thread.skype/Cardinal%2520(Digital%2520Design%2520System)?groupId=37025936-13d1-4eac-a0dd-5e50de1b27a1&tenantId=46e16835-c804-41de-be3c-55835d14dee4).
