@asyncapi/cli 3.1.1 → 3.3.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 (194) hide show
  1. package/README.md +4 -0
  2. package/assets/create-glee-app/templates/default/package-lock.json +1185 -676
  3. package/assets/create-glee-app/templates/tutorial/package-lock.json +1148 -554
  4. package/assets/create-template/templates/default/package-lock.json +55 -132
  5. package/lib/apps/api/app.d.ts +15 -0
  6. package/lib/apps/api/app.js +89 -0
  7. package/lib/apps/api/configs/development.json +16 -0
  8. package/lib/apps/api/configs/production.json +16 -0
  9. package/lib/apps/api/configs/test.json +16 -0
  10. package/lib/apps/api/constants.d.ts +1 -0
  11. package/lib/apps/api/constants.js +4 -0
  12. package/lib/apps/api/controllers/bundle.controller.d.ts +7 -0
  13. package/lib/apps/api/controllers/bundle.controller.js +44 -0
  14. package/lib/apps/api/controllers/convert.controller.d.ts +11 -0
  15. package/lib/apps/api/controllers/convert.controller.js +69 -0
  16. package/lib/apps/api/controllers/diff.controller.d.ts +7 -0
  17. package/lib/apps/api/controllers/diff.controller.js +42 -0
  18. package/lib/apps/api/controllers/docs.controller.d.ts +6 -0
  19. package/lib/apps/api/controllers/docs.controller.js +24 -0
  20. package/lib/apps/api/controllers/generate.controller.d.ts +22 -0
  21. package/lib/apps/api/controllers/generate.controller.js +176 -0
  22. package/lib/apps/api/controllers/help.controller.d.ts +6 -0
  23. package/lib/apps/api/controllers/help.controller.js +101 -0
  24. package/lib/apps/api/controllers/parse.controller.d.ts +10 -0
  25. package/lib/apps/api/controllers/parse.controller.js +35 -0
  26. package/lib/apps/api/controllers/validate.controller.d.ts +10 -0
  27. package/lib/apps/api/controllers/validate.controller.js +50 -0
  28. package/lib/apps/api/exceptions/problem.exception.d.ts +14 -0
  29. package/lib/apps/api/exceptions/problem.exception.js +10 -0
  30. package/lib/apps/api/index.d.ts +9 -0
  31. package/lib/apps/api/index.js +21 -0
  32. package/lib/apps/api/middlewares/problem.middleware.d.ts +6 -0
  33. package/lib/apps/api/middlewares/problem.middleware.js +27 -0
  34. package/lib/apps/api/middlewares/validation.middleware.d.ts +12 -0
  35. package/lib/apps/api/middlewares/validation.middleware.js +236 -0
  36. package/lib/apps/api/server.d.ts +3 -0
  37. package/lib/apps/api/server.js +19 -0
  38. package/lib/{commands → apps/cli/commands}/bundle.d.ts +1 -1
  39. package/lib/{commands → apps/cli/commands}/bundle.js +3 -3
  40. package/lib/{commands → apps/cli/commands}/config/analytics.d.ts +1 -1
  41. package/lib/{commands → apps/cli/commands}/config/analytics.js +4 -3
  42. package/lib/{commands → apps/cli/commands}/config/context/add.d.ts +1 -1
  43. package/lib/{commands → apps/cli/commands}/config/context/add.js +12 -6
  44. package/lib/{commands → apps/cli/commands}/config/context/current.d.ts +1 -1
  45. package/lib/{commands → apps/cli/commands}/config/context/current.js +4 -4
  46. package/lib/{commands → apps/cli/commands}/config/context/edit.d.ts +1 -1
  47. package/lib/{commands → apps/cli/commands}/config/context/edit.js +12 -6
  48. package/lib/{commands → apps/cli/commands}/config/context/index.d.ts +1 -1
  49. package/lib/{commands → apps/cli/commands}/config/context/index.js +1 -1
  50. package/lib/{commands → apps/cli/commands}/config/context/init.d.ts +1 -1
  51. package/lib/{commands → apps/cli/commands}/config/context/init.js +7 -4
  52. package/lib/{commands → apps/cli/commands}/config/context/list.d.ts +1 -1
  53. package/lib/{commands → apps/cli/commands}/config/context/list.js +4 -4
  54. package/lib/{commands → apps/cli/commands}/config/context/remove.d.ts +1 -1
  55. package/lib/{commands → apps/cli/commands}/config/context/remove.js +8 -5
  56. package/lib/{commands → apps/cli/commands}/config/context/use.d.ts +1 -1
  57. package/lib/{commands → apps/cli/commands}/config/context/use.js +8 -5
  58. package/lib/{commands → apps/cli/commands}/config/index.d.ts +1 -1
  59. package/lib/{commands → apps/cli/commands}/config/index.js +1 -1
  60. package/lib/{commands → apps/cli/commands}/config/versions.d.ts +1 -1
  61. package/lib/{commands → apps/cli/commands}/config/versions.js +2 -2
  62. package/lib/{commands → apps/cli/commands}/convert.d.ts +2 -7
  63. package/lib/apps/cli/commands/convert.js +85 -0
  64. package/lib/{commands → apps/cli/commands}/diff.d.ts +11 -2
  65. package/lib/{commands → apps/cli/commands}/diff.js +85 -31
  66. package/lib/{commands → apps/cli/commands}/format.d.ts +1 -1
  67. package/lib/{commands → apps/cli/commands}/format.js +4 -4
  68. package/lib/{commands → apps/cli/commands}/generate/fromTemplate.d.ts +4 -5
  69. package/lib/{commands → apps/cli/commands}/generate/fromTemplate.js +89 -122
  70. package/lib/{commands → apps/cli/commands}/generate/index.d.ts +1 -1
  71. package/lib/{commands → apps/cli/commands}/generate/index.js +1 -1
  72. package/lib/{commands → apps/cli/commands}/generate/models.d.ts +6 -1
  73. package/lib/{commands → apps/cli/commands}/generate/models.js +48 -9
  74. package/lib/{commands → apps/cli/commands}/new/file.d.ts +1 -1
  75. package/lib/{commands → apps/cli/commands}/new/file.js +11 -8
  76. package/lib/{commands → apps/cli/commands}/new/glee.d.ts +2 -2
  77. package/lib/{commands → apps/cli/commands}/new/glee.js +4 -4
  78. package/lib/{commands → apps/cli/commands}/new/index.d.ts +1 -1
  79. package/lib/{commands → apps/cli/commands}/new/index.js +1 -1
  80. package/lib/{commands → apps/cli/commands}/new/template.d.ts +1 -1
  81. package/lib/{commands → apps/cli/commands}/new/template.js +10 -8
  82. package/lib/{commands → apps/cli/commands}/optimize.d.ts +1 -1
  83. package/lib/{commands → apps/cli/commands}/optimize.js +71 -30
  84. package/lib/{commands → apps/cli/commands}/pretty.d.ts +1 -1
  85. package/lib/{commands → apps/cli/commands}/pretty.js +8 -5
  86. package/lib/apps/cli/commands/start/api.d.ts +11 -0
  87. package/lib/apps/cli/commands/start/api.js +23 -0
  88. package/lib/{commands → apps/cli/commands}/start/index.d.ts +1 -1
  89. package/lib/{commands → apps/cli/commands}/start/index.js +1 -1
  90. package/lib/{commands → apps/cli/commands}/start/preview.d.ts +1 -1
  91. package/lib/{commands → apps/cli/commands}/start/preview.js +9 -6
  92. package/lib/{commands → apps/cli/commands}/start/studio.d.ts +1 -1
  93. package/lib/{commands → apps/cli/commands}/start/studio.js +10 -7
  94. package/lib/{commands → apps/cli/commands}/validate.d.ts +6 -2
  95. package/lib/apps/cli/commands/validate.js +94 -0
  96. package/lib/{core → apps/cli/internal}/base.d.ts +1 -1
  97. package/lib/{core → apps/cli/internal}/base.js +12 -4
  98. package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
  99. package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
  100. package/lib/{core → apps/cli/internal}/flags/config/context.flags.js +1 -1
  101. package/lib/{core → apps/cli/internal}/flags/convert.flags.js +9 -2
  102. package/lib/{core → apps/cli/internal}/flags/diff.flags.d.ts +1 -1
  103. package/lib/{core → apps/cli/internal}/flags/diff.flags.js +3 -3
  104. package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.js +12 -12
  105. package/lib/{core → apps/cli/internal}/flags/generate/models.flags.js +2 -2
  106. package/lib/{core → apps/cli/internal}/flags/global.flags.js +1 -1
  107. package/lib/{core → apps/cli/internal}/flags/new/file.flags.js +7 -2
  108. package/lib/{core → apps/cli/internal}/flags/optimize.flags.js +24 -4
  109. package/lib/apps/cli/internal/flags/parser.flags.d.ts +10 -0
  110. package/lib/apps/cli/internal/flags/parser.flags.js +28 -0
  111. package/lib/{core → apps/cli/internal}/flags/proxy.flags.js +3 -3
  112. package/lib/apps/cli/internal/flags/start/api.flags.d.ts +5 -0
  113. package/lib/apps/cli/internal/flags/start/api.flags.js +20 -0
  114. package/lib/apps/cli/internal/flags/start/preview.flags.js +31 -0
  115. package/lib/{core → apps/cli/internal}/flags/start/studio.flags.js +9 -2
  116. package/lib/{core → apps/cli/internal}/flags/validate.flags.d.ts +3 -1
  117. package/lib/{core → apps/cli/internal}/flags/validate.flags.js +11 -3
  118. package/lib/{core → apps/cli/internal}/globals.d.ts +1 -1
  119. package/lib/{core → apps/cli/internal}/globals.js +2 -4
  120. package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.js +14 -4
  121. package/lib/{core → domains}/models/Context.js +1 -1
  122. package/lib/{core → domains}/models/Preview.js +35 -19
  123. package/lib/{core → domains}/models/SpecificationFile.d.ts +2 -2
  124. package/lib/{core → domains}/models/SpecificationFile.js +8 -5
  125. package/lib/{core → domains}/models/Studio.js +4 -4
  126. package/lib/domains/services/archiver.service.d.ts +17 -0
  127. package/lib/domains/services/archiver.service.js +53 -0
  128. package/lib/domains/services/base.service.d.ts +6 -0
  129. package/lib/domains/services/base.service.js +26 -0
  130. package/lib/domains/services/convert.service.d.ts +12 -0
  131. package/lib/domains/services/convert.service.js +65 -0
  132. package/lib/domains/services/generator.service.d.ts +15 -0
  133. package/lib/domains/services/generator.service.js +95 -0
  134. package/lib/domains/services/validation.service.d.ts +54 -0
  135. package/lib/domains/services/validation.service.js +288 -0
  136. package/lib/{core/errors → errors}/specification-file.js +1 -1
  137. package/lib/{core/errors → errors}/validation-error.js +6 -5
  138. package/lib/interfaces/index.d.ts +87 -0
  139. package/lib/interfaces/index.js +7 -0
  140. package/lib/utils/ajv.d.ts +2 -0
  141. package/lib/utils/ajv.js +18 -0
  142. package/lib/utils/app-openapi.d.ts +4 -0
  143. package/lib/utils/app-openapi.js +28 -0
  144. package/lib/{core/utils/generator.js → utils/fileWatcher.js} +8 -2
  145. package/lib/utils/logger.d.ts +6 -0
  146. package/lib/utils/logger.js +33 -0
  147. package/lib/utils/retrieve-language.d.ts +1 -0
  148. package/lib/utils/retrieve-language.js +9 -0
  149. package/lib/utils/temp-dir.d.ts +2 -0
  150. package/lib/utils/temp-dir.js +25 -0
  151. package/oclif.manifest.json +124 -1
  152. package/package.json +37 -22
  153. package/lib/commands/convert.js +0 -132
  154. package/lib/commands/validate.js +0 -45
  155. package/lib/core/flags/bundle.flags.js +0 -14
  156. package/lib/core/flags/config/analytics.flags.js +0 -13
  157. package/lib/core/flags/start/preview.flags.js +0 -15
  158. package/lib/core/parser.d.ts +0 -33
  159. package/lib/core/parser.js +0 -176
  160. /package/lib/{core → apps/cli/internal}/flags/bundle.flags.d.ts +0 -0
  161. /package/lib/{core → apps/cli/internal}/flags/config/analytics.flags.d.ts +0 -0
  162. /package/lib/{core → apps/cli/internal}/flags/config/context.flags.d.ts +0 -0
  163. /package/lib/{core → apps/cli/internal}/flags/convert.flags.d.ts +0 -0
  164. /package/lib/{core → apps/cli/internal}/flags/format.flags.d.ts +0 -0
  165. /package/lib/{core → apps/cli/internal}/flags/format.flags.js +0 -0
  166. /package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.d.ts +0 -0
  167. /package/lib/{core → apps/cli/internal}/flags/generate/models.flags.d.ts +0 -0
  168. /package/lib/{core → apps/cli/internal}/flags/global.flags.d.ts +0 -0
  169. /package/lib/{core → apps/cli/internal}/flags/new/file.flags.d.ts +0 -0
  170. /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.d.ts +0 -0
  171. /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.js +0 -0
  172. /package/lib/{core → apps/cli/internal}/flags/new/template.flags.d.ts +0 -0
  173. /package/lib/{core → apps/cli/internal}/flags/new/template.flags.js +0 -0
  174. /package/lib/{core → apps/cli/internal}/flags/optimize.flags.d.ts +0 -0
  175. /package/lib/{core → apps/cli/internal}/flags/pretty.flags.d.ts +0 -0
  176. /package/lib/{core → apps/cli/internal}/flags/pretty.flags.js +0 -0
  177. /package/lib/{core → apps/cli/internal}/flags/proxy.flags.d.ts +0 -0
  178. /package/lib/{core → apps/cli/internal}/flags/start/preview.flags.d.ts +0 -0
  179. /package/lib/{core → apps/cli/internal}/flags/start/studio.flags.d.ts +0 -0
  180. /package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.d.ts +0 -0
  181. /package/lib/{core → domains}/models/Context.d.ts +0 -0
  182. /package/lib/{core → domains}/models/Preview.d.ts +0 -0
  183. /package/lib/{core → domains}/models/Studio.d.ts +0 -0
  184. /package/lib/{core/errors → errors}/context-error.d.ts +0 -0
  185. /package/lib/{core/errors → errors}/context-error.js +0 -0
  186. /package/lib/{core/errors → errors}/diff-error.d.ts +0 -0
  187. /package/lib/{core/errors → errors}/diff-error.js +0 -0
  188. /package/lib/{core/errors → errors}/generator-error.d.ts +0 -0
  189. /package/lib/{core/errors → errors}/generator-error.js +0 -0
  190. /package/lib/{core/errors → errors}/specification-file.d.ts +0 -0
  191. /package/lib/{core/errors → errors}/validation-error.d.ts +0 -0
  192. /package/lib/{core/utils/generator.d.ts → utils/fileWatcher.d.ts} +0 -0
  193. /package/lib/{core/utils → utils}/scoreCalculator.d.ts +0 -0
  194. /package/lib/{core/utils → utils}/scoreCalculator.js +0 -0
