|
1 | | -# WIP |
| 1 | +# Contributing to *crda-javascript-api*<br/>![nodejs-version][10] |
| 2 | + |
| 3 | +* Fork the repository |
| 4 | +* Create a new branch |
| 5 | +* Commit your changes |
| 6 | +* Commits <strong>must</strong> be signed-off (see [Certificate of Origin](#certificate-of-origin)) |
| 7 | +* Create a pull request against the main branch |
| 8 | +* Pull request titles <strong>must</strong> adhere the [Conventional Commits specification][0] |
| 9 | + |
| 10 | +## Development |
| 11 | + |
| 12 | +### NPM Scripts |
| 13 | + |
| 14 | +* `npm run compile` compile all _TS_ and _JS_ code into the _dist_ folder |
| 15 | +* `npm run lint` run eslint on _JS_ source code |
| 16 | +* `npm run lint:fix` fix eslint issues found in _JS_ source code |
| 17 | +* `npm run test` run unit tests,verify coverage, and print coverage info |
| 18 | +* `npm run tests` run unit tests (no coverage) |
| 19 | +* `npm run tests:rep` run unit tests and save the test results as _unit-tests-result.json_ (for ci) |
| 20 | +* `npm run gen:backend` generate the _Backend_ types from its _OpenAPI_ as _TS_ spec in the _generated/backend_ folder |
| 21 | + |
| 22 | +### OpenAPI Specifications |
| 23 | + |
| 24 | +We use our [Backend's OpenAPI spec file][1] for generating types used for deserialization of the Backend's |
| 25 | +API responses.<br/> |
| 26 | +The generated classes files are _TypeScript_ files generated in the [generated/backend](generated/backend). |
| 27 | +Which is skipped when calculating coverage thresholds. **Avoid writing code in this folder.**<br/> |
| 28 | +When the [Backend's spec file][1] is modified, we need to **manually** run the `npm run gen:backend` script. |
| 29 | +We only generate types. |
| 30 | + |
| 31 | +### Code Walkthrough |
| 32 | + |
| 33 | +* [index.js](src/index.js) is the _ESM Module_ starting point. It exports 2 functions: _componentAnalysis_ and _stackAnalysis_. |
| 34 | + As well as the _AnalysisReport_ type imported from the _Backend_'s generated classes. |
| 35 | +* [cli.js](src/cli.js) is the starting point of the _CLI Script_, also used when installed as a _Global Package_. |
| 36 | + It describes two commands: _component_ and _stack_. Use the _help_ command to get more info. |
| 37 | +* [analysis.js](src/analysis.js) exports two functions for communicating to the _Backend_. |
| 38 | + The _requestComponent_ and _requestStack_ functions. |
| 39 | +* [provider.js](src/provider.js) hosts the utility function for matching _Providers_ based on the manifest type. |
| 40 | + New providers needs to be listed here. |
| 41 | +* [providers](src/providers) folder is where we place _Providers_. A _Provider_ is basically 3 functions per supported ecosystem. |
| 42 | + The _isSupported_, _provideComponent_, and _provideStack_ functions help determine the appropriate provider, |
| 43 | + which will provide data that we can send to the _Backend_ using _analysis.js_. See the [Adding a Provider](#adding-a-provider) section. |
| 44 | + * [java_maven.js](src/providers/java_maven.js) is the provider for the _Java_ _Maven_ ecosystem. |
| 45 | + |
| 46 | +#### Types |
| 47 | + |
| 48 | +This code is meant to be used as an _ESM_ module for both _JavaScript_ and _TypeScript_. So make sure you add type declarations if needed.<br/> |
| 49 | +Note the [sources](src) are in _JavaScript_, and the [generated](generated/backend) _Backend_ types are in _TypeScript_. |
| 50 | +Both will be compiled as an _ESM Module_ including declarations (_x.d.ts_) in the ignored _dist_ using the `npm run compile` script |
| 51 | +and the [tsconfig.json](tsconfig.json) configuration file. Also note the _TypeScript_ files are excluded from both linting and coverage. |
| 52 | + |
| 53 | +#### Adding a Provider |
| 54 | + |
| 55 | +* Add the new provider code in a designated file in the [providers'](src/providers) folder. |
| 56 | + A _Provider_ exports 3 functions: |
| 57 | + * _isSupported_ takes a manifest name as a string, i.e. _pom.xml_ and returns _true_ if it's supported by this provider. |
| 58 | + * _provideComponent_ takes the **manifest's content** as a string and returns the ecosystem name, the content for the request body, and the content's type. |
| 59 | + * _provideStack_ takes the **manifest's path** as a string and the ecosystem name, the content for the request body, and the content's type. |
| 60 | + |
| 61 | + The data returning from the _provideX_ functions, will be passed on to the [analysis.js](src/analysis.js) for sending to the _Backend_. |
| 62 | + Use [java_maven.js](src/providers/java_maven.js) as an example to get you started. |
| 63 | +* Import the new _Provider_ and list in the in _availableProviders_ array in [provider.js](src/provider.js). |
| 64 | +* Update the _choices_ configuration for the _manifest-name_ positional argument in [cli.js](src/cli.js). |
| 65 | +* Update the documentation. This document and [README.md](README.md). |
| 66 | + |
| 67 | +## Certificate of Origin |
| 68 | + |
| 69 | +By contributing to this project you agree to the Developer Certificate of |
| 70 | +Origin (DCO). This document was created by the Linux Kernel community and is a |
| 71 | +simple statement that you, as a contributor, have the legal right to make the |
| 72 | +contribution. See the [DCO](DCO) file for details. |
| 73 | + |
| 74 | +<!-- Real links --> |
| 75 | +[0]: https://www.conventionalcommits.org/en/v1.0.0/ |
| 76 | +[1]: https://github.com/RHEcosystemAppEng/crda-backend/blob/main/src/main/resources/META-INF/openapi.yaml |
| 77 | + |
| 78 | +<!-- Badge links --> |
| 79 | +[10]: https://badgen.net/badge/NodeJS%20Version/18/68a063 |
0 commit comments