@asyncapi/cli 4.1.1 → 5.0.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 (45) hide show
  1. package/README.md +4 -0
  2. package/assets/create-template/templates/default/package-lock.json +4 -3
  3. package/lib/apps/api/controllers/generate.controller.js +1 -3
  4. package/lib/apps/cli/commands/convert.d.ts +0 -2
  5. package/lib/apps/cli/commands/convert.js +9 -14
  6. package/lib/apps/cli/commands/format.d.ts +1 -3
  7. package/lib/apps/cli/commands/format.js +7 -10
  8. package/lib/apps/cli/commands/generate/client.js +5 -5
  9. package/lib/apps/cli/commands/generate/fromTemplate.d.ts +0 -25
  10. package/lib/apps/cli/commands/generate/fromTemplate.js +9 -17
  11. package/lib/apps/cli/commands/generate/models.js +3 -5
  12. package/lib/apps/cli/commands/optimize.js +11 -12
  13. package/lib/apps/cli/commands/start/preview.js +1 -1
  14. package/lib/apps/cli/commands/validate.js +2 -7
  15. package/lib/apps/cli/internal/base/BaseGeneratorCommand.js +3 -5
  16. package/lib/apps/cli/internal/base.d.ts +1 -1
  17. package/lib/apps/cli/internal/base.js +8 -7
  18. package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.d.ts +0 -25
  19. package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.js +1 -2
  20. package/lib/apps/cli/internal/globals.js +2 -1
  21. package/lib/domains/models/Context.js +3 -1
  22. package/lib/domains/models/Preview.js +9 -2
  23. package/lib/domains/models/SpecificationFile.d.ts +12 -0
  24. package/lib/domains/models/SpecificationFile.js +20 -3
  25. package/lib/domains/models/Studio.js +9 -2
  26. package/lib/domains/services/base.service.d.ts +26 -2
  27. package/lib/domains/services/base.service.js +23 -0
  28. package/lib/domains/services/convert.service.d.ts +13 -0
  29. package/lib/domains/services/convert.service.js +14 -3
  30. package/lib/domains/services/generator.service.d.ts +20 -2
  31. package/lib/domains/services/generator.service.js +21 -28
  32. package/lib/domains/services/validation.service.d.ts +16 -0
  33. package/lib/domains/services/validation.service.js +68 -57
  34. package/lib/index.d.ts +4 -0
  35. package/lib/index.js +7 -0
  36. package/lib/interfaces/index.d.ts +54 -12
  37. package/lib/utils/error-handler.d.ts +95 -0
  38. package/lib/utils/error-handler.js +134 -0
  39. package/lib/utils/proxy.d.ts +29 -0
  40. package/lib/utils/proxy.js +47 -0
  41. package/lib/utils/validation.d.ts +103 -0
  42. package/lib/utils/validation.js +159 -0
  43. package/oclif.manifest.json +1 -9
  44. package/package.json +10 -11
  45. package/scripts/generateTypesForGenerateCommand.js +1 -1