@@ -2,46 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const core_1 = require("@oclif/core");
5
- const base_1 = tslib_1.__importDefault(require("../../core/base"));
5
+ const base_1 = tslib_1.__importDefault(require("../../internal/base"));
6
6
  // eslint-disable-next-line
7
7
  // @ts-ignore
8
8
  const generator_1 = tslib_1.__importDefault(require("@asyncapi/generator"));
9
- const generator_v2_1 = tslib_1.__importDefault(require("generator-v2"));
10
9
  const path_1 = tslib_1.__importDefault(require("path"));
11
- const os_1 = tslib_1.__importDefault(require("os"));
12
10
  const fs_1 = tslib_1.__importDefault(require("fs"));
13
- const SpecificationFile_1 = require("../../core/models/SpecificationFile");
14
- const generator_2 = require("../../core/utils/generator");
15
- const validation_error_1 = require("../../core/errors/validation-error");
16
- const generator_error_1 = require("../../core/errors/generator-error");
11
+ const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
12
+ const fileWatcher_1 = require("../../../../utils/fileWatcher");
13
+ const validation_error_1 = require("../../../../errors/validation-error");
14
+ const generator_error_1 = require("../../../../errors/generator-error");
17
15
  const parser_1 = require("@asyncapi/parser");
18
16
  const prompts_1 = require("@clack/prompts");
