From 5e58efe992904c2592f7d208437aab1ef4ff281d Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <124715224+DhairyaMajmudar@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:56:20 +0530 Subject: [PATCH 01/15] docs: minor updation in generated files output folder path (#1263) --- apps/generator/docs/generator-template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/generator/docs/generator-template.md b/apps/generator/docs/generator-template.md index be84e4587..e9643234e 100644 --- a/apps/generator/docs/generator-template.md +++ b/apps/generator/docs/generator-template.md @@ -159,7 +159,7 @@ To see this in action, navigate to the **python-mqtt-client-template** directory ``` cmd Generation in progress. Keep calm and wait a bit... done -Check out your shiny new generated files at output. +Check out your shiny new generated files at test/project. ``` Navigating to the **test/project** directory. You should see a **client.py** file; the only content is `Temperature Service`. From 001bbcd0a1cfe37905d3f7533b33a4c9900310d3 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:42:38 +0200 Subject: [PATCH 02/15] docs: add DhairyaMajmudar as a contributor for bug (#1266) --- .all-contributorsrc | 9 +++++++++ README.md | 1 + 2 files changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 149459782..c25044ade 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -196,6 +196,15 @@ "test", "doc" ] + }, + { + "login": "DhairyaMajmudar", + "name": "Dhairya Majmudar", + "avatar_url": "https://avatars.githubusercontent.com/u/124715224?v=4", + "profile": "https://dhaiyra-majmudar.netlify.app/", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 3, diff --git a/README.md b/README.md index 74d2c5056..c525d69b8 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d pierrick-boule
pierrick-boule

💻 ⚠️ 📖 + Dhairya Majmudar
Dhairya Majmudar

🐛 From 60a788dea7b6ac8783670dbbc1d83a829683cca2 Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <124715224+DhairyaMajmudar@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:36:03 +0530 Subject: [PATCH 03/15] ci: minor fix in update docs workflow (#1267) Co-authored-by: asyncapi-bot --- .github/workflows/update-docs-in-website.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-docs-in-website.yml b/.github/workflows/update-docs-in-website.yml index b39628970..7501f2565 100644 --- a/.github/workflows/update-docs-in-website.yml +++ b/.github/workflows/update-docs-in-website.yml @@ -6,6 +6,7 @@ on: - 'master' paths: - 'apps/generator/docs/*.md' + - '.github/workflows/update-docs-in-website.yml' jobs: Make-PR: @@ -39,7 +40,7 @@ jobs: mkdir -p ./markdown/docs/tools/generator rm ../generator/apps/generator/docs/README.md rm -r ../generator/apps/generator/docs/jsdoc2md-handlebars - printf "%s\ntitle: Generator\nweight: 3\n%s" "---" "---"> ../generator/docs/_section.md + printf "%s\ntitle: Generator\nweight: 3\n%s" "---" "---"> ../generator/apps/generator/docs/_section.md mv ../generator/apps/generator/docs/*.md ./markdown/docs/tools/generator - name: Commit and push working-directory: ./website From 48441cba7e8b65e0e60031fb5f61e69bc7fa74d9 Mon Sep 17 00:00:00 2001 From: asyncapi-bot Date: Wed, 11 Sep 2024 15:29:06 +0200 Subject: [PATCH 04/15] fix: update @asyncapi/generator-react-sdk to 1.1.2 version and others (#1268) --- apps/generator/package.json | 6 +++--- .../test-templates/nunjucks-template/package-lock.json | 8 ++++---- .../test/test-templates/nunjucks-template/package.json | 2 +- .../test-templates/react-template/package-lock.json | 8 ++++---- .../test/test-templates/react-template/package.json | 2 +- package-lock.json | 10 +++++----- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/generator/package.json b/apps/generator/package.json index 3dbc021b1..e919b8902 100644 --- a/apps/generator/package.json +++ b/apps/generator/package.json @@ -49,7 +49,7 @@ "license": "Apache-2.0", "homepage": "https://github.com/asyncapi/generator", "dependencies": { - "@asyncapi/generator-react-sdk": "^1.1.1", + "@asyncapi/generator-react-sdk": "^1.1.2", "@asyncapi/multi-parser": "^2.1.1", "@asyncapi/nunjucks-filters": "*", "@asyncapi/parser": "^3.0.14", @@ -81,11 +81,11 @@ "eslint-plugin-jest": "^23.8.2", "eslint-plugin-react": "^7.34.1", "eslint-plugin-sonarjs": "^0.5.0", + "fs-extra": "9.1.0", "jest": "^27.3.1", "jsdoc-to-markdown": "^7.1.1", "markdown-toc": "^1.2.0", "rimraf": "^3.0.2", - "unixify": "^1.0.0", - "fs-extra": "9.1.0" + "unixify": "^1.0.0" } } diff --git a/apps/generator/test/test-templates/nunjucks-template/package-lock.json b/apps/generator/test/test-templates/nunjucks-template/package-lock.json index d1f6ed151..a72376f24 100644 --- a/apps/generator/test/test-templates/nunjucks-template/package-lock.json +++ b/apps/generator/test/test-templates/nunjucks-template/package-lock.json @@ -8,7 +8,7 @@ "name": "nunjucks-template", "version": "0.0.1", "dependencies": { - "@asyncapi/generator-react-sdk": "^1.1.1" + "@asyncapi/generator-react-sdk": "^1.1.2" } }, "node_modules/@ampproject/remapping": { @@ -25,9 +25,9 @@ } }, "node_modules/@asyncapi/generator-react-sdk": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@asyncapi/generator-react-sdk/-/generator-react-sdk-1.1.1.tgz", - "integrity": "sha512-R86Xa20wLtzI4fVf9HECR+UCSYvNE1B4WZs3eI5jAvGtONBTFOvkixd4SUL+uLP4DP96pU2DuKhih/PQbmMneQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@asyncapi/generator-react-sdk/-/generator-react-sdk-1.1.2.tgz", + "integrity": "sha512-hU9ux8hEMhXwQWWzySZlZ+L5SsM0r4uXdPFvYRTX5uVGeLKGoj4Ok8hY2gPhahKcvMELOIU2mw3O6h9h9AcskQ==", "dependencies": { "@asyncapi/parser": "^3.1.0", "@babel/core": "7.12.9", diff --git a/apps/generator/test/test-templates/nunjucks-template/package.json b/apps/generator/test/test-templates/nunjucks-template/package.json index e6c43bf61..531d63fcc 100644 --- a/apps/generator/test/test-templates/nunjucks-template/package.json +++ b/apps/generator/test/test-templates/nunjucks-template/package.json @@ -16,6 +16,6 @@ } }, "dependencies": { - "@asyncapi/generator-react-sdk": "^1.1.1" + "@asyncapi/generator-react-sdk": "^1.1.2" } } diff --git a/apps/generator/test/test-templates/react-template/package-lock.json b/apps/generator/test/test-templates/react-template/package-lock.json index c42587539..9d895fc52 100644 --- a/apps/generator/test/test-templates/react-template/package-lock.json +++ b/apps/generator/test/test-templates/react-template/package-lock.json @@ -8,7 +8,7 @@ "name": "react-template", "version": "0.0.1", "dependencies": { - "@asyncapi/generator-react-sdk": "^1.1.1" + "@asyncapi/generator-react-sdk": "^1.1.2" } }, "node_modules/@ampproject/remapping": { @@ -25,9 +25,9 @@ } }, "node_modules/@asyncapi/generator-react-sdk": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@asyncapi/generator-react-sdk/-/generator-react-sdk-1.1.1.tgz", - "integrity": "sha512-R86Xa20wLtzI4fVf9HECR+UCSYvNE1B4WZs3eI5jAvGtONBTFOvkixd4SUL+uLP4DP96pU2DuKhih/PQbmMneQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@asyncapi/generator-react-sdk/-/generator-react-sdk-1.1.2.tgz", + "integrity": "sha512-hU9ux8hEMhXwQWWzySZlZ+L5SsM0r4uXdPFvYRTX5uVGeLKGoj4Ok8hY2gPhahKcvMELOIU2mw3O6h9h9AcskQ==", "dependencies": { "@asyncapi/parser": "^3.1.0", "@babel/core": "7.12.9", diff --git a/apps/generator/test/test-templates/react-template/package.json b/apps/generator/test/test-templates/react-template/package.json index 610fcf223..5f430552e 100644 --- a/apps/generator/test/test-templates/react-template/package.json +++ b/apps/generator/test/test-templates/react-template/package.json @@ -18,6 +18,6 @@ } }, "dependencies": { - "@asyncapi/generator-react-sdk": "^1.1.1" + "@asyncapi/generator-react-sdk": "^1.1.2" } } diff --git a/package-lock.json b/package-lock.json index 45663cb5b..434b3c16e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,10 +20,10 @@ }, "apps/generator": { "name": "@asyncapi/generator", - "version": "2.3.0", + "version": "2.4.1", "license": "Apache-2.0", "dependencies": { - "@asyncapi/generator-react-sdk": "^1.1.1", + "@asyncapi/generator-react-sdk": "^1.1.2", "@asyncapi/multi-parser": "^2.1.1", "@asyncapi/nunjucks-filters": "*", "@asyncapi/parser": "^3.0.14", @@ -208,9 +208,9 @@ "link": true }, "node_modules/@asyncapi/generator-react-sdk": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@asyncapi/generator-react-sdk/-/generator-react-sdk-1.1.1.tgz", - "integrity": "sha512-R86Xa20wLtzI4fVf9HECR+UCSYvNE1B4WZs3eI5jAvGtONBTFOvkixd4SUL+uLP4DP96pU2DuKhih/PQbmMneQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@asyncapi/generator-react-sdk/-/generator-react-sdk-1.1.2.tgz", + "integrity": "sha512-hU9ux8hEMhXwQWWzySZlZ+L5SsM0r4uXdPFvYRTX5uVGeLKGoj4Ok8hY2gPhahKcvMELOIU2mw3O6h9h9AcskQ==", "dependencies": { "@asyncapi/parser": "^3.1.0", "@babel/core": "7.12.9", From c4c49bab8694672c8834d98c9abacd9674dfcd40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 29 Sep 2024 03:01:08 +0200 Subject: [PATCH 05/15] chore(deps): bump rollup from 2.79.1 to 2.79.2 in /apps/generator/test/test-templates/nunjucks-template (#1271) --- .../test/test-templates/nunjucks-template/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/generator/test/test-templates/nunjucks-template/package-lock.json b/apps/generator/test/test-templates/nunjucks-template/package-lock.json index a72376f24..b6bad24bc 100644 --- a/apps/generator/test/test-templates/nunjucks-template/package-lock.json +++ b/apps/generator/test/test-templates/nunjucks-template/package-lock.json @@ -3693,9 +3693,9 @@ } }, "node_modules/rollup": { - "version": "2.79.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", - "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", + "version": "2.79.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.2.tgz", + "integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==", "bin": { "rollup": "dist/bin/rollup" }, From 1f06df5d0f82ec481dceb2063ddc132afd42e5e6 Mon Sep 17 00:00:00 2001 From: Mintu Gogoi <127925465+Gmin2@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:57:16 +0530 Subject: [PATCH 06/15] docs: add the development guide on how to run test (#1250) Co-authored-by: Florence Njeri <40742916+Florence-Njeri@users.noreply.github.com>%0ACo-authored-by: Lukasz Gornicki --- Development.md | 187 ++++++++++++++++++ README.md | 91 +-------- .../react-template/package.json | 2 +- 3 files changed, 190 insertions(+), 90 deletions(-) create mode 100644 Development.md diff --git a/Development.md b/Development.md new file mode 100644 index 000000000..f62d50476 --- /dev/null +++ b/Development.md @@ -0,0 +1,187 @@ +# Development guide + +This guide will help you set up the `generator` locally, run tests, and use Docker for isolated testing. + +## Getting started + +1. Fork & Clone the repository: + +First fork the repository from github and then clone it, + +```bash +git clone https://github.com/{your_username}/generator.git +cd generator +``` + +After cloning the repository, you should setup the fork properly and configure the `remote` repository as described [here](https://github.com/asyncapi/community/blob/master/git-workflow.md) + +2. Install dependencies: + +```bash +npm install +``` + +## Running tests + +### Local testing + +To run all tests locally: + +- Unit tests: `npm run generator:test:unit` +- Integration tests: `npm run generator:test:integration` +- CLI tests: `npm run generator:test:cli` + +### Adding tests + +1. Create new test files in the appropriate directory under `apps/generator/test/`: + +2. Follow the existing test patterns. + +3. Run your new tests using the commands mentioned above. + +## Docker isolated testing + +To run tests in an isolated Docker environment: + +1. Ensure Docker is installed and running on your machine. + +2. Run the following command from the project root: + +```bash +docker run --rm -v ${PWD}:/app -w /app node:18 sh -c " +cp -r /app /tmp/app && +cd /tmp/app && +npm install && +npm test +" +``` + +This command above does the following: +- Mounts the current directory to `/app` in the container +- Copies the project to a temporary directory +- Installs dependencies +- Runs all tests + +Note: This approach ensures a clean environment for each test run by removing any existing `node_modules`. + +### Manually testing with test templates + +To test template features manually we have `react-template` and `nunjucks-template` in `apps/generator/test/templates`, you can use this templates to manually test your changes like this: + +1. Navigate to the generator directory: + +```bash +cd apps/generator +``` +2. Modify the react-template in `./test/test-templates/react-template` to test different features. + +3. Run the generator with the react-template: + +```bash +asyncapi generate fromTemplate ./test/docs/dummy.yml ./test/test-templates/react-template -o ./test/output --force-write +``` + +4. Check the output in the `./test/output` directory to verify the output that you desired. + +## Release process + +To release a major/minor/patch: + +### Conventional Commits: + +To maintain a clear git history of commits and easily identify what each commit changed and whether it triggered a release, we use conventional commits. The feat and fix prefixes are particularly important as they are needed to trigger changesets. Using these prefixes ensures that the changes are correctly categorized and the versioning system functions as expected. + +For Example: +``` +feat: add new feature +``` + +#### Manual + +1. Create a new release markdown file in the `.changeset` directory. The filename should indicate what the change is about. + +2. Add the following content to the file in this particular format: + + ```markdown + --- + "@package-name-1": [type] (major/minor/patch) + "@package-name-2": [type] + --- + + [Provide a brief description of the changes. For example: Added a new Release GitHub Flow to the Turborepo. No new features or bugfixes were introduced.] + ``` + + For Example: + + ```markdown + --- + "@asyncapi/generator": minor + --- + + Adding new Release Github Flow to the Turborepo. No new features or bugfixes were introduced. + + ``` + +3. Include the file in your pull request. + +#### Using CLI + +1. Create a new release markdown file using changeset CLI. Below command will trigger an interactive prompt that you can use to specify release type and affected packages. + ```cli + npx -p @changesets/cli@2.27.7 changeset + ``` + +2. Include the file in your pull request. + +> [!TIP] +> For more detailed instructions, you can refer to the official documentation for creating a changeset: +[Adding a changeset](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md) + +### Release Flow: + +1. **Add a Changeset**: + - When you make changes that need to be released, create a markdown file in the `.changeset` directory stating the package name and level of change (major/minor/patch). + +2. **Open a Pull Request**: + - Push your changes and open a Pull Request (PR). After the PR is merged the changeset file helps communicate the type of changes (major, minor, patch). + +3. **CI Processes Changeset**: + - After PR is merged, a dedicated GitHub Actions release workflow runs using changeset action, + + - This action reads the markdown files in the `.changeset` folder and creates a PR with the updated version of the package and removes the markdown file. For example: + + Before: + ```json + "name": "@asyncapi/generator", + "version": "2.0.1", + ``` + + After: + ```json + "name": "@asyncapi/generator", + "version": "3.0.1", + ``` + + - The new PR will also contain the description from the markdown files, + + - AsyncAPI bot automatically merge such release PR. + +4. **Release the Package**: + + - After the PR is merged, the CI/CD pipeline triggers again. The `changesets/action` step identifies that the PR was created by itself. It then verifies if the current version of the package is greater than the previously released version. If a difference is detected, it executes the publish command to release the updated package. + +## Additional commands + +- Lint the code: `npm run lint` +- Generate documentation: `npm run docs` +- Build Docker image: `npm run docker:build` + +## Troubleshooting + +If you encounter any issues during development or testing, please check the following: + +1. Ensure you're using the correct Node.js version (18.12.0 or higher) and npm version (8.19.0 or higher). +2. Clear the `node_modules` directory and reinstall dependencies if you encounter unexpected behavior. +3. For Docker-related issues, make sure Docker is running and you have sufficient permissions. + +If problems persist, please open an issue on the GitHub repository. \ No newline at end of file diff --git a/README.md b/README.md index c525d69b8..5fe3c6018 100644 --- a/README.md +++ b/README.md @@ -62,97 +62,10 @@ This library consists of: - Custom filters. Check out [API docs](apps/nunjucks-filters/docs/api.md) for complete list - Lodash-powered filters. For the list of all available filters check [official docs](https://lodash.com/docs/) -## Release Process - -To release a major/minor/patch: - -### Conventional Commits: - -To maintain a clear git history of commits and easily identify what each commit changed and whether it triggered a release, we use conventional commits. The feat and fix prefixes are particularly important as they are needed to trigger changesets. Using these prefixes ensures that the changes are correctly categorized and the versioning system functions as expected. - -For Example: -``` -feat: add new feature -``` - -#### Manual - -1. Create a new release markdown file in the `.changeset` directory. The filename should indicate what the change is about. - -2. Add the following content to the file in this particular format: - - ```markdown - --- - "@package-name-1": [type] (major/minor/patch) - "@package-name-2": [type] - --- - - [Provide a brief description of the changes. For example: Added a new Release GitHub Flow to the Turborepo. No new features or bugfixes were introduced.] - ``` - - For Example: - - ```markdown - --- - "@asyncapi/generator": minor - --- - - Adding new Release Github Flow to the Turborepo. No new features or bugfixes were introduced. - - ``` - -3. Include the file in your pull request. - -#### Using CLI - -1. Create a new release markdown file using changeset CLI. Below command will trigger an interactive prompt that you can use to specify release type and affected packages. - ```cli - npx -p @changesets/cli@2.27.7 changeset - ``` - -2. Include the file in your pull request. - -> [!TIP] -> For more detailed instructions, you can refer to the official documentation for creating a changeset: -[Adding a changeset](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md) - - - -### Release Flow: - -1. **Add a Changeset**: - - When you make changes that need to be released, create a markdown file in the `.changeset` directory stating the package name and level of change (major/minor/patch). - -2. **Open a Pull Request**: - - Push your changes and open a Pull Request (PR). After the PR is merged the changeset file helps communicate the type of changes (major, minor, patch). - -3. **CI Processes Changeset**: - - After PR is merged, a dedicated GitHub Actions release workflow runs using changeset action, - - - This action reads the markdown files in the `.changeset` folder and creates a PR with the updated version of the package and removes the markdown file. For example: - - Before: - ```json - "name": "@asyncapi/generator", - "version": "2.0.1", - ``` - - After: - ```json - "name": "@asyncapi/generator", - "version": "3.0.1", - ``` - - - The new PR will also contain the description from the markdown files, - - - AsyncAPI bot automatically merge such release PR. - -4. **Release the Package**: - - - After the PR is merged, the CI/CD pipeline triggers again. The `changesets/action` step identifies that the PR was created by itself. It then verifies if the current version of the package is greater than the previously released version. If a difference is detected, it executes the publish command to release the updated package. - ## Contributing +For developement setup you can follow the detailed guide in [Developement guide](Development.md) + Read [CONTRIBUTING](CONTRIBUTING.md) guide. ## Contributors ✨ diff --git a/apps/generator/test/test-templates/react-template/package.json b/apps/generator/test/test-templates/react-template/package.json index 5f430552e..ee383f64b 100644 --- a/apps/generator/test/test-templates/react-template/package.json +++ b/apps/generator/test/test-templates/react-template/package.json @@ -7,7 +7,7 @@ }, "generator": { "renderer": "react", - "api": "v3", + "apiVersion": "v3", "parameters": { "version": { "description": "Custom version to be used" From 52c67960cd938aaac51fb03e43f56001cf616fdd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:38:33 +0200 Subject: [PATCH 07/15] chore(deps): bump rollup from 2.79.1 to 2.79.2 in /apps/generator/test/test-templates/react-template (#1273) --- .../test/test-templates/react-template/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/generator/test/test-templates/react-template/package-lock.json b/apps/generator/test/test-templates/react-template/package-lock.json index 9d895fc52..4b283e1c6 100644 --- a/apps/generator/test/test-templates/react-template/package-lock.json +++ b/apps/generator/test/test-templates/react-template/package-lock.json @@ -3693,9 +3693,9 @@ } }, "node_modules/rollup": { - "version": "2.79.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", - "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", + "version": "2.79.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.2.tgz", + "integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==", "bin": { "rollup": "dist/bin/rollup" }, From 5c28787ff61c786c3681e19f343a9663d77525cf Mon Sep 17 00:00:00 2001 From: rishabhr4 <118053976+rishabhr4@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:10:11 +0530 Subject: [PATCH 08/15] refactor: switch to optional chaining in custom filters and update eslint config (#1274) --- .eslintrc | 2 +- apps/nunjucks-filters/src/customFilters.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 38ad4e746..727aafeae 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,7 @@ extends: - plugin:sonarjs/recommended parserOptions: - ecmaVersion: 2018 + ecmaVersion: 2020 sourceType: module ecmaFeatures: jsx: true diff --git a/apps/nunjucks-filters/src/customFilters.js b/apps/nunjucks-filters/src/customFilters.js index 670554fa3..7d5339f17 100644 --- a/apps/nunjucks-filters/src/customFilters.js +++ b/apps/nunjucks-filters/src/customFilters.js @@ -198,7 +198,7 @@ function replaceServerVariablesWithValues(url, serverVariables) { const getVariableValue = (object, variable) => { const keyValue = object[variable]._json; - if (keyValue) return keyValue.default || (keyValue.enum && keyValue.enum[0]); + if (keyValue) return keyValue.default ?? keyValue.enum?.[0]; }; const urlVariables = getVariablesNamesFromUrl(url); From a3460a5c40007e3f9460856df9cd073615a8fe92 Mon Sep 17 00:00:00 2001 From: rishabhr4 <118053976+rishabhr4@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:22:31 +0530 Subject: [PATCH 09/15] refactor: optional chaining instead of expression in `parser.js` (#1277) Co-authored-by: Lukasz Gornicki --- apps/generator/lib/parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/generator/lib/parser.js b/apps/generator/lib/parser.js index ac1d327a8..54b2c54fa 100644 --- a/apps/generator/lib/parser.js +++ b/apps/generator/lib/parser.js @@ -63,7 +63,7 @@ function convertOldOptionsToNew(oldOptions, generator) { } const resolvers = []; - if (generator && generator.mapBaseUrlToFolder && generator.mapBaseUrlToFolder.url) { + if (generator?.mapBaseUrlToFolder?.url) { resolvers.push(...getMapBaseUrlToFolderResolvers(generator.mapBaseUrlToFolder)); } if (oldOptions.resolve) { From 2feefdc1e535690bb44419f2823b204fc8329269 Mon Sep 17 00:00:00 2001 From: rishabhr4 <118053976+rishabhr4@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:34:28 +0530 Subject: [PATCH 10/15] refactor: use an object spread instead of `Object.assign` in filters (#1276) Co-authored-by: Lukasz Gornicki --- apps/nunjucks-filters/src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/nunjucks-filters/src/index.js b/apps/nunjucks-filters/src/index.js index c986644ae..4b0ea87f9 100644 --- a/apps/nunjucks-filters/src/index.js +++ b/apps/nunjucks-filters/src/index.js @@ -1,4 +1,6 @@ const customFilters = require('./customFilters'); const lodashFilters = require('./lodashFilters'); -module.exports = Object.assign({}, lodashFilters, customFilters); \ No newline at end of file +module.exports = { + ...lodashFilters, + ...customFilters}; \ No newline at end of file From 687202089ec7c70f8fc8cabe8c664a5862875d7c Mon Sep 17 00:00:00 2001 From: asyncapi-bot Date: Wed, 9 Oct 2024 12:57:42 +0200 Subject: [PATCH 11/15] ci: update .prettierignore from global .github repo (#1293) --- .prettierignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..fa29cdfff --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +** \ No newline at end of file From 85408328fe0b12f6a8dc92d99bbe3e8fdf26be44 Mon Sep 17 00:00:00 2001 From: rishabhr4 <118053976+rishabhr4@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:57:03 +0530 Subject: [PATCH 12/15] refactor: switch to optional chaining in custom filters and removing unnecessary escape character in logMessages.js (#1285) Co-authored-by: Lukasz Gornicki --- apps/generator/lib/logMessages.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/generator/lib/logMessages.js b/apps/generator/lib/logMessages.js index 0ea167d6b..a02f3f1f1 100644 --- a/apps/generator/lib/logMessages.js +++ b/apps/generator/lib/logMessages.js @@ -2,7 +2,7 @@ const TEMPLATE_INSTALL_FLAG_MSG = 'because you passed --install flag'; const TEMPLATE_INSTALL_DISK_MSG = 'because the template cannot be found on disk'; -const NODE_MODULES_INSTALL ='Remember that your local template must have its own node_modules installed first, \"npm install\" is not triggered by the generator.'; +const NODE_MODULES_INSTALL = 'Remember that your local template must have its own node_modules installed first, "npm install" is not triggered by the generator.'; const NPM_INSTALL_TRIGGER = 'Installation of template located on disk technically means symlink creation betweed node_modules of the generator and template sources. Your local template must have its own node_modules, "npm install" is not triggered.'; @@ -19,7 +19,7 @@ function templateNotFound(templateName) { } function packageNotAvailable(packageDetails) { - if (packageDetails && packageDetails.pkgPath) { + if (packageDetails?.pkgPath) { return `Unable to resolve template location at ${packageDetails.pkgPath}. Package is not available locally.`; } From 950f4c8b3fc5589ac760637f2af6ac1b843a3373 Mon Sep 17 00:00:00 2001 From: rishabhr4 <118053976+rishabhr4@users.noreply.github.com> Date: Thu, 10 Oct 2024 00:09:28 +0530 Subject: [PATCH 13/15] refactor: used optional chaining instead of expression in generator.js (#1290) Co-authored-by: Lukasz Gornicki --- apps/generator/lib/generator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/generator/lib/generator.js b/apps/generator/lib/generator.js index 8a07a5670..b7286ce2b 100644 --- a/apps/generator/lib/generator.js +++ b/apps/generator/lib/generator.js @@ -562,8 +562,8 @@ class Generator { try { installedPkg = getTemplateDetails(this.templateName, PACKAGE_JSON_FILENAME); - pkgPath = installedPkg && installedPkg.pkgPath; - packageVersion = installedPkg && installedPkg.version; + pkgPath = installedPkg?.pkgPath; + packageVersion = installedPkg?.version; log.debug(logMessage.templateSource(pkgPath)); if (packageVersion) log.debug(logMessage.templateVersion(packageVersion)); From 074e520d080fd7b6dd5ffc149557cde02cda3506 Mon Sep 17 00:00:00 2001 From: Manikanta Mandala <77623256+ManikantaMandala@users.noreply.github.com> Date: Thu, 10 Oct 2024 00:21:33 +0530 Subject: [PATCH 14/15] refactor: improve custom filters readability with optional chaining (#1275) Co-authored-by: Lukasz Gornicki --- apps/nunjucks-filters/src/customFilters.js | 56 +++++++++++----------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/apps/nunjucks-filters/src/customFilters.js b/apps/nunjucks-filters/src/customFilters.js index 7d5339f17..83ef06fbb 100644 --- a/apps/nunjucks-filters/src/customFilters.js +++ b/apps/nunjucks-filters/src/customFilters.js @@ -58,7 +58,7 @@ function getPayloadExamples(msg) { } const payload = msg.payload(); - if (payload && payload.examples()) { + if (payload?.examples()) { return payload.examples().map(example => ({ example })); } } @@ -90,7 +90,7 @@ function getHeadersExamples(msg) { } const headers = msg.headers(); - if (headers && headers.examples()) { + if (headers?.examples()) { return headers.examples().map(example => ({ example })); } } @@ -120,7 +120,7 @@ filter.oneLine = oneLine; /** * Generate JSDoc from message properties of the header and the payload - * + * * @example * docline( * Schema { @@ -134,9 +134,9 @@ filter.oneLine = oneLine; * my-app-header, * options.message.headers * ) - * + * * Returned value will be -> * @param {integer} options.message.headers.my-app-header - * + * * @field {object} - Property object * @fieldName {string} - Name of documented property * @scopePropName {string} - Name of param for JSDocs @@ -144,34 +144,34 @@ filter.oneLine = oneLine; */ function docline(field, fieldName, scopePropName) { /* eslint-disable sonarjs/cognitive-complexity */ - const buildLine = (f, fName, pName) => { - const type = f.type() ? f.type() : 'string'; - const description = f.description() ? ` - ${f.description().replace(/\r?\n|\r/g, '')}` : ''; - let def = f.default(); + const getType = (f) => f.type() || 'string'; + const getDescription = (f) => f.description() ? ` - ${f.description().replace(/\r?\n|\r/g, '')}` : ''; + const getDefault = (f, type) => (f.default() && type === 'string') ? `'${f.default()}'` : f.default(); + const getPName = (pName) => pName ? `${pName}.` : ''; - if (def && type === 'string') def = `'${def}'`; + const buildLineCore = (type, def, pName, fName) => { + return `* @param {${type}} ${pName}${fName}${def !== undefined ? `=${def}` : ''}`; + }; - let line; - if (def !== undefined) { - line = ` * @param {${type}} [${pName ? `${pName}.` : ''}${fName}=${def}]`; - } else { - line = ` * @param {${type}} ${pName ? `${pName}.` : ''}${fName}`; - } + const buildLine = (f, fName, pName) => { + const type = getType(f); + const def = getDefault(f, type); + const line = buildLineCore(type, def, getPName(pName), fName); + return line + (type === 'object' ? '' : getDescription(f)); + }; - if (type === 'object') { - let lines = `${line}\n`; - let first = true; - for (const propName in f.properties()) { - lines = `${lines}${first ? '' : '\n'}${buildLine(f.properties()[propName], propName, `${pName ? `${pName}.` : ''}${fName}`)}`; - first = false; - } - return lines; - } + const buildObjectLines = (f, fName, pName) => { + const properties = f.properties(); + const mainLine = buildLine(f, fName, pName); - return `${line}${description}`; + return `${mainLine }\n${ Object.keys(properties).map((propName) => + buildLine(properties[propName], propName, `${getPName(pName)}${fName}`) + ).join('\n')}`; }; - return buildLine(field, fieldName, scopePropName); + return getType(field) === 'object' + ? buildObjectLines(field, fieldName, scopePropName) + : buildLine(field, fieldName, scopePropName); } filter.docline = docline; @@ -179,7 +179,7 @@ filter.docline = docline; * Helper function to replace server variables in the url with actual values * @url {string} - url string * @serverserverVariables {Object} - Variables model map - * @returns {string} + * @returns {string} */ function replaceServerVariablesWithValues(url, serverVariables) { const getVariablesNamesFromUrl = (inputUrl) => { From 6f60d50f3e4544d7356e8b1c8dc40380dfb87ece Mon Sep 17 00:00:00 2001 From: rishabhr4 <118053976+rishabhr4@users.noreply.github.com> Date: Thu, 10 Oct 2024 00:37:28 +0530 Subject: [PATCH 15/15] refactor: used object.hasown instead of object.hasownproperty in generator.js (#1291) Co-authored-by: Lukasz Gornicki --- apps/generator/lib/generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/generator/lib/generator.js b/apps/generator/lib/generator.js index b7286ce2b..cb4ffe950 100644 --- a/apps/generator/lib/generator.js +++ b/apps/generator/lib/generator.js @@ -759,7 +759,7 @@ class Generator { // Check if the filename dictates it should be separated let wasSeparated = false; for (const prop in fileNamesForSeparation) { - if (Object.prototype.hasOwnProperty.call(fileNamesForSeparation, prop) && stats.name.includes(`$$${prop}$$`)) { + if (Object.hasOwn(fileNamesForSeparation, prop) && stats.name.includes(`$$${prop}$$`)) { await this.generateSeparateFiles(asyncapiDocument, fileNamesForSeparation[prop], prop, stats.name, root); const templateFilePath = path.relative(this.templateContentDir, path.resolve(root, stats.name)); fs.unlink(path.resolve(this.targetDir, templateFilePath), next);