package/README.md CHANGED
@@ -13,6 +13,7 @@ CLI to work with your AsyncAPI files. Currently under development, we are workin
13
13
  - [Installation](#installation)
14
14
  - [Usage](#usage)
15
15
  - [Architecture](#architecture)
16
+ - [Debugging & Testing](#debugging--testing)
16
17
  - [Github Action](#github-action)
17
18
  - [Contributing](#contributing)
18
19
  * [Set up development environment](#set-up-development-environment)
@@ -30,6 +31,9 @@ The [usage guide](/docs/usage.md) provides information about different ways to u
30
31
  ## Architecture
31
32
  The [architecture guide](/docs/architecture.md) provides information about the architecture.
32
33
 
34
+ ## Debugging & Testing
35
+ The [debugging & testing guide](/docs/debugging-testing.md) provides step-by-step instructions for debugging CLI commands, API endpoints, and services, along with comprehensive testing guidelines.
36
+
33
37
  ## Github Action
34
38
 
35
39
  The AsyncAPI CLI can be used as a GitHub Action. You can find more information in the [GitHub Action guide](https://www.asyncapi.com/docs/tools/cli/github-action).
@@ -3243,9 +3243,10 @@
3243
3243
  "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
3244
3244
  },
3245
3245
  "node_modules/js-yaml": {
3246
- "version": "4.1.0",
3247
- "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
3248
- "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
3246
+ "version": "4.1.1",
3247
+ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz",
3248
+ "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==",
3249
+ "license": "MIT",
3249
3250
  "dependencies": {
3250
3251
  "argparse": "^2.0.1"
3251
3252
  },
@@ -36,9 +36,7 @@ class GenerateController {
36
36
  forceWrite: true,
37
37
  templateParams: parameters,
38
38
  };
39
- const generateFunc = req.body['use-fallback-generator']
40
- ? this.generatorService.generate.bind(this.generatorService)
41
- : this.generatorService.generateUsingNewGenerator.bind(this.generatorService);
39
+ const generateFunc = this.generatorService.generate.bind(this.generatorService);
42
40
  try {
43
41
  const result = yield generateFunc(new SpecificationFile_1.Specification(typeof asyncapi === 'object' ? JSON.stringify(asyncapi) : asyncapi), template, tmpDir, options, {}, true);
44
42
  if (!result.success) {
@@ -1,7 +1,5 @@
1
1
  import Command from '../internal/base';
2
2
  export default class Convert extends Command {
3
- static specFile: any;
4
- static metricsMetadata: any;
5
3
  static description: string;
6
4
  private conversionService;
7
5
  static flags: {
@@ -11,7 +11,9 @@ const proxy_flags_1 = require("../internal/flags/proxy.flags");
11
11
  const specs_1 = tslib_1.__importDefault(require("@asyncapi/specs"));
12
12
  const convert_flags_1 = require("../internal/flags/convert.flags");
13
13
  const convert_service_1 = require("../../../domains/services/convert.service");
14
+ const proxy_1 = require("../../../utils/proxy");
14
15
  const latestVersion = Object.keys(specs_1.default.schemas).pop();
16
+ const TARGET_VERSION_FLAG = 'target-version';
15
17
  class Convert extends base_1.default {
16
18
  constructor() {
17
19
  super(...arguments);
@@ -20,21 +22,15 @@ class Convert extends base_1.default {
20
22
  run() {
21
23
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
22
24
  const { args, flags } = yield this.parse(Convert);
23
- let filePath = args['spec-file'];
24
- const proxyHost = flags['proxyHost'];
25
- const proxyPort = flags['proxyPort'];
26
- if (proxyHost && proxyPort) {
27
- const proxyUrl = `http://${proxyHost}:${proxyPort}`;
28
- filePath = `${filePath}+${proxyUrl}`; // Update filePath with proxyUrl
29
- }
25
+ const filePath = (0, proxy_1.applyProxyToPath)(args['spec-file'], flags['proxyHost'], flags['proxyPort']);
26
+ const targetVersion = flags[TARGET_VERSION_FLAG];
30
27
  try {
31
28
  // LOAD FILE
32
29
  this.specFile = yield (0, SpecificationFile_1.load)(filePath);
33
- // eslint-disable-next-line sonarjs/no-duplicate-string
34
- this.metricsMetadata.to_version = flags['target-version'];
30
+ this.metricsMetadata.to_version = targetVersion;
35
31
  const conversionOptions = {
36
32
  format: flags.format,
37
- 'target-version': (flags['target-version'] ||
33
+ [TARGET_VERSION_FLAG]: (targetVersion ||
38
34
  latestVersion),
39
35
  perspective: flags['perspective'],
40
36
  };
@@ -52,12 +48,12 @@ class Convert extends base_1.default {
52
48
  }
53
49
  }
54
50
  catch (err) {
55
- this.handleError(err, filePath !== null && filePath !== void 0 ? filePath : 'unknown', flags);
51
+ this.handleError(err, filePath !== null && filePath !== void 0 ? filePath : 'unknown', targetVersion);
56
52
  }
57
53
  });
58
54
  }
59
55
  // Helper function to handle errors
60
- handleError(err, filePath, flags) {
56
+ handleError(err, filePath, targetVersion) {
61
57
  var _a;
62
58
  if (err instanceof specification_file_1.SpecificationFileNotFound) {
63
59
  this.error(new validation_error_1.ValidationError({
@@ -65,7 +61,7 @@ class Convert extends base_1.default {
65
61
  filepath: filePath,
66
62
  }));
67
63
  }
68
- else if (((_a = this.specFile) === null || _a === void 0 ? void 0 : _a.toJson().asyncapi) > flags['target-version']) {
64
+ else if (((_a = this.specFile) === null || _a === void 0 ? void 0 : _a.toJson().asyncapi) > (targetVersion !== null && targetVersion !== void 0 ? targetVersion : '')) {
69
65
  this.error(`The ${(0, picocolors_1.cyan)(filePath)} file cannot be converted to an older version. Downgrading is not supported.`);
70
66
  }
71
67
  else {
@@ -73,7 +69,6 @@ class Convert extends base_1.default {
73
69
  }
74
70
  }
75
71
  }
76
- Convert.metricsMetadata = {};
77
72
  Convert.description = 'Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI';
78
73
  Convert.flags = Object.assign(Object.assign({}, (0, convert_flags_1.convertFlags)(latestVersion)), (0, proxy_flags_1.proxyFlags)());
79
74
  Convert.args = {
@@ -1,7 +1,5 @@
1
1
  import Command from '../internal/base';
2
- export default class Convert extends Command {
3
- static specFile: any;
4
- static metricsMetadata: any;
2
+ export default class Format extends Command {
5
3
  static description: string;
6
4
  static flags: {
7
5
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- /* eslint-disable @typescript-eslint/ban-ts-comment */
5
4
  const fs_1 = require("fs");
6
5
  const core_1 = require("@oclif/core");
7
6
  const base_1 = tslib_1.__importDefault(require("../internal/base"));
@@ -9,17 +8,16 @@ const SpecificationFile_1 = require("../../../domains/models/SpecificationFile")
9
8
  const specification_file_1 = require("../../../errors/specification-file");
10
9
  const picocolors_1 = require("picocolors");
11
10
  const format_flags_1 = require("../internal/flags/format.flags");
12
- class Convert extends base_1.default {
11
+ class Format extends base_1.default {
13
12
  run() {
14
13
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
- const { args, flags } = yield this.parse(Convert);
14
+ const { args, flags } = yield this.parse(Format);
16
15
  const filePath = args['spec-file'];
17
16
  const outputFileFormat = flags['format'];
18
17
  let convertedFile;
19
18
  try {
20
19
  this.specFile = yield (0, SpecificationFile_1.load)(filePath);
21
- // eslint-disable-next-line sonarjs/no-duplicate-string
22
- this.metricsMetadata.to_version = flags['target-version'];
20
+ this.metricsMetadata.output_format = outputFileFormat;
23
21
  const ff = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
24
22
  const isSpecFileJson = ff === 'json';
25
23
  const isSpecFileYaml = ff === 'yaml';
@@ -85,13 +83,12 @@ class Convert extends base_1.default {
85
83
  return filename;
86
84
  }
87
85
  }
88
- Convert.metricsMetadata = {};
89
- Convert.description = 'Convert asyncapi documents from any format to yaml, yml or JSON';
90
- Convert.flags = (0, format_flags_1.convertFormatFlags)();
91
- Convert.args = {
86
+ Format.description = 'Convert asyncapi documents from any format to yaml, yml or JSON';
87
+ Format.flags = (0, format_flags_1.convertFormatFlags)();
88
+ Format.args = {
92
89
  'spec-file': core_1.Args.string({
93
90
  description: 'spec path, url, or context-name',
94
91
  required: false,
95
92
  }),
96
93
  };
97
- exports.default = Convert;
94
+ exports.default = Format;
@@ -5,7 +5,7 @@ const core_1 = require("@oclif/core");
5
5
  const BaseGeneratorCommand_1 = require("../../internal/base/BaseGeneratorCommand");
6
6
  // eslint-disable-next-line
7
7
  // @ts-ignore
8
- const generator_v2_1 = require("generator-v2");
8
+ const generator_1 = require("@asyncapi/generator");
9
9
  const prompts_1 = require("@clack/prompts");
10
10
  const picocolors_1 = require("picocolors");
11
11
  const clients_flags_1 = require("../../internal/flags/generate/clients.flags");
@@ -41,10 +41,10 @@ class Client extends BaseGeneratorCommand_1.BaseGeneratorCommand {
41
41
  this.metricsMetadata.language = language;
42
42
  const watchTemplate = flags['watch'];
43
43
  const genOption = this.buildGenOption(flags, parsedFlags);
44
- // Use GeneratorService with new generator (v2) for client generation
44
+ // Use GeneratorService for client generation
45
45
  const specification = yield this.loadSpecificationSafely(asyncapi);
46
- const result = yield this.generatorService.generateUsingNewGenerator(specification, template, output, options, // GeneratorService expects different options interface
47
- genOption);
46
+ const result = yield this.generatorService.generate(specification, template, output, options, // GeneratorService expects different options interface
47
+ genOption, interactive);
48
48
  if (!result.success) {
49
49
  throw new generator_error_1.GeneratorError(new Error(result.error));
50
50
  }
@@ -73,7 +73,7 @@ class Client extends BaseGeneratorCommand_1.BaseGeneratorCommand {
73
73
  }
74
74
  getTemplateName(language) {
75
75
  var _a;
76
- const template = (_a = (0, generator_v2_1.listBakedInTemplates)({ type: 'client' }).find((template) => {
76
+ const template = (_a = (0, generator_1.listBakedInTemplates)({ type: 'client' }).find((template) => {
77
77
  return template.target === language;
78
78
  })) === null || _a === void 0 ? void 0 : _a.name;
79
79
  if (!template) {
@@ -5,31 +5,6 @@ export default class Template extends BaseGeneratorCommand {
5
5
  static readonly flags: {
6
6
  proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
7
7
  proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
- 'use-new-generator': {
9
- name: string;
10
- char?: import("@oclif/core/lib/interfaces").AlphabetLowercase | import("@oclif/core/lib/interfaces").AlphabetUppercase;
11
- summary?: string;
12
- description: string;
13
- helpLabel?: string;
14
- helpGroup?: string;
15
- env?: string;
16
- hidden?: boolean;
17
- required?: boolean;
18
- dependsOn?: string[];
19
- exclusive?: string[];
20
- exactlyOne?: string[];
21
- relationships?: import("@oclif/core/lib/interfaces/parser").Relationship[];
22
- deprecated?: true | import("@oclif/core/lib/interfaces").Deprecation;
23
- aliases?: string[];
24
- charAliases?: (import("@oclif/core/lib/interfaces").AlphabetLowercase | import("@oclif/core/lib/interfaces").AlphabetUppercase)[];
25
- deprecateAliases?: boolean;
26
- noCacheDefault?: boolean;
27
- atLeastOne?: string[];
28
- type: "boolean";
29
- allowNo: boolean;
30
- default: import("@oclif/core/lib/interfaces/parser").FlagDefault<boolean>;
31
- parse: (input: boolean, context: import("@oclif/core/lib/interfaces/parser").FlagParserContext, opts: import("@oclif/core/lib/interfaces/parser").FlagProps & import("@oclif/core/lib/interfaces/parser").BooleanFlagProps) => Promise<boolean>;
32
- };
33
8
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
34
9
  'disable-hook': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
35
10
  'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -11,12 +11,11 @@ const picocolors_1 = require("picocolors");
11
11
  const fromTemplate_flags_1 = require("../../internal/flags/generate/fromTemplate.flags");
12
12
  const flags_1 = require("../../../../utils/generate/flags");
13
13
  const prompts_2 = require("../../../../utils/generate/prompts");
14
- const inProgressMsg = 'Generation in progress. Keep calm and wait a bit';
15
14
  class Template extends BaseGeneratorCommand_1.BaseGeneratorCommand {
16
15
  // eslint-disable-next-line sonarjs/cognitive-complexity
17
16
  run() {
18
17
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
- var _a, _b, _c, _d;
18
+ var _a, _b, _c;
20
19
  const { args, flags } = yield this.parse(Template); // NOSONAR
21
20
  const interactive = !flags['no-interactive'];
22
21
  let asyncapi = (_a = args['asyncapi']) !== null && _a !== void 0 ? _a : '';
@@ -50,22 +49,15 @@ class Template extends BaseGeneratorCommand_1.BaseGeneratorCommand {
50
49
  filepath: asyncapi,
51
50
  }), { exit: 1 });
52
51
  }
53
- if (flags['use-new-generator']) {
54
- this.log(inProgressMsg);
55
- const result = yield this.generatorService.generateUsingNewGenerator(specification, template, output, options, // GeneratorService expects different options interface
56
- genOption);
57
- if (!result.success) {
58
- throw new generator_error_1.GeneratorError(new Error(result.error));
59
- }
60
- else {
61
- this.log((_d = (_c = result.data) === null || _c === void 0 ? void 0 : _c.logs) === null || _d === void 0 ? void 0 : _d.join('\n'));
62
- }
52
+ const result = yield this.generatorService.generate(specification, template, output, options, // GeneratorService expects different options interface
53
+ genOption, interactive);
54
+ if (!result.success) {
55
+ throw new generator_error_1.GeneratorError(new Error(result.error));
63
56
  }
64
- else {
65
- const result = yield this.generatorService.generate(specification, template, output, options, // GeneratorService expects different options interface
66
- genOption, interactive);
67
- if (!result.success) {
68
- throw new generator_error_1.GeneratorError(new Error(result.error));
57
+ // Output logs in non-interactive mode
58
+ if (!interactive && ((_c = result.data) === null || _c === void 0 ? void 0 : _c.logs)) {
59
+ for (const log of result.data.logs) {
60
+ this.log(log);
69
61
  }
70
62
  }
71
63
  if (watchTemplate) {
@@ -9,6 +9,7 @@ const modelina_cli_1 = require("@asyncapi/modelina-cli");
9
9
  const models_flags_1 = require("../../internal/flags/generate/models.flags");
10
10
  const proxy_flags_1 = require("../../internal/flags/proxy.flags");
11
11
  const validation_service_1 = require("../../../../domains/services/validation.service");
12
+ const proxy_1 = require("../../../../utils/proxy");
12
13
  class Models extends base_1.default {
13
14
  constructor() {
14
15
  super(...arguments);
@@ -29,11 +30,8 @@ class Models extends base_1.default {
29
30
  file = parsedArgs.file;
30
31
  output = parsedArgs.output;
31
32
  }
32
- if (proxyHost && proxyPort) {
33
- const proxyUrl = `http://${proxyHost}:${proxyPort}`;
34
- file = `${file}+${proxyUrl}`;
35
- }
36
- const inputFile = (yield (0, SpecificationFile_1.load)(file)) || (yield (0, SpecificationFile_1.load)());
33
+ const fileWithProxy = (0, proxy_1.applyProxyToPath)(file, proxyHost, proxyPort);
34
+ const inputFile = (yield (0, SpecificationFile_1.load)(fileWithProxy)) || (yield (0, SpecificationFile_1.load)());
37
35
  const result = yield this.validationService.parseDocument(inputFile, {}, flags);
38
36
  if (!result.success) {
39
37
  this.error(`Failed to parse the AsyncAPI document: ${result.error}`, {
@@ -13,6 +13,7 @@ const fs_1 = require("fs");
13
13
  const parser_1 = require("@asyncapi/parser");
14
14
  const optimize_flags_1 = require("../internal/flags/optimize.flags");
15
15
  const proxy_flags_1 = require("../internal/flags/proxy.flags");
16
+ const proxy_1 = require("../../../utils/proxy");
16
17
  const { writeFile } = fs_1.promises;
17
18
  var Optimizations;
18
19
  (function (Optimizations) {
@@ -41,13 +42,7 @@ class Optimize extends base_1.default {
41
42
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
43
  var _a, _b, _c, _d;
43
44
  const { args, flags } = yield this.parse(Optimize); //NOSONAR
44
- let filePath = args['spec-file'];
45
- const proxyHost = flags['proxyHost'];
46
- const proxyPort = flags['proxyPort'];
47
- if (proxyHost && proxyPort) {
48
- const proxyUrl = `http://${proxyHost}:${proxyPort}`;
49
- filePath = `${filePath}+${proxyUrl}`; // Update filePath with proxyUrl
50
- }
45
+ const filePath = (0, proxy_1.applyProxyToPath)(args['spec-file'], flags['proxyHost'], flags['proxyPort']);
51
46
  try {
52
47
  this.specFile = yield (0, SpecificationFile_1.load)(filePath);
53
48
  }
@@ -95,7 +90,8 @@ class Optimize extends base_1.default {
95
90
  yield this.interactiveRun(report);
96
91
  }
97
92
  try {
98
- const optimizedDocument = optimizer.getOptimizedDocument({
93
+ const fileFormat = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
94
+ let optimizedDocument = optimizer.getOptimizedDocument({
99
95
  rules: {
100
96
  moveDuplicatesToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_DUPLICATES_TO_COMPONENTS),
101
97
  moveAllToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_ALL_TO_COMPONENTS),
@@ -105,8 +101,11 @@ class Optimize extends base_1.default {
105
101
  disableOptimizationFor: {
106
102
  schema: this.disableOptimizations.includes(DisableOptimizations.SCHEMA),
107
103
  },
108
- output: optimizer_1.Output.YAML,
104
+ output: fileFormat === 'json' ? optimizer_1.Output.JSON : optimizer_1.Output.YAML,
109
105
  });
106
+ if (fileFormat === 'json') {
107
+ optimizedDocument = JSON.stringify((JSON.parse(optimizedDocument)), null, 2);
108
+ }
110
109
  this.collectMetricsData(report);
111
110
  const specPath = this.specFile.getFilePath();
112
111
  let newPath = '';
@@ -115,7 +114,7 @@ class Optimize extends base_1.default {
115
114
  newPath = `${specPath.substring(0, pos)}_optimized.${specPath.substring(pos + 1)}`;
116
115
  }
117
116
  else {
118
- newPath = 'optimized-asyncapi.yaml';
117
+ newPath = `optimized-asyncapi.${fileFormat}`;
119
118
  }
120
119
  switch (this.outputMethod) {
121
120
  case Outputs.TERMINAL:
@@ -124,10 +123,10 @@ class Optimize extends base_1.default {
124
123
  break;
125
124
  case Outputs.NEW_FILE:
126
125
  yield writeFile(newPath, optimizedDocument, { encoding: 'utf8' });
127
- this.log(`✅ Success! Your optimized file has been created at ${chalk_1.default.blue({ newPath })}.`);
126
+ this.log(`✅ Success! Your optimized file has been created at ${chalk_1.default.blue(newPath)}.`);
128
127
  break;
129
128
  case Outputs.OVERWRITE:
130
- yield writeFile(specPath !== null && specPath !== void 0 ? specPath : 'asyncapi.yaml', optimizedDocument, {
129
+ yield writeFile(specPath !== null && specPath !== void 0 ? specPath : `asyncapi.${fileFormat}`, optimizedDocument, {
131
130
  encoding: 'utf8',
132
131
  });
133
132
  this.log(`✅ Success! Your original file at ${specPath} has been updated.`);
@@ -26,7 +26,7 @@ class PreviewStudio extends base_1.default {
26
26
  }
27
27
  }
28
28
  this.metricsMetadata.port = previewPort;
29
- yield (0, Preview_1.startPreview)(filePath, flags.base, flags.baseDir, flags.xOrigin, flags.suppressLogs, previewPort, flags.noBrowser);
29
+ (0, Preview_1.startPreview)(filePath, flags.base, flags.baseDir, flags.xOrigin, flags.suppressLogs, previewPort, flags.noBrowser);
30
30
  });
31
31
  }
32
32
  }
@@ -8,6 +8,7 @@ const globals_1 = require("../internal/globals");
8
8
  const validate_flags_1 = require("../internal/flags/validate.flags");
9
9
  const proxy_flags_1 = require("../internal/flags/proxy.flags");
10
10
  const validation_service_1 = require("../../../domains/services/validation.service");
11
+ const proxy_1 = require("../../../utils/proxy");
11
12
  class Validate extends base_1.default {
12
13
  constructor() {
13
14
  super(...arguments);
@@ -17,13 +18,7 @@ class Validate extends base_1.default {
17
18
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
19
  var _a, _b;
19
20
  const { args, flags } = yield this.parse(Validate); //NOSONAR
20
- let filePath = args['spec-file'];
21
- const proxyHost = flags['proxyHost'];
22
- const proxyPort = flags['proxyPort'];
23
- if (proxyHost && proxyPort) {
24
- const proxyUrl = `http://${proxyHost}:${proxyPort}`;
25
- filePath = `${filePath}+${proxyUrl}`; // Update filePath with proxyUrl
26
- }
21
+ const filePath = (0, proxy_1.applyProxyToPath)(args['spec-file'], flags['proxyHost'], flags['proxyPort']);
27
22
  this.specFile = yield (0, SpecificationFile_1.load)(filePath);
28
23
  const watchMode = flags.watch;
29
24
  if (watchMode) {
@@ -17,6 +17,7 @@ const watcher_1 = require("../../../../utils/generate/watcher");
17
17
  const mapBaseUrl_1 = require("../../../../utils/generate/mapBaseUrl");
18
18
  const prompts_2 = require("../../../../utils/generate/prompts");
19
19
  const generator_service_1 = require("../../../../domains/services/generator.service");
20
+ const proxy_1 = require("../../../../utils/proxy");
20
21
  class BaseGeneratorCommand extends base_1.default {
21
22
  constructor() {
22
23
  super(...arguments);
@@ -42,11 +43,8 @@ class BaseGeneratorCommand extends base_1.default {
42
43
  });
43
44
  }
44
45
  applyProxyConfiguration(asyncapi, proxyHost, proxyPort) {
45
- if (proxyHost && proxyPort) {
46
- const proxyUrl = `http://${proxyHost}:${proxyPort}`;
47
- return `${asyncapi}+${proxyUrl}`;
48
- }
49
- return asyncapi;
46
+ var _a;
47
+ return (_a = (0, proxy_1.applyProxyToPath)(asyncapi, proxyHost, proxyPort)) !== null && _a !== void 0 ? _a : asyncapi;
50
48
  }
51
49
  handleWatchMode(asyncapi, template, output, options, genOption, interactive) {
52
50
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -10,7 +10,7 @@ export default abstract class extends Command {
10
10
  init(): Promise<void>;
11
11
  catch(err: Error & {
12
12
  exitCode?: number;
13
- }): Promise<any>;
13
+ }): Promise<void>;
14
14
  recordActionFinished(action: string, metadata?: MetricMetadata, rawDocument?: string): Promise<void>;
15
15
  recordActionInvoked(action: string, metadata?: MetricMetadata): Promise<void>;
16
16
  recordActionMetric(recordFunc: (recorder: Recorder) => Promise<void>): Promise<void>;
@@ -40,14 +40,14 @@ class default_1 extends core_1.Command {
40
40
  });
41
41
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
42
  try {
43
- return yield _super.catch.call(this, err);
43
+ yield _super.catch.call(this, err);
44
44
  }
45
45
  catch (e) {
46
- if (e.message.includes('EEXIT: 0')) {
47
- process.exitCode = 0;
48
- return;
49
- }
50
46
  if (e instanceof Error) {
47
+ if (e.message.includes('EEXIT: 0')) {
48
+ process.exitCode = 0;
49
+ return;
50
+ }
51
51
  this.logToStderr(`${e.name}: ${e.message}`);
52
52
  process.exitCode = 1;
53
53
  }
@@ -114,8 +114,9 @@ class default_1 extends core_1.Command {
114
114
  const stats = yield stat(specFilePath);
115
115
  this.metricsMetadata['file_creation_timestamp'] = stats.birthtimeMs;
116
116
  }
117
- catch (e) {
118
- // If there's an error with the file, we don't handle it here because it's expected to be handled and reported in the 'finally' method of the command.
117
+ catch (_b) {
118
+ // If there's an error with the file, we don't handle it here
119
+ // because it's expected to be handled and reported in the 'finally' method of the command.
119
120
  }
120
121
  });
121
122
  }
@@ -1,29 +1,4 @@
1
1
  export declare const fromTemplateFlags: () => {
2
- 'use-new-generator': {
3
- name: string;
4
- char?: import("@oclif/core/lib/interfaces").AlphabetLowercase | import("@oclif/core/lib/interfaces").AlphabetUppercase;
5
- summary?: string;
6
- description: string;
7
- helpLabel?: string;
8
- helpGroup?: string;
9
- env?: string;
10
- hidden?: boolean;
11
- required?: boolean;
12
- dependsOn?: string[];
13
- exclusive?: string[];
14
- exactlyOne?: string[];
15
- relationships?: import("@oclif/core/lib/interfaces/parser").Relationship[];
16
- deprecated?: true | import("@oclif/core/lib/interfaces").Deprecation;
17
- aliases?: string[];
18
- charAliases?: (import("@oclif/core/lib/interfaces").AlphabetLowercase | import("@oclif/core/lib/interfaces").AlphabetUppercase)[];
19
- deprecateAliases?: boolean;
20
- noCacheDefault?: boolean;
21
- atLeastOne?: string[];
22
- type: "boolean";
23
- allowNo: boolean;
24
- default: import("@oclif/core/lib/interfaces/parser").FlagDefault<boolean>;
25
- parse: (input: boolean, context: import("@oclif/core/lib/interfaces/parser").FlagParserContext, opts: import("@oclif/core/lib/interfaces/parser").FlagProps & import("@oclif/core/lib/interfaces/parser").BooleanFlagProps) => Promise<boolean>;
26
- };
27
2
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
28
3
  'disable-hook': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
29
4
  'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -2,8 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fromTemplateFlags = void 0;
4
4
  const sharedFlags_1 = require("./sharedFlags");
5
- const core_1 = require("@oclif/core");
6
5
  const fromTemplateFlags = () => {
7
- return Object.assign(Object.assign({}, sharedFlags_1.sharedFlags), { 'use-new-generator': Object.assign({ default: false, description: 'Use v2 generator, for generating from newer templates' }, core_1.Flags.boolean()) });
6
+ return Object.assign({}, sharedFlags_1.sharedFlags);
8
7
  };
9
8
  exports.fromTemplateFlags = fromTemplateFlags;
@@ -4,6 +4,7 @@ exports.specWatcher = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const error_handler_1 = require("../../../utils/error-handler");
7
8
  const GreenLog = chalk_1.default.hex('#00FF00');
8
9
  const OrangeLog = chalk_1.default.hex('#FFA500');
9
10
  const CHOKIDAR_CONFIG = {
@@ -40,7 +41,7 @@ const specWatcher = (params) => {
40
41
  CHOKIDAR_INSTANCE_STORE.set(params.label || '_default', true);
41
42
  }
42
43
  catch (error) {
43
- console.log(error);
44
+ console.error(chalk_1.default.red(`Watch error: ${(0, error_handler_1.getErrorMessage)(error)}`));
44
45
  }
45
46
  };
46
47
  exports.specWatcher = specWatcher;
@@ -295,7 +295,9 @@ function getContextFilePath() {
295
295
  return exports.CONTEXT_FILE_PATH;
296
296
  }
297
297
  }
298
- catch (e) { } // eslint-disable-line
298
+ catch (_a) {
299
+ // Silently continue to parent directory if file doesn't exist or is invalid JSON
300
+ }
299
301
  currentPath.pop();
300
302
  }
301
303
  return null;
@@ -10,7 +10,6 @@ const http_1 = require("http");
10
10
  const ws_1 = require("ws");
11
11
  const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
12
12
  const open_1 = tslib_1.__importDefault(require("open"));
13
- const next_1 = tslib_1.__importDefault(require("next"));
14
13
  const path_1 = tslib_1.__importDefault(require("path"));
15
14
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
16
15
  const picocolors_1 = require("picocolors");
@@ -24,6 +23,13 @@ exports.DEFAULT_PORT = 0;
24
23
  function isValidFilePath(filePath) {
25
24
  return (0, fs_1.existsSync)(filePath);
26
25
  }
26
+ function resolveStudioNextInstance(studioPath) {
27
+ var _a;
28
+ const resolvedNextPath = require.resolve('next', { paths: [studioPath] });
29
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require
30
+ const nextModule = require(resolvedNextPath);
31
+ return (_a = nextModule.default) !== null && _a !== void 0 ? _a : nextModule;
32
+ }
27
33
  // eslint-disable-next-line sonarjs/cognitive-complexity
28
34
  function startPreview(filePath, base, baseDirectory, xOrigin, suppressLogs, port = exports.DEFAULT_PORT, noBrowser) {
29
35
  if (filePath && !isValidFilePath(filePath)) {
@@ -43,7 +49,8 @@ function startPreview(filePath, base, baseDirectory, xOrigin, suppressLogs, port
43
49
  }
44
50
  });
45
51
  const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
46
- const app = (0, next_1.default)({
52
+ const nextInstance = resolveStudioNextInstance(studioPath);
53
+ const app = nextInstance({
47
54
  dev: false,
48
55
  dir: studioPath,
49
56
  conf: {
@@ -35,6 +35,18 @@ export declare function nameType(name: string): Promise<string>;
35
35
  export declare function isURL(urlpath: string): Promise<boolean>;
36
36
  export declare function fileExists(name: string): Promise<boolean>;
37
37
  export declare function retrieveFileFormat(content: string): fileFormat | undefined;
38
+ /**
39
+ * Converts a JSON or YAML specification to YAML format.
40
+ *
41
+ * @param spec - The specification content as a string
42
+ * @returns The YAML formatted string, or undefined if conversion fails
43
+ */
38
44
  export declare function convertToYaml(spec: string): string | undefined;
45
+ /**
46
+ * Converts a JSON or YAML specification to JSON format.
47
+ *
48
+ * @param spec - The specification content as a string
49
+ * @returns The JSON formatted string, or undefined if conversion fails
50
+ */
39
51
  export declare function convertToJSON(spec: string): string | undefined;
40
52
  export {};