19
17
  const picocolors_1 = require("picocolors");
20
- const fromTemplate_flags_1 = require("../../core/flags/generate/fromTemplate.flags");
21
- const proxy_flags_1 = require("../../core/flags/proxy.flags");
22
- const templatesNotSupportingV3 = {
23
- '@asyncapi/minimaltemplate': 'some link', // For testing purpose
24
- '@asyncapi/dotnet-nats-template': 'https://github.com/asyncapi/dotnet-nats-template/issues/384',
25
- '@asyncapi/ts-nats-template': 'https://github.com/asyncapi/ts-nats-template/issues/545',
26
- '@asyncapi/python-paho-template': 'https://github.com/asyncapi/python-paho-template/issues/189',
27
- '@asyncapi/nodejs-ws-template': 'https://github.com/asyncapi/nodejs-ws-template/issues/294',
28
- '@asyncapi/java-spring-cloud-stream-template': 'https://github.com/asyncapi/java-spring-cloud-stream-template/issues/336',
29
- '@asyncapi/go-watermill-template': 'https://github.com/asyncapi/go-watermill-template/issues/243',
30
- '@asyncapi/java-spring-template': 'https://github.com/asyncapi/java-spring-template/issues/308',
31
- '@asyncapi/php-template': 'https://github.com/asyncapi/php-template/issues/191'
32
- };
33
- /**
34
- * Verify that a given template support v3, if not, return the link to the issue that needs to be solved.
35
- */
36
- function verifyTemplateSupportForV3(template) {
37
- if (templatesNotSupportingV3[`${template}`] !== undefined) {
38
- return templatesNotSupportingV3[`${template}`];
39
- }
40
- return undefined;
41
- }
18
+ const fromTemplate_flags_1 = require("../../internal/flags/generate/fromTemplate.flags");
19
+ const proxy_flags_1 = require("../../internal/flags/proxy.flags");
20
+ const generator_service_1 = require("../../../../domains/services/generator.service");
42
21
  class Template extends base_1.default {
43
22
  constructor() {
44
23
  super(...arguments);
24
+ this.generatorService = new generator_service_1.GeneratorService(true);
45
25
  this.parser = new parser_1.Parser();
46
26
  this.getMapBaseUrlToFolderResolver = (urlToFolder) => {
47
27
  return {
@@ -52,7 +32,7 @@ class Template extends base_1.default {
52
32
  read(file) {
53
33
  const baseUrl = urlToFolder.url;
54
34
  const baseDir = urlToFolder.folder;
55
- return new Promise(((resolve, reject) => {
35
+ return new Promise((resolve, reject) => {
56
36
  let localpath = file.url;
57
37
  localpath = localpath.replace(baseUrl, baseDir);
58
38
  try {
@@ -68,14 +48,14 @@ class Template extends base_1.default {
68
48
  catch (err) {
69
49
  reject(`Error opening file "${localpath}"`);
70
50
  }
71
- }));
72
- }
51
+ });
52
+ },
73
53
  };
74
54
  };
75
55
  }
76
56
  run() {
77
57
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
78
- var _a, _b;
58
+ var _a, _b, _c, _d;
79
59
  const { args, flags } = yield this.parse(Template); // NOSONAR
80
60
  const interactive = !flags['no-interactive'];
81
61
  let asyncapi = (_a = args['asyncapi']) !== null && _a !== void 0 ? _a : '';
@@ -101,8 +81,8 @@ class Template extends base_1.default {
101
81
  registry: {
102
82
  url: flags['registry-url'],
103
83
  auth: flags['registry-auth'],
104
- token: flags['registry-token']
105
- }
84
+ token: flags['registry-token'],
85
+ },
106
86
  };
107
87
  if (proxyHost && proxyPort) {
108
88
  const proxyUrl = `http://${proxyHost}:${proxyPort}`;
@@ -114,19 +94,35 @@ class Template extends base_1.default {
114
94
  const watchTemplate = flags['watch'];
115
95
  const genOption = {};
116
96
  if (flags['map-base-url']) {
117
- genOption.resolve = { resolve: this.getMapBaseUrlToFolderResolver(parsedFlags.mapBaseUrlToFolder) };
97
+ genOption.resolve = {
98
+ resolve: this.getMapBaseUrlToFolderResolver(parsedFlags.mapBaseUrlToFolder),
99
+ };
118
100
  }
119
- if (asyncapiInput.isAsyncAPI3()) {
120
- const v3IssueLink = verifyTemplateSupportForV3(template);
121
- if (v3IssueLink !== undefined) {
122
- this.error(`${template} template does not support AsyncAPI v3 documents, please checkout ${v3IssueLink}`);
123
- }
101
+ let specification;
102
+ try {
103
+ specification = yield (0, SpecificationFile_1.load)(asyncapi);
104
+ }
105
+ catch (err) {
106
+ return this.error(new validation_error_1.ValidationError({
107
+ type: 'invalid-file',
108
+ filepath: asyncapi,
109
+ }), { exit: 1 });
124
110
  }
125
111
  if (flags['use-new-generator']) {
126
- yield this.generateUsingNewGenerator(asyncapi, template, output, options, genOption);
112
+ this.log('Generation in progress. Keep calm and wait a bit');
113
+ const result = yield this.generatorService.generateUsingNewGenerator(specification, template, output, options, genOption);
114
+ if (!result.success) {
115
+ throw new generator_error_1.GeneratorError(new Error(result.error));
116
+ }
117
+ else {
118
+ this.log((_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c.logs) === null || _d === void 0 ? void 0 : _d.join('\n'));
119
+ }
127
120
  }
128
121
  else {
129
- yield this.generate(asyncapi, template, output, options, genOption, interactive);
122
+ const result = yield this.generatorService.generate(specification, template, output, options, genOption, interactive);
123
+ if (!result.success) {
124
+ throw new generator_error_1.GeneratorError(new Error(result.error));
125
+ }
130
126
  }
131
127
  if (watchTemplate) {
132
128
  const watcherHandler = this.watcherHandler(asyncapi, template, output, options, genOption, interactive);
@@ -151,7 +147,7 @@ class Template extends base_1.default {
151
147
  else if (!fs_1.default.existsSync(value)) {
152
148
  return 'The file does not exist';
153
149
  }
154
- }
150
+ },
155
151
  });
156
152
  }
157
153
  if ((0, prompts_1.isCancel)(asyncapi)) {
@@ -175,7 +171,7 @@ class Template extends base_1.default {
175
171
  else if (typeof value !== 'string') {
176
172
  return 'The output directory must be a string';
177
173
  }
178
- }
174
+ },
179
175
  }));
180
176
  }
181
177
  if ((0, prompts_1.isCancel)(output) || (0, prompts_1.isCancel)(template)) {
@@ -184,13 +180,32 @@ class Template extends base_1.default {
184
180
  return { asyncapi, template, output };
185
181
  });
186
182
  }
183
+ disableHooksParser(inputs) {
184
+ if (!inputs) {
185
+ return {};
186
+ }
187
+ const disableHooks = {};
188
+ for (const input of inputs) {
189
+ const [hookType, hookNames] = input.split(/=/);
190
+ if (!hookType) {
191
+ throw new Error('Invalid --disable-hook flag. It must be in the format of: --disable-hook <hookType> or --disable-hook <hookType>=<hookName1>,<hookName2>,...');
192
+ }
193
+ if (hookNames) {
194
+ disableHooks[String(hookType)] = hookNames.split(',');
195
+ }
196
+ else {
197
+ disableHooks[String(hookType)] = true;
198
+ }
199
+ }
200
+ return disableHooks;
201
+ }
187
202
  parseFlags(disableHooks, params, mapBaseUrl, registryUrl, registryAuth, registryToken) {
188
203
  return {
189
204
  params: this.paramParser(params),
190
205
  disableHooks: this.disableHooksParser(disableHooks),
191
206
  mapBaseUrlToFolder: this.mapBaseURLParser(mapBaseUrl),
192
207
  registryURLValidation: this.registryURLParser(registryUrl),
193
- registryAuthentication: this.registryValidation(registryUrl, registryAuth, registryToken)
208
+ registryAuthentication: this.registryValidation(registryUrl, registryAuth, registryToken),
194
209
  };
195
210
  }
