@asyncapi/generator 2.0.3 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.dockerignore +2 -0
  2. package/CHANGELOG.md +15 -0
  3. package/docs/configuration-file.md +2 -2
  4. package/docs/nunjucks-render-engine.md +2 -1
  5. package/jest.config.js +9 -0
  6. package/lib/__mocks__/filtersRegistry.js +3 -0
  7. package/lib/__mocks__/hooksRegistry.js +3 -0
  8. package/lib/__mocks__/templateConfigValidator.js +3 -0
  9. package/lib/__mocks__/utils.js +25 -0
  10. package/lib/filtersRegistry.js +14 -10
  11. package/package.json +9 -9
  12. package/test/__mocks__/@npmcli/arborist.js +11 -0
  13. package/test/__mocks__/@npmcli/config.js +3 -0
  14. package/test/__mocks__/fs.extra.js +3 -0
  15. package/test/__mocks__/loglevel.js +3 -0
  16. package/test/__mocks__/resolve-from.js +8 -0
  17. package/test/__mocks__/resolve-pkg.js +8 -0
  18. package/test/__snapshots__/integration.test.js.snap +25 -0
  19. package/test/docs/apiwithref.json +41 -0
  20. package/test/docs/dummy.yml +390 -0
  21. package/test/docs/dummyV3.yml +31 -0
  22. package/test/docs/shared.json +27 -0
  23. package/test/docs/ws.yml +36 -0
  24. package/test/generator.test.js +626 -0
  25. package/test/integration.test.js +58 -0
  26. package/test/parser.test.js +107 -0
  27. package/test/renderer.test.js +62 -0
  28. package/test/templateConfigValidator.test.js +277 -0
  29. package/test/test-project/.yarncr.yml +3 -0
  30. package/test/test-project/README.md +4 -0
  31. package/test/test-project/docker-compose.yml +24 -0
  32. package/test/test-project/package.json +25 -0
  33. package/test/test-project/test-entrypoint.sh +12 -0
  34. package/test/test-project/test-global.test.js +37 -0
  35. package/test/test-project/test-project.test.js +98 -0
  36. package/test/test-project/test-registry.test.js +55 -0
  37. package/test/test-project/test.sh +99 -0
  38. package/test/test-project/verdaccio/config.yaml +16 -0
  39. package/test/test-project/verdaccio/htpasswd +1 -0
  40. package/test/test-templates/nunjucks-template/package-lock.json +4143 -0
  41. package/test/test-templates/nunjucks-template/package.json +21 -0
  42. package/test/test-templates/nunjucks-template/template/test-file.md +5 -0
  43. package/test/test-templates/react-template/__transpiled/test-file.md.js +24 -0
  44. package/test/test-templates/react-template/__transpiled/test-file.md.js.map +1 -0
  45. package/test/test-templates/react-template/package-lock.json +4143 -0
  46. package/test/test-templates/react-template/package.json +23 -0
  47. package/test/test-templates/react-template/template/test-file.md.js +11 -0
  48. package/test/utils.test.js +76 -0
  49. package/.eslintignore +0 -5
  50. package/.eslintrc +0 -113
  51. package/.npmrc.template +0 -1
  52. package/.releaserc +0 -24
  53. package/.sonarcloud.properties +0 -2
  54. package/CODEOWNERS +0 -12
  55. package/CODE_OF_CONDUCT.md +0 -46
  56. package/CONTRIBUTING.md +0 -79
  57. package/LICENSE +0 -201
  58. package/README.md +0 -98
  59. package/assets/readme-banner.png +0 -0
package/.dockerignore ADDED
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ npm-debug.log
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @asyncapi/generator
2
+
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 36ee8a8: Fix docker image publishing. Removed package name from version tag for Docker tagging.
8
+
9
+ ## 2.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 99a14a8: - New release pipeline supporting monorepo,
14
+ - Package `@asyncapi/generator-filters` is now part of `generator` repo and won't be released separately. New name of the library is `nunjuckis-filters`,
15
+ - By default `@asyncapi/generator-filters` package, known as package with a lot of different nunjucks filters, is registered and added to generator and you no longer have to configure it in your `package.json`. Package `@asyncapi/generator-filters` will no longer be published to NPM separately and is deprecated.
@@ -60,8 +60,8 @@ The `generator` property from `package.json` file must contain a JSON object tha
60
60
  "lib/lib/config.js"
61
61
  ],
62
62
  "generator": "<2.0.0",
