@asyncapi/generator 2.0.3 → 2.1.0

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 +9 -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
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ const { readFile } = require('fs').promises;
6
+ const path = require('path');
7
+ const Generator = require('@asyncapi/generator');
8
+ const dummySpecPath = path.resolve(__dirname, '../docs/dummy.yml');
9
+ const tempOutputResults = path.resolve(__dirname, 'output');
10
+
11
+ console.log = jest.fn();
12
+
13
+ describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from argument', () => {
14
+ jest.setTimeout(1000000);
15
+
16
+ it('generated using private registory', async () => {
17
+ const generator = new Generator('react-template', tempOutputResults,
18
+ {
19
+ debug: true,
20
+ install: true,
21
+ forceWrite: true,
22
+ templateParams: { version: 'v1', mode: 'production' },
23
+ registry: {
24
+ url: 'http://verdaccio:4873',
25
+ auth: 'YWRtaW46bmltZGE=' // base64 encoded username and password represented as admin:nimda
26
+
27
+ }
28
+ });
29
+
30
+ await generator.generateFromFile(dummySpecPath);
31
+
32
+ const file = await readFile(path.join(tempOutputResults, 'test-file.md'), 'utf8');
33
+ expect(file).toContain('new content');
34
+ expect(console.log).toHaveBeenCalledWith('Using npm registry http://verdaccio:4873 and authorization type //verdaccio:4873:_auth to handle template installation.');
35
+ });
36
+ });
37
+
38
+ describe('Integration testing generateFromFile() to make sure the template can be download from the private repository from npm config', () => {
39
+ jest.setTimeout(1000000);
40
+
41
+ it('generated using private registory from npm config', async () => {
42
+ const generator = new Generator('react-template', tempOutputResults,
43
+ {
44
+ debug: true,
45
+ install: true,
46
+ forceWrite: true,
47
+ templateParams: { version: 'v1', mode: 'production' }
48
+ });
49
+
50
+ await generator.generateFromFile(dummySpecPath);
51
+
52
+ const file = await readFile(path.join(tempOutputResults, 'test-file.md'), 'utf8');
53
+ expect(file).toContain('new content');
54
+ });
55
+ });
@@ -0,0 +1,99 @@
1
+ #!/bin/bash
2
+
3
+ # Function to install and test a specific project
4
+ function test_project {
5
+ echo "##########
6
+ Starting standard project test
7
+ ##########"
8
+ # Copy to isolated env
9
+ cp -r /app /testprojectA
10
+ cd /testprojectA/apps/generator/test/test-project
11
+ npm install react-template@0.0.1 # installing old version of template
12
+ npm run test:project:A
13
+ # Copy to isolated env
14
+ cp -r /app /testprojectB
15
+ cd /testprojectB/apps/generator/test/test-project
16
+ npm run test:project:B
17
+ # Copy to isolated env
18
+ cp -r /app /testprojectC
19
+ cd /testprojectC/apps/generator/test/test-project
20
+ npm run test:project:C
21
+ echo "##########
22
+ Starting test of global template installation
23
+ ##########"
24
+ cp -r /app /testprojectglobal
25
+ cd /testprojectglobal/apps/generator/test/test-project
26
+ # Installing test template globally before global tests
27
+ npm install -g react-template@0.0.1
28
+ npm run test:global
29
+ }
30
+
31
+ # Function to test the registry
32
+ function test_registry {
33
+ echo "##########
34
+ Starting registry test
35
+ ##########"
36
+ echo "0.0.0.0 registry.npmjs.org" > /etc/hosts # no access to registry.npmjs.org directly
37
+ cp -r /app /testprojectregistry
38
+ cd /testprojectregistry/apps/generator/test/test-project
39
+
40
+ npm config delete registry #making sure we do not have verdaccio details in config and test really use library arguments
41
+ npm run test:registry:arg
42
+
43
+ #Now running test for npm config support
44
+ npm config set registry http://verdaccio:4873
45
+ #base64 encoded username and password represented as admin:nimda
46
+ npm config set -- //verdaccio:4873/:_auth=YWRtaW46bmltZGE=
47
+ npm run test:registry:npm-config
48
+ }
49
+
50
+ # Required by GitHub Actions
51
+ sudo chown -R 1001:121 "/root/.npm"
52
+
53
+ # Always run these steps
54
+ cd app
55
+
56
+ echo "##########
57
+ Running installation in root
58
+ ##########"
59
+ npm install
60
+ cd apps/generator/test/test-project
61
+
62
+ echo "##########
63
+ Running installation in test-project
64
+ ##########"
65
+ npm install
66
+ npm install --install-links ../.. #installing generator without symlink
67
+
68
+ echo "##########
69
+ Publish test template to local npm-verdaccio
70
+ ##########"
71
+ npm config set -- //verdaccio:4873/:_auth=YWRtaW46bmltZGE=
72
+ npm config set registry http://verdaccio:4873
73
+
74
+ echo "##########
75
+ Publishing the correct template as 0.0.1
76
+ ##########"
77
+ npm publish ../test-templates/react-template
78
+
79
+ echo "##########
80
+ Publishing new version as 0.0.2
81
+ ##########"
82
+ cp -r ../test-templates/react-template ../test-templates/react-template-v2 #we need copy so later in project tests we still have access to old v1 template
83
+ new_version="0.0.2"
84
+ sed -i 's/"version": "[^"]*"/"version": "'"$new_version"'"/' ../test-templates/react-template-v2/package.json
85
+ new_content="import { File, Text } from '@asyncapi/generator-react-sdk'; export default function({ asyncapi, params }) { return ( <File name='test-file.md'> <Text>new content</Text> </File> ); }"
86
+ echo "$new_content" > ../test-templates/react-template-v2/template/test-file.md.js
87
+ npm publish ../test-templates/react-template-v2
88
+
89
+ # Run the functions based on the provided arguments
90
+ case "$1" in
91
+ "test-project")
92
+ test_project
93
+ test_registry
94
+ ;;
95
+ *)
96
+ echo "Invalid argument. Supported arguments: test-project"
97
+ exit 1
98
+ ;;
99
+ esac
@@ -0,0 +1,16 @@
1
+ storage: ../storage
2
+ auth:
3
+ htpasswd:
4
+ file: ./htpasswd
5
+ algorithm: bcrypt
6
+ uplinks:
7
+ npmjs:
8
+ url: https://registry.npmjs.org/
9
+ packages:
10
+ "react-template":
11
+ access: admin
12
+ publish: admin
13
+ "!react-template":
14
+ access: admin
15
+ proxy: npmjs
16
+ log: { type: stdout, format: pretty, level: error }
@@ -0,0 +1 @@
1
+ admin:$2a$10$mHopVorSKSZPGTrmGfmMfOnLZKU5M/aXapfjafRqK24eMgREtALRq:autocreated 2024-01-04T16:17:07.359Z