196
211
  registryURLParser(input) {
@@ -232,25 +247,6 @@ class Template extends base_1.default {
232
247
  }
233
248
  return params;
234
249
  }
235
- disableHooksParser(inputs) {
236
- if (!inputs) {
237
- return {};
238
- }
239
- const disableHooks = {};
240
- for (const input of inputs) {
241
- const [hookType, hookNames] = input.split(/=/);
242
- if (!hookType) {
243
- throw new Error('Invalid --disable-hook flag. It must be in the format of: --disable-hook <hookType> or --disable-hook <hookType>=<hookName1>,<hookName2>,...');
244
- }
245
- if (hookNames) {
246
- disableHooks[String(hookType)] = hookNames.split(',');
247
- }
248
- else {
249
- disableHooks[String(hookType)] = true;
250
- }
251
- }
252
- return disableHooks;
253
- }
254
250
  mapBaseURLParser(input) {
255
251
  if (!input) {
256
252
  return;
@@ -269,55 +265,6 @@ class Template extends base_1.default {
269
265
  }
270
266
  return mapBaseURLToFolder;
271
267
  }
272
- generate(asyncapi_1, template_1, output_1, options_1, genOption_1) {
273
- return tslib_1.__awaiter(this, arguments, void 0, function* (asyncapi, template, output, options, genOption, interactive = true) {
274
- let specification;
275
- try {
276
- specification = yield (0, SpecificationFile_1.load)(asyncapi);
277
- }
278
- catch (err) {
279
- return this.error(new validation_error_1.ValidationError({
280
- type: 'invalid-file',
281
- filepath: asyncapi,
282
- }), { exit: 1 });
283
- }
284
- const generator = new generator_1.default(template, output || path_1.default.resolve(os_1.default.tmpdir(), 'asyncapi-generator'), options);
285
- const s = interactive ? (0, prompts_1.spinner)() : { start: () => null, stop: (string) => console.log(string) };
286
- s.start('Generation in progress. Keep calm and wait a bit');
287
- try {
288
- yield generator.generateFromString(specification.text(), Object.assign(Object.assign({}, genOption), { path: asyncapi }));
289
- }
290
- catch (err) {
291
- s.stop('Generation failed');
292
- throw new generator_error_1.GeneratorError(err);
293
- }
294
- s.stop(`${(0, picocolors_1.yellow)('Check out your shiny new generated files at ') + (0, picocolors_1.magenta)(output) + (0, picocolors_1.yellow)('.')}\n`);
295
- });
296
- }
297
- generateUsingNewGenerator(asyncapi, template, output, options, genOption) {
298
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
299
- let specification;
300
- try {
301
- specification = yield (0, SpecificationFile_1.load)(asyncapi);
302
- }
303
- catch (err) {
304
- return this.error(new validation_error_1.ValidationError({
305
- type: 'invalid-file',
306
- filepath: asyncapi,
307
- }), { exit: 1 });
308
- }
309
- const generator = new generator_v2_1.default(template, output || path_1.default.resolve(os_1.default.tmpdir(), 'asyncapi-generator'), options);
310
- this.log('Generation in progress. Keep calm and wait a bit');
311
- try {
312
- yield generator.generateFromString(specification.text(), Object.assign(Object.assign({}, genOption), { path: asyncapi }));
313
- }
314
- catch (err) {
315
- this.log('Generation failed');
316
- throw new generator_error_1.GeneratorError(err);
317
- }
318
- this.log(`${(0, picocolors_1.yellow)('Check out your shiny new generated files at ') + (0, picocolors_1.magenta)(output) + (0, picocolors_1.yellow)('.')}\n`);
319
- });
320
- }
321
268
  runWatchMode(asyncapi, template, output, watchHandler) {
322
269
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
323
270
  const specification = yield (0, SpecificationFile_1.load)(asyncapi);
@@ -337,16 +284,17 @@ class Template extends base_1.default {
337
284
  // intentional
338
285
  }
339
286
  let watcher;
340
- if (specificationFile) { // is local AsyncAPI file
287
+ if (specificationFile) {
288
+ // is local AsyncAPI file
341
289
  this.log(`[WATCHER] Watching for changes in the template directory ${(0, picocolors_1.magenta)(watchDir)} and in the AsyncAPI file ${(0, picocolors_1.magenta)(specificationFile)}`);
342
- watcher = new generator_2.Watcher([specificationFile, watchDir], ignorePaths);
290
+ watcher = new fileWatcher_1.Watcher([specificationFile, watchDir], ignorePaths);
343
291
  }
344
292
  else {
345
293
  this.log(`[WATCHER] Watching for changes in the template directory ${(0, picocolors_1.magenta)(watchDir)}`);
346
- watcher = new generator_2.Watcher(watchDir, ignorePaths);
294
+ watcher = new fileWatcher_1.Watcher(watchDir, ignorePaths);
347
295
  }
348
296
  // Must check template in its installation path in generator to use isLocalTemplate function
349
- if (!(yield (0, generator_2.isLocalTemplate)(path_1.default.resolve(generator_1.default.DEFAULT_TEMPLATES_DIR, templateName)))) {
297
+ if (!(yield (0, fileWatcher_1.isLocalTemplate)(path_1.default.resolve(generator_1.default.DEFAULT_TEMPLATES_DIR, templateName)))) {
350
298
  this.warn(`WARNING: ${template} is a remote template. Changes may be lost on subsequent installations.`);
351
299
  }
352
300
  yield watcher.watch(watchHandler, (paths) => {
@@ -377,8 +325,21 @@ class Template extends base_1.default {
377
325
  }
378
326
  this.log(`\t${(0, picocolors_1.magenta)(value.path)} was ${eventText}`);
379
327
  }
328
+ let specification;
380
329
  try {
381
- yield this.generate(asyncapi, template, output, options, genOption, interactive);
330
+ specification = yield (0, SpecificationFile_1.load)(asyncapi);
331
+ }
332
+ catch (err) {
333
+ return this.error(new validation_error_1.ValidationError({
334
+ type: 'invalid-file',
335
+ filepath: asyncapi,
336
+ }), { exit: 1 });
337
+ }
338
+ try {
339
+ const result = yield this.generatorService.generate(specification, template, output, options, genOption, interactive);
340
+ if (!result.success) {
341
+ throw new generator_error_1.GeneratorError(new Error(result.error));
342
+ }
382
343
  }
383
344
  catch (err) {
384
345
  throw new generator_error_1.GeneratorError(err);
@@ -388,11 +349,17 @@ class Template extends base_1.default {
388
349
  }
389
350
  Template.description = 'Generates whatever you want using templates compatible with AsyncAPI Generator.';
390
351
  Template.examples = [
391
- 'asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --param version=1.0.0 singleFile=true --output ./docs --force-write'
352
+ 'asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --param version=1.0.0 singleFile=true --output ./docs --force-write',
392
353
  ];
393
354
  Template.flags = Object.assign(Object.assign({}, (0, fromTemplate_flags_1.fromTemplateFlags)()), (0, proxy_flags_1.proxyFlags)());
394
355
  Template.args = {
395
- asyncapi: core_1.Args.string({ description: '- Local path, url or context-name pointing to AsyncAPI file', required: false }),
396
- template: core_1.Args.string({ description: '- Name of the generator template like for example @asyncapi/html-template or https://github.com/asyncapi/html-template', required: false }),
356
+ asyncapi: core_1.Args.string({
357
+ description: '- Local path, url or context-name pointing to AsyncAPI file',
358
+ required: false,
359
+ }),
360
+ template: core_1.Args.string({
361
+ description: '- Name of the generator template like for example @asyncapi/html-template or https://github.com/asyncapi/html-template',
362
+ required: false,
363
+ }),
397
364
  };
398
365
  exports.default = Template;
@@ -1,4 +1,4 @@
1
- import Command from '../../core/base';
1
+ import Command from '../../internal/base';
2
2
  export default class Generate extends Command {
3
3
  static description: string;
4
4
  run(): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const base_1 = tslib_1.__importDefault(require("../../core/base"));
4
+ const base_1 = tslib_1.__importDefault(require("../../internal/base"));
5
5
  const core_1 = require("@oclif/core");
6
6
  class Generate extends base_1.default {
7
7
  run() {
@@ -1,6 +1,10 @@
1
- import Command from '../../core/base';
1
+ import Command from '../../internal/base';
2
+ import { Specification } from '../../../../domains/models/SpecificationFile';
3
+ import { ValidationStatus } from '../../../../domains/services/validation.service';
4
+ import { Diagnostic } from '@asyncapi/parser/cjs';
2
5
  export default class Models extends Command {
3
6
  static description: string;
7
+ private validationService;
4
8
  static readonly args: any;
5
9
  static readonly flags: {
6
10
  proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -8,4 +12,5 @@ export default class Models extends Command {
8
12
  };
9
13
  run(): Promise<void>;
10
14
  private parseArgs;
15
+ handleGovernanceMessage(document: Specification, diagnostics: Diagnostic[], status: ValidationStatus): Promise<void>;
11
16
  }
@@ -1,15 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const base_1 = tslib_1.__importDefault(require("../../core/base"));
5
- const SpecificationFile_1 = require("../../core/models/SpecificationFile");
6
- const parser_1 = require("../../core/parser");
4
+ const base_1 = tslib_1.__importDefault(require("../../internal/base"));
5
+ const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
7
6
  const prompts_1 = require("@clack/prompts");
8
7
  const picocolors_1 = require("picocolors");
9
8
  const modelina_cli_1 = require("@asyncapi/modelina-cli");
10
- const models_flags_1 = require("../../core/flags/generate/models.flags");
11
- const proxy_flags_1 = require("../../core/flags/proxy.flags");
9
+ const models_flags_1 = require("../../internal/flags/generate/models.flags");
10
+ const proxy_flags_1 = require("../../internal/flags/proxy.flags");
11
+ const validation_service_1 = require("../../../../domains/services/validation.service");
12
12
  class Models extends base_1.default {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.validationService = new validation_service_1.ValidationService();
16
+ }
13
17
  run() {
14
18
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
19
  const { args, flags } = yield this.parse(Models);
@@ -29,12 +33,27 @@ class Models extends base_1.default {
29
33
  file = `${file}+${proxyUrl}`;
30
34
  }
31
35
  const inputFile = (yield (0, SpecificationFile_1.load)(file)) || (yield (0, SpecificationFile_1.load)());
32
- const { document, diagnostics, status } = yield (0, parser_1.parse)(this, inputFile, flags);
36
+ const result = yield this.validationService.parseDocument(inputFile, {}, flags);
37
+ if (!result.success) {
38
+ this.error(`Failed to parse the AsyncAPI document: ${result.error}`, {
39
+ exit: 1,
40
+ });
41
+ }
42
+ else if (!result.data) {
43
+ this.error('No data returned from parsing the AsyncAPI document.', {
44
+ exit: 1,
45
+ });
46
+ }
47
+ const { document, diagnostics, status } = result.data;
33
48
  if (!document || status === 'invalid') {
34
49
  const severityErrors = diagnostics.filter((obj) => obj.severity === 0);
35
- this.log(`Input is not a correct AsyncAPI document so it cannot be processed.${(0, parser_1.formatOutput)(severityErrors, 'stylish', 'error')}`);
50
+ this.log(`Input is not a correct AsyncAPI document so it cannot be processed.${this.validationService.formatDiagnosticsOutput(severityErrors, 'stylish', 'error')}`);
36
51
  return;
37
52
  }
53
+ if (flags['log-diagnostics'] && inputFile) {
54
+ this.handleGovernanceMessage(inputFile, diagnostics, status);
55
+ this.log(this.validationService.formatDiagnosticsOutput(diagnostics, flags['diagnostics-format'], flags['fail-severity']));
56
+ }
38
57
  const logger = {
39
58
  info: (message) => {
40
59
  this.log(message);
@@ -54,7 +73,9 @@ class Models extends base_1.default {
54
73
  try {
55
74
  const generatedModels = yield (0, modelina_cli_1.generateModels)(Object.assign(Object.assign({}, flags), { output }), document, logger, language);
56
75
  if (output && output !== 'stdout') {
57
- const generatedModelStrings = generatedModels.map((model) => { return model.modelName; });
76
+ const generatedModelStrings = generatedModels.map((model) => {
77
+ return model.modelName;
78
+ });
58
79
  s.stop((0, picocolors_1.green)(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`));
59
80
  return;
60
81
  }
@@ -85,7 +106,11 @@ class Models extends base_1.default {
85
106
  if (!language) {
86
107
  language = yield (0, prompts_1.select)({
87
108
  message: 'Select the language you want to generate models for',
88
- options: Object.keys(modelina_cli_1.Languages).map((key) => ({ value: key, label: key, hint: modelina_cli_1.Languages[key] })),
109
+ options: Object.keys(modelina_cli_1.Languages).map((key) => ({
110
+ value: key,
111
+ label: key,
112
+ hint: modelina_cli_1.Languages[key],
113
+ })),
89
114
  });
90
115
  askForOutput = true;
91
116
  }
@@ -119,6 +144,20 @@ class Models extends base_1.default {
119
144
  return { language, file, output: output !== null && output !== void 0 ? output : 'stdout' };
120
145
  });
121
146
  }
147
+ handleGovernanceMessage(document, diagnostics, status) {
148
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
149
+ const sourceString = document.toSourceString();
150
+ const hasIssues = diagnostics && diagnostics.length > 0;
151
+ const isFailSeverity = status === validation_service_1.ValidationStatus.INVALID;
152
+ const governanceMessage = this.validationService.generateGovernanceMessage(sourceString, hasIssues, isFailSeverity);
153
+ if (isFailSeverity) {
154
+ this.logToStderr(governanceMessage);
155
+ }
156
+ else {
157
+ this.log(governanceMessage);
158
+ }
159
+ });
160
+ }
122
161
  }
123
162
  Models.description = 'Generates typed models';
124
163
  Models.args = modelina_cli_1.ModelinaArgs;
@@ -1,4 +1,4 @@
1
- import Command from '../../core/base';
1
+ import Command from '../../internal/base';
2
2
  export default class NewFile extends Command {
3
3
  static description: string;
4
4
  static flags: {
@@ -2,19 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const fs_1 = require("fs");
5
- const base_1 = tslib_1.__importDefault(require("../../core/base"));
5
+ const base_1 = tslib_1.__importDefault(require("../../internal/base"));
6
6
  const inquirer = tslib_1.__importStar(require("inquirer"));
7
- const Studio_1 = require("../../core/models/Studio");
7
+ const Studio_1 = require("../../../../domains/models/Studio");
8
8
  const path_1 = require("path");
9
- const SpecificationFile_1 = require("../../core/models/SpecificationFile");
9
+ const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
10
10
  const picocolors_1 = require("picocolors");
11
- const file_flags_1 = require("../../core/flags/new/file.flags");
11
+ const file_flags_1 = require("../../internal/flags/new/file.flags");
12
12
  const { writeFile, readFile } = fs_1.promises;
13
13
  const DEFAULT_ASYNCAPI_FILE_NAME = 'asyncapi.yaml';
14
14
  const DEFAULT_ASYNCAPI_YAML_TEMPLATE = 'default-example.yaml';
15
15
  const DEFAULT_ASYNCAPI_JSON_TEMPLATE = 'default-example.json';
16
16
  function loadExampleFile() {
17
- const exampleFiles = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '../../../assets/examples/examples.json'), { encoding: 'utf8' });
17
+ const exampleFiles = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '../../../../../assets/examples/examples.json'), { encoding: 'utf8' });
18
18
  return JSON.parse(exampleFiles);
19
19
  }
20
20
  function getExamplesFlagDescription() {
@@ -57,6 +57,7 @@ class NewFile extends base_1.default {
57
57
  /* eslint-disable sonarjs/cognitive-complexity */
58
58
  runInteractive() {
59
59
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
60
+ // NOSONAR
60
61
  const { flags } = yield this.parse(NewFile); // NOSONAR
61
62
  let fileName = flags['file-name'];
62
63
  let selectedTemplate = flags['example'];
@@ -134,7 +135,7 @@ class NewFile extends base_1.default {
134
135
  }
135
136
  createAsyncapiFile(fileName, selectedTemplate) {
136
137
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
137
- const asyncApiFile = yield readFile((0, path_1.resolve)(__dirname, '../../../assets/examples/', selectedTemplate), { encoding: 'utf8' });
138
+ const asyncApiFile = yield readFile((0, path_1.resolve)(__dirname, '../../../../../assets/examples/', selectedTemplate), { encoding: 'utf8' });
138
139
  let fileNameToWriteToDisk;
139
140
  if (!fileName.includes('.')) {
140
141
  fileNameToWriteToDisk = `${fileName}.yaml`;
@@ -150,7 +151,9 @@ class NewFile extends base_1.default {
150
151
  }
151
152
  }
152
153
  try {
153
- const content = yield readFile(fileNameToWriteToDisk, { encoding: 'utf8' });
154
+ const content = yield readFile(fileNameToWriteToDisk, {
155
+ encoding: 'utf8',
156
+ });
154
157
  if (content !== undefined) {
155
158
  console.log(`A file named ${fileNameToWriteToDisk} already exists. Please choose a different name.`);
156
159
  return;
@@ -172,6 +175,6 @@ NewFile.description = 'Creates a new asyncapi file';
172
175
  NewFile.flags = (0, file_flags_1.fileFlags)(getExamplesFlagDescription());
173
176
  NewFile.examples = [
174
177
  'asyncapi new\t - start creation of a file in interactive mode',
175
- 'asyncapi new --file-name=my-asyncapi.yaml --example=default-example.yaml --no-tty\t - create a new file with a specific name, using one of the examples and without interactive mode'
178
+ 'asyncapi new --file-name=my-asyncapi.yaml --example=default-example.yaml --no-tty\t - create a new file with a specific name, using one of the examples and without interactive mode',
176
179
  ];
177
180
  exports.default = NewFile;
@@ -1,5 +1,5 @@
1
- import Command from '../../core/base';
2
- import { Specification } from '../../core/models/SpecificationFile';
1
+ import Command from '../../internal/base';
2
+ import { Specification } from '../../../../domains/models/SpecificationFile';
3
3
  export declare const successMessage: (projectName: string) => string;
4
4
  export default class NewGlee extends Command {
5
5
  static description: string;
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.successMessage = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_1 = require("fs");
6
- const base_1 = tslib_1.__importDefault(require("../../core/base"));
6
+ const base_1 = tslib_1.__importDefault(require("../../internal/base"));
7
7
  const path_1 = tslib_1.__importStar(require("path"));
8
8
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
9
- const SpecificationFile_1 = require("../../core/models/SpecificationFile");
9
+ const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
10
10
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
11
11
  const inquirer_1 = require("inquirer");
12
12
  // eslint-disable-next-line
13
13
  // @ts-ignore
14
14
  const generator_1 = tslib_1.__importDefault(require("@asyncapi/generator"));
15
15
  const picocolors_1 = require("picocolors");
16
- const glee_flags_1 = require("../../core/flags/new/glee.flags");
16
+ const glee_flags_1 = require("../../internal/flags/new/glee.flags");
17
17
  const successMessage = (projectName) => `🎉 Your Glee project has been successfully created!
18
18
  ⏩ Next steps: follow the instructions ${(0, picocolors_1.cyan)('below')} to manage your project:
19
19
 
@@ -124,7 +124,7 @@ class NewGlee extends base_1.default {
124
124
  const { flags } = yield this.parse(NewGlee); // NOSONAR
125
125
  const { name: projectName, template: templateName, file, 'force-write': forceWrite, } = flags;
126
126
  const PROJECT_DIRECTORY = (0, path_1.join)(process.cwd(), projectName);
127
- const GLEE_TEMPLATES_DIRECTORY = (0, path_1.resolve)(__dirname, '../../../assets/create-glee-app/templates/', templateName);
127
+ const GLEE_TEMPLATES_DIRECTORY = (0, path_1.resolve)(__dirname, '../../../../../assets/create-glee-app/templates/', templateName);
128
128
  const CURRENT_GLEE_TEMPLATE = 'https://github.com/KhudaDad414/glee-generator-template';
129
129
  if (file && templateName && templateName !== 'default') {
130
130
  this.error('You cannot use both --t and --f in the same command.');
@@ -1,4 +1,4 @@
1
- import Command from '../../core/base';
1
+ import Command from '../../internal/base';
2
2
  export default class New extends Command {
3
3
  static readonly description = "Create a new AsyncAPI project, specification files, or templates for clients and applications.";
4
4
  run(): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const base_1 = tslib_1.__importDefault(require("../../core/base"));
4
+ const base_1 = tslib_1.__importDefault(require("../../internal/base"));
5
5
  const core_1 = require("@oclif/core");
6
6
  class New extends base_1.default {
7
7
  run() {
@@ -1,4 +1,4 @@
1
- import Command from '../../core/base';
1
+ import Command from '../../internal/base';
2
2
  export declare const successMessage: (projectName: string) => string;
3
3
  export default class template extends Command {
4
4
  static description: string;