63
- "filters": [
64
- "@asyncapi/generator-filters"
63
+ "filters":[
64
+ "my-package-with-filters"
65
65
  ],
66
66
  "hooks": {
67
67
  "@asyncapi/generator-hooks": "hookFunctionName"
@@ -73,6 +73,7 @@ async function asyncCamelCase(str, callback) {
73
73
  }
74
74
  ```
75
75
 
76
- In case you have more than one template and want to reuse filters, you can put them in a single library. You can configure such a library in the template configuration under `filters` property. You can also use the official AsyncAPI [filters library](https://github.com/asyncapi/generator-filters). To learn how to add such filters to configuration [read more about the configuration file](#configuration-file).
76
+ In case you have more than one template and want to reuse filters, you can put them in a single library. You can configure such a library in the template configuration under `filters` property. To learn how to add such filters to configuration [read more about the configuration file](#configuration-file).
77
77
 
78
78
 
79
+ You can also use the official AsyncAPI [nunjucks-filters](/apps/nunjucks-filters) that are by default included in the generator library.
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ const path = require('path');
2
+ module.exports = {
3
+ clearMocks: true,
4
+ moduleNameMapper: {
5
+ '^nimma/legacy$': '<rootDir>../../node_modules/nimma/dist/legacy/cjs/index.js',
6
+ '^nimma/(.*)': '<rootDir>../../node_modules/nimma/dist/cjs/$1',
7
+ '^nunjucks-filters$': path.resolve(__dirname, '../nunjucks-filters'),
8
+ },
9
+ };
@@ -0,0 +1,3 @@
1
+ const filtersRegistry = jest.genMockFromModule('../filtersRegistry');
2
+
3
+ module.exports = filtersRegistry;
@@ -0,0 +1,3 @@
1
+ const hooksRegistry = jest.genMockFromModule('../hooksRegistry');
2
+
3
+ module.exports = hooksRegistry;
@@ -0,0 +1,3 @@
1
+ const templateConfigValidator = jest.genMockFromModule('../templateConfigValidator');
2
+
3
+ module.exports = templateConfigValidator;
@@ -0,0 +1,25 @@
1
+ const utils = jest.genMockFromModule('../utils');
2
+
3
+ utils.__files = {};
4
+ utils.readFile = jest.fn(async (filePath) => {
5
+ return utils.__files[filePath];
6
+ });
7
+
8
+ utils.__contentOfFetchedFile = '';
9
+ utils.fetchSpec = jest.fn(async (fileUrl) => {
10
+ return utils.__contentOfFetchedFile;
11
+ });
12
+
13
+ utils.__isFileSystemPathValue = false;
14
+ utils.isFileSystemPath = jest.fn(() => utils.__isFileSystemPathValue);
15
+
16
+ utils.__isLocalTemplateValue = false;
17
+ utils.isLocalTemplate = jest.fn(async () => utils.__isLocalTemplateValue);
18
+
19
+ utils.__generatorVersion = '';
20
+ utils.getGeneratorVersion = jest.fn(() => utils.__generatorVersion);
21
+
22
+ utils.__getTemplateDetails = {};
23
+ utils.getTemplateDetails = jest.fn(() => utils.__getTemplateDetails);
24
+
25
+ module.exports = utils;
@@ -2,6 +2,7 @@ const path = require('path');
2
2
  const fs = require('fs');
3
3
  const xfs = require('fs.extra');
4
4
  const { isAsyncFunction } = require('./utils');
5
+ const nunjucksFilters = require('nunjucks-filters');
5
6
 
6
7
  /**
7
8
  * Registers all template filters.
@@ -13,6 +14,9 @@ const { isAsyncFunction } = require('./utils');
13
14
  module.exports.registerFilters = async (nunjucks, templateConfig, templateDir, filtersDir) => {
14
15
  await registerLocalFilters(nunjucks, templateDir, filtersDir);
15
16
  registerConfigFilters(nunjucks, templateDir, templateConfig);
17
+
18
+ // Register Nunjucks filters from the 'nunjucks-filters' module without needing to list them explicitly in package.json
19
+ addFilters(nunjucks, nunjucksFilters);
16
20
  };
17
21
 
18
22
  /**
@@ -40,7 +44,7 @@ function registerLocalFilters(nunjucks, templateDir, filtersDir) {
40
44
  const mod = require(filePath);
41
45
 
42
46
  addFilters(nunjucks, mod);
43
-
47
+
44
48
  next();
45
49
  } catch (e) {
46
50
  reject(e);
@@ -58,14 +62,14 @@ function registerLocalFilters(nunjucks, templateDir, filtersDir) {
58
62
  }
59
63
 
60
64
  /**
61
- * Registers the additionally configured filters.
62
- * @private
63
- * @param {Object} nunjucks Nunjucks environment.
64
- * @param {String} templateDir Directory where template is located.
65
- * @param {Object} templateConfig Template configuration.
66
- */
65
+ * Registers the additionally configured filters.
66
+ * @private
67
+ * @param {Object} nunjucks Nunjucks environment.
68
+ * @param {String} templateDir Directory where template is located.
69
+ * @param {Object} templateConfig Template configuration.
70
+ */
67
71
  async function registerConfigFilters(nunjucks, templateDir, templateConfig) {
68
- const confFilters = templateConfig.filters;
72
+ const confFilters = templateConfig.filters;
69
73
  const DEFAULT_MODULES_DIR = 'node_modules';
70
74
  if (!Array.isArray(confFilters)) return;
71
75
 
@@ -87,7 +91,7 @@ async function registerConfigFilters(nunjucks, templateDir, templateConfig) {
87
91
  filterName = path.resolve(templateDir, '../..', filtersModule);
88
92
  mod = require(filterName);
89
93
  } catch (error) {
90
- //in rare cases, especially in isolated tests, it may happen that installation
94
+ //in rare cases, especially in isolated tests, it may happen that installation
91
95
  //ends but is not yet fully completed, so initial require of the same path do not work
92
96
  //but in next attempt it works
93
97
  //we need to keep this workaround until we find a solution
@@ -117,5 +121,5 @@ function addFilters(nunjucks, filters) {
117
121
  } else {
118
122
  nunjucks.addFilter(key, value);
119
123
  }
120
- });
124
+ });
121
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/generator",
3
- "version": "2.0.3",
3
+ "version": "2.1.1",
4
4
  "description": "The AsyncAPI generator. It can generate documentation, code, anything!",
5
5
  "main": "./lib/generator.js",
6
6
  "bin": {
@@ -21,8 +21,8 @@
21
21
  "test:cleanup": "rimraf \"test/temp\"",
22
22
  "docs": "jsdoc2md --partial docs/jsdoc2md-handlebars/custom-sig-name.hbs docs/jsdoc2md-handlebars/main.hbs docs/jsdoc2md-handlebars/docs.hbs docs/jsdoc2md-handlebars/header.hbs docs/jsdoc2md-handlebars/defaultvalue.hbs docs/jsdoc2md-handlebars/link.hbs docs/jsdoc2md-handlebars/params-table.hbs --files lib/generator.js > docs/api.md",
23
23
  "docker:build": "docker build -t asyncapi/generator:latest .",
24
- "lint": "eslint --max-warnings 0 --config .eslintrc .",
25
- "lint:tpl:validator": "eslint --fix --config .eslintrc .github/templates-list-validator",
24
+ "lint": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore .",
25
+ "lint:tpl:validator": "eslint --fix --config ../../.eslintrc ../../.github/templates-list-validator",
26
26
  "generate:readme:toc": "markdown-toc -i README.md",
27
27
  "generate:assets": "npm run docs && npm run generate:readme:toc",
28
28
  "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION"
@@ -49,10 +49,10 @@
49
49
  "license": "Apache-2.0",
50
50
  "homepage": "https://github.com/asyncapi/generator",
51
51
  "dependencies": {
52
- "@asyncapi/generator-react-sdk": "^1.0.19",
53
- "@asyncapi/parser": "^3.0.16",
54
52
  "@npmcli/arborist": "5.6.3",
55
53
  "@npmcli/config": "^8.0.2",
54
+ "@asyncapi/generator-react-sdk": "^1.0.18",
55
+ "@asyncapi/parser": "^3.0.14",
56
56
  "@smoya/multi-parser": "^5.0.0",
57
57
  "ajv": "^8.12.0",
58
58
  "chokidar": "^3.4.0",
@@ -74,15 +74,15 @@
74
74
  "simple-git": "^3.3.0",
75
75
  "source-map-support": "^0.5.19",
76
76
  "ts-node": "^10.9.1",
77
- "typescript": "^4.9.3"
77
+ "typescript": "^4.9.3",
78
+ "nunjucks-filters": "file:../nunjucks-filters"
78
79
  },
79
80
  "devDependencies": {
80
- "conventional-changelog-conventionalcommits": "^5.0.0",
81
81
  "eslint": "^6.8.0",
82
82
  "eslint-plugin-jest": "^23.8.2",
83
- "eslint-plugin-react": "^7.34.1",
84
83
  "eslint-plugin-sonarjs": "^0.5.0",
85
- "jest": "^25.5.0",
84
+ "eslint-plugin-react": "^7.34.1",
85
+ "jest": "^27.3.1",
86
86
  "jsdoc-to-markdown": "^7.1.1",
87
87
  "markdown-toc": "^1.2.0",
88
88
  "rimraf": "^3.0.2",
@@ -0,0 +1,11 @@
1
+ const arb = jest.genMockFromModule('@npmcli/arborist');
2
+
3
+ arb.prototype[Symbol.for('resolvedAdd')] = [{name: 'test'}];
4
+
5
+ arb.prototype.reify = jest.fn(async (opt) => {
6
+ const childrenMap = new Map();
7
+ childrenMap.set('test', {path: './test'});
8
+ return { children: childrenMap };
9
+ });
10
+
11
+ module.exports = arb;
@@ -0,0 +1,3 @@
1
+ const npmConfig = jest.genMockFromModule('@npmcli/config');
2
+
3
+ module.exports = npmConfig;
@@ -0,0 +1,3 @@
1
+ const xfs = jest.genMockFromModule('fs.extra');
2
+
3
+ module.exports = xfs;
@@ -0,0 +1,3 @@
1
+ const log = jest.genMockFromModule('loglevel');
2
+
3
+ module.exports = log;
@@ -0,0 +1,8 @@
1
+ let resolveFrom = jest.genMockFromModule('resolve-from');
2
+
3
+ resolveFrom.__resolveFromValue = '';
4
+ resolveFrom = jest.fn((path) => {
5
+ return resolveFrom.__resolveFromValue;
6
+ });
7
+
8
+ module.exports = resolveFrom;
@@ -0,0 +1,8 @@
1
+ let resolvePkg = jest.genMockFromModule('resolve-pkg');
2
+
3
+ resolvePkg.__resolvePkgValue = '';
4
+ resolvePkg = jest.fn((path) => {
5
+ return resolvePkg.__resolvePkgValue;
6
+ });
7
+
8
+ module.exports = resolvePkg;
@@ -0,0 +1,25 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot generate json based api with referenced JSON Schema 1`] = `
4
+ "This is a markdown file for my application.
5
+ App name is: **This is Async API with a schema reference**
6
+ Version v1 running on production mode
7
+ "
8
+ `;
9
+
10
+ exports[`Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot generate using React template 1`] = `
11
+ "This is a markdown file for my application.
12
+ App name is: **Dummy example with all spec features included**
13
+ Version v1 running on production mode
14
+ "
15
+ `;
16
+
17
+ exports[`Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot generated using Nunjucks template 1`] = `
18
+ "This is a markdown file for my application.
19
+ App name is: **Dummy example with all spec features included**
20
+ Version v1 running on production mode
21
+
22
+ HTML description: **&lt;p&gt;This is an example of AsyncAPI specification file that is suppose to include all possible features of the AsyncAPI specification. Do not use it on production.&lt;/p&gt;
23
+ &lt;p&gt;It&#39;s goal is to support development of documentation and code generation with the &lt;a href=&quot;https://github.com/asyncapi/generator/&quot;&gt;AsyncAPI Generator&lt;/a&gt; and &lt;a href=&quot;https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate&quot;&gt;Template projects&lt;/a&gt;&lt;/p&gt;
24
+ **"
25
+ `;
@@ -0,0 +1,41 @@
1
+ {
2
+ "asyncapi": "2.0.0",
3
+ "info": {
4
+ "title": "This is Async API with a schema reference",
5
+ "version": "0.0.1"
6
+ },
7
+ "channels": {
8
+ "VirtualTopic.crmservice": {
9
+ "publish": {
10
+ "message": {
11
+ "oneOf": [
12
+ {
13
+ "$ref": "#/components/messages/crm:Customer.Created"
14
+ },
15
+ {
16
+ "$ref": "#/components/messages/crm:Customer.Updated"
17
+ }
18
+ ]
19
+ }
20
+ }
21
+ }
22
+ },
23
+ "components": {
24
+ "messages": {
25
+ "crm:Customer.Created": {
26
+ "summary": "A customer was created",
27
+ "schemaFormat": "application/schema+json;version=draft-07",
28
+ "payload": {
29
+ "$ref": "https://schema.example.com/crm/shared.json"
30
+ }
31
+ },
32
+ "crm:Customer.Updated": {
33
+ "summary": "A customer was created",
34
+ "schemaFormat": "application/schema+json;version=draft-07",
35
+ "payload": {
36
+ "$ref": "https://schema.example.com/crm/shared.json"
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }