@asyncapi/cli 3.0.1 → 3.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.
@@ -451,11 +451,13 @@
451
451
  }
452
452
  },
453
453
  "node_modules/@babel/code-frame": {
454
- "version": "7.24.7",
455
- "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz",
456
- "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==",
454
+ "version": "7.26.2",
455
+ "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz",
456
+ "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==",
457
+ "license": "MIT",
457
458
  "dependencies": {
458
- "@babel/highlight": "^7.24.7",
459
+ "@babel/helper-validator-identifier": "^7.25.9",
460
+ "js-tokens": "^4.0.0",
459
461
  "picocolors": "^1.0.0"
460
462
  },
461
463
  "engines": {
@@ -753,17 +755,19 @@
753
755
  }
754
756
  },
755
757
  "node_modules/@babel/helper-string-parser": {
756
- "version": "7.24.8",
757
- "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz",
758
- "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==",
758
+ "version": "7.25.9",
759
+ "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz",
760
+ "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==",
761
+ "license": "MIT",
759
762
  "engines": {
760
763
  "node": ">=6.9.0"
761
764
  }
762
765
  },
763
766
  "node_modules/@babel/helper-validator-identifier": {
764
- "version": "7.24.7",
765
- "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz",
766
- "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==",
767
+ "version": "7.25.9",
768
+ "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz",
769
+ "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==",
770
+ "license": "MIT",
767
771
  "engines": {
768
772
  "node": ">=6.9.0"
769
773
  }
@@ -790,101 +794,25 @@
790
794
  }
791
795
  },
792
796
  "node_modules/@babel/helpers": {
793
- "version": "7.25.6",
794
- "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.25.6.tgz",
795
- "integrity": "sha512-Xg0tn4HcfTijTwfDwYlvVCl43V6h4KyVVX2aEm4qdO/PC6L2YvzLHFdmxhoeSA3eslcE6+ZVXHgWwopXYLNq4Q==",
796
- "dependencies": {
797
- "@babel/template": "^7.25.0",
798
- "@babel/types": "^7.25.6"
799
- },
800
- "engines": {
801
- "node": ">=6.9.0"
802
- }
803
- },
804
- "node_modules/@babel/highlight": {
805
- "version": "7.24.7",
806
- "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz",
807
- "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==",
797
+ "version": "7.26.10",
798
+ "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.26.10.tgz",
799
+ "integrity": "sha512-UPYc3SauzZ3JGgj87GgZ89JVdC5dj0AoetR5Bw6wj4niittNyFh6+eOGonYvJ1ao6B8lEa3Q3klS7ADZ53bc5g==",
800
+ "license": "MIT",
808
801
  "dependencies": {
809
- "@babel/helper-validator-identifier": "^7.24.7",
810
- "chalk": "^2.4.2",
811
- "js-tokens": "^4.0.0",
812
- "picocolors": "^1.0.0"
802
+ "@babel/template": "^7.26.9",
803
+ "@babel/types": "^7.26.10"
813
804
  },
814
805
  "engines": {
815
806
  "node": ">=6.9.0"
816
807
  }
817
808
  },
818
- "node_modules/@babel/highlight/node_modules/ansi-styles": {
819
- "version": "3.2.1",
820
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
821
- "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
822
- "dependencies": {
823
- "color-convert": "^1.9.0"
824
- },
825
- "engines": {
826
- "node": ">=4"
827
- }
828
- },
829
- "node_modules/@babel/highlight/node_modules/chalk": {
830
- "version": "2.4.2",
831
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
832
- "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
833
- "dependencies": {
834
- "ansi-styles": "^3.2.1",
835
- "escape-string-regexp": "^1.0.5",
836
- "supports-color": "^5.3.0"
837
- },
838
- "engines": {
839
- "node": ">=4"
840
- }
841
- },
842
- "node_modules/@babel/highlight/node_modules/color-convert": {
843
- "version": "1.9.3",
844
- "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
845
- "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
846
- "dependencies": {
847
- "color-name": "1.1.3"
848
- }
849
- },
850
- "node_modules/@babel/highlight/node_modules/color-name": {
851
- "version": "1.1.3",
852
- "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
853
- "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw=="
854
- },
855
- "node_modules/@babel/highlight/node_modules/escape-string-regexp": {
856
- "version": "1.0.5",
857
- "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
858
- "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
859
- "engines": {
860
- "node": ">=0.8.0"
861
- }
862
- },
863
- "node_modules/@babel/highlight/node_modules/has-flag": {
864
- "version": "3.0.0",
865
- "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
866
- "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
867
- "engines": {
868
- "node": ">=4"
869
- }
870
- },
871
- "node_modules/@babel/highlight/node_modules/supports-color": {
872
- "version": "5.5.0",
873
- "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
874
- "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
875
- "dependencies": {
876
- "has-flag": "^3.0.0"
877
- },
878
- "engines": {
879
- "node": ">=4"
880
- }
881
- },
882
809
  "node_modules/@babel/parser": {
883
- "version": "7.25.6",
884
- "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.6.tgz",
885
- "integrity": "sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q==",
810
+ "version": "7.26.10",
811
+ "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.10.tgz",
812
+ "integrity": "sha512-6aQR2zGE/QFi8JpDLjUZEPYOs7+mhKXm86VaKFiLP35JQwQb6bwUE+XbvkH0EptsYhbNBSUGaUBLKqxH1xSgsA==",
813
+ "license": "MIT",
886
814
  "dependencies": {
887
- "@babel/types": "^7.25.6"
815
+ "@babel/types": "^7.26.10"
888
816
  },
889
817
  "bin": {
890
818
  "parser": "bin/babel-parser.js"
@@ -2160,13 +2088,14 @@
2160
2088
  }
2161
2089
  },
2162
2090
  "node_modules/@babel/template": {
2163
- "version": "7.25.0",
2164
- "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz",
2165
- "integrity": "sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==",
2091
+ "version": "7.26.9",
2092
+ "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.26.9.tgz",
2093
+ "integrity": "sha512-qyRplbeIpNZhmzOysF/wFMuP9sctmh2cFzRAZOn1YapxBsE1i9bJIY586R/WBLfLcmcBlM8ROBiQURnnNy+zfA==",
2094
+ "license": "MIT",
2166
2095
  "dependencies": {
2167
- "@babel/code-frame": "^7.24.7",
2168
- "@babel/parser": "^7.25.0",
2169
- "@babel/types": "^7.25.0"
2096
+ "@babel/code-frame": "^7.26.2",
2097
+ "@babel/parser": "^7.26.9",
2098
+ "@babel/types": "^7.26.9"
2170
2099
  },
2171
2100
  "engines": {
2172
2101
  "node": ">=6.9.0"
@@ -2190,13 +2119,13 @@
2190
2119
  }
2191
2120
  },
2192
2121
  "node_modules/@babel/types": {
2193
- "version": "7.25.6",
2194
- "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.6.tgz",
2195
- "integrity": "sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw==",
2122
+ "version": "7.26.10",
2123
+ "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.10.tgz",
2124
+ "integrity": "sha512-emqcG3vHrpxUKTrxcblR36dcrcoRDvKmnL/dCL6ZsHaShW80qxCAcNhzQZrpeM765VzEos+xOi4s+r4IXzTwdQ==",
2125
+ "license": "MIT",
2196
2126
  "dependencies": {
2197
- "@babel/helper-string-parser": "^7.24.8",
2198
- "@babel/helper-validator-identifier": "^7.24.7",
2199
- "to-fast-properties": "^2.0.0"
2127
+ "@babel/helper-string-parser": "^7.25.9",
2128
+ "@babel/helper-validator-identifier": "^7.25.9"
2200
2129
  },
2201
2130
  "engines": {
2202
2131
  "node": ">=6.9.0"
@@ -12340,14 +12269,6 @@
12340
12269
  "resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.6.0.tgz",
12341
12270
  "integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw=="
12342
12271
  },
12343
- "node_modules/to-fast-properties": {
12344
- "version": "2.0.0",
12345
- "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
12346
- "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
12347
- "engines": {
12348
- "node": ">=4"
12349
- }
12350
- },
12351
12272
  "node_modules/to-regex-range": {
12352
12273
  "version": "5.0.1",
12353
12274
  "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@@ -0,0 +1,16 @@
1
+ import Command from '../../core/base';
2
+ export default class PreviewStudio extends Command {
3
+ static readonly description = "starts a new local instance of Studio in minimal state bundling all the refs of the schema file and with no editing allowed.";
4
+ static readonly flags: {
5
+ help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
6
+ port: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
7
+ base: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ baseDir: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
+ xOrigin: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ suppressLogs: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ static readonly args: {
13
+ 'spec-file': import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
14
+ };
15
+ run(): Promise<void>;
16
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const base_1 = tslib_1.__importDefault(require("../../core/base"));
6
+ const preview_flags_1 = require("../../core/flags/start/preview.flags");
7
+ const SpecificationFile_1 = require("../../core/models/SpecificationFile");
8
+ const Preview_1 = require("../../core/models/Preview");
9
+ class PreviewStudio extends base_1.default {
10
+ run() {
11
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
+ var _a;
13
+ const { args, flags } = yield this.parse(PreviewStudio);
14
+ let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
15
+ const previewPort = flags.port;
16
+ if (!filePath) {
17
+ filePath = ((yield (0, SpecificationFile_1.load)()).getFilePath());
18
+ this.log(`Loaded the specification from: ${filePath}`);
19
+ }
20
+ try {
21
+ this.specFile = yield (0, SpecificationFile_1.load)(filePath);
22
+ }
23
+ catch (error) {
24
+ if (filePath) {
25
+ this.error(error);
26
+ }
27
+ }
28
+ this.metricsMetadata.port = previewPort;
29
+ (0, Preview_1.startPreview)(filePath, flags.base, flags.baseDir, flags.xOrigin, flags.suppressLogs, previewPort);
30
+ });
31
+ }
32
+ }
33
+ PreviewStudio.description = 'starts a new local instance of Studio in minimal state bundling all the refs of the schema file and with no editing allowed.';
34
+ PreviewStudio.flags = (0, preview_flags_1.previewFlags)();
35
+ PreviewStudio.args = {
36
+ 'spec-file': core_1.Args.string({ description: 'the path to the file to be opened with studio or context name', required: true }),
37
+ };
38
+ exports.default = PreviewStudio;
@@ -5,9 +5,11 @@ export default class StartStudio extends Command {
5
5
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
6
6
  file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
7
7
  port: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ 'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
9
  };
9
10
  static readonly args: {
10
11
  'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
11
12
  };
12
13
  run(): Promise<void>;
14
+ private parseArgs;
13
15
  }
@@ -6,16 +6,23 @@ const Studio_1 = require("../../core/models/Studio");
6
6
  const SpecificationFile_1 = require("../../core/models/SpecificationFile");
7
7
  const studio_flags_1 = require("../../core/flags/start/studio.flags");
8
8
  const core_1 = require("@oclif/core");
9
+ const prompts_1 = require("@clack/prompts");
9
10
  class StartStudio extends base_1.default {
10
11
  run() {
11
12
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
13
  var _a;
13
14
  const { args, flags } = yield this.parse(StartStudio);
15
+ let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
16
+ let port = flags.port;
14
17
  if (flags.file) {
15
18
  this.warn('The file flag has been removed and is being replaced by the argument spec-file. Please pass the filename directly like `asyncapi start studio asyncapi.yml`');
16
19
  }
17
- let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
18
- const port = flags.port;
20
+ const isInteractive = !flags['no-interactive'];
21
+ if (isInteractive && !filePath) {
22
+ const parsedArgs = yield this.parseArgs({ filePath }, port === null || port === void 0 ? void 0 : port.toString());
23
+ filePath = parsedArgs.filePath;
24
+ port = parseInt(parsedArgs.port, 10);
25
+ }
19
26
  if (!filePath) {
20
27
  try {
21
28
  filePath = ((yield (0, SpecificationFile_1.load)()).getFilePath());
@@ -38,6 +45,43 @@ class StartStudio extends base_1.default {
38
45
  (0, Studio_1.start)(filePath, port);
39
46
  });
40
47
  }
48
+ parseArgs(args, port) {
49
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
50
+ const operationCancelled = 'Operation cancelled by the user.';
51
+ let askForPort = false;
52
+ let { filePath } = args;
53
+ if (!filePath) {
54
+ filePath = yield (0, prompts_1.text)({
55
+ message: 'Enter the path to the AsyncAPI document',
56
+ defaultValue: 'asyncapi.yaml',
57
+ placeholder: 'asyncapi.yaml',
58
+ validate: (value) => {
59
+ if (!value) {
60
+ return 'The path to the AsyncAPI document is required';
61
+ }
62
+ },
63
+ });
64
+ askForPort = true;
65
+ }
66
+ if ((0, prompts_1.isCancel)(filePath)) {
67
+ (0, prompts_1.cancel)(operationCancelled);
68
+ this.exit();
69
+ }
70
+ if (!port && askForPort) {
71
+ port = (yield (0, prompts_1.text)({
72
+ message: 'Enter the port in which to start Studio',
73
+ defaultValue: '3210',
74
+ placeholder: '3210',
75
+ validate: (value) => (!value ? 'The port number is required' : undefined),
76
+ }));
77
+ }
78
+ if ((0, prompts_1.isCancel)(port)) {
79
+ (0, prompts_1.cancel)(operationCancelled);
80
+ this.exit();
81
+ }
82
+ return { filePath, port: port !== null && port !== void 0 ? port : '3210' };
83
+ });
84
+ }
41
85
  }
42
86
  StartStudio.description = 'starts a new local instance of Studio';
43
87
  StartStudio.flags = (0, studio_flags_1.studioFlags)();
@@ -0,0 +1,8 @@
1
+ export declare const previewFlags: () => {
2
+ help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
3
+ port: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
4
+ base: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
5
+ baseDir: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
6
+ xOrigin: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
+ suppressLogs: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.previewFlags = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ const previewFlags = () => {
6
+ return {
7
+ help: core_1.Flags.help({ char: 'h' }),
8
+ port: core_1.Flags.integer({ char: 'p', description: 'port in which to start Studio in the preview mode' }),
9
+ base: core_1.Flags.string({ char: 'b', description: 'Path to the file which will act as a base. This is required when some properties need to be overwritten while bundling with the file.' }),
10
+ baseDir: core_1.Flags.string({ char: 'd', description: 'One relative/absolute path to directory relative to which paths to AsyncAPI Documents that should be bundled will be resolved.' }),
11
+ xOrigin: core_1.Flags.boolean({ char: 'x', description: 'Pass this switch to generate properties "x-origin" that will contain historical values of dereferenced "$ref"s.' }),
12
+ suppressLogs: core_1.Flags.boolean({ char: 'l', description: 'Pass this to suppress the detiled error logs.', default: false })
13
+ };
14
+ };
15
+ exports.previewFlags = previewFlags;
@@ -2,4 +2,5 @@ export declare const studioFlags: () => {
2
2
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
3
3
  file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
4
4
  port: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
5
+ 'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
5
6
  };
@@ -7,6 +7,11 @@ const studioFlags = () => {
7
7
  help: core_1.Flags.help({ char: 'h' }),
8
8
  file: core_1.Flags.string({ char: 'f', description: 'path to the AsyncAPI file to link with Studio', deprecated: true }),
9
9
  port: core_1.Flags.integer({ char: 'p', description: 'port in which to start Studio' }),
10
+ 'no-interactive': core_1.Flags.boolean({
11
+ description: 'disable prompts for this command which asks for file path if not passed via the arguments.',
12
+ required: false,
13
+ default: false,
14
+ }),
10
15
  };
11
16
  };
12
17
  exports.studioFlags = studioFlags;
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_PORT = 3210;
2
+ export declare function startPreview(filePath: string, base: string | undefined, baseDirectory: string | undefined, xOrigin: boolean | undefined, suppressLogs: boolean | undefined, port?: number): void;
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_PORT = void 0;
4
+ exports.startPreview = startPreview;
5
+ const tslib_1 = require("tslib");
6
+ const specification_file_1 = require("../errors/specification-file");
7
+ const fs_1 = require("fs");
8
+ const bundler_1 = tslib_1.__importDefault(require("@asyncapi/bundler"));
9
+ const http_1 = require("http");
10
+ const ws_1 = require("ws");
11
+ const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
12
+ const open_1 = tslib_1.__importDefault(require("open"));
13
+ const next_1 = tslib_1.__importDefault(require("next"));
14
+ const path_1 = tslib_1.__importDefault(require("path"));
15
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
16
+ const picocolors_1 = require("picocolors");
17
+ const package_json_1 = require("@asyncapi/studio/package.json");
18
+ const sockets = [];
19
+ const messageQueue = [];
20
+ const filePathsToWatch = new Set();
21
+ const defaultErrorMessage = 'error occured while bundling files. use --detailedLog or -l flag to get more details.';
22
+ let bundleError = true;
23
+ exports.DEFAULT_PORT = 3210;
24
+ function isValidFilePath(filePath) {
25
+ return (0, fs_1.existsSync)(filePath);
26
+ }
27
+ // eslint-disable-next-line sonarjs/cognitive-complexity
28
+ function startPreview(filePath, base, baseDirectory, xOrigin, suppressLogs, port = exports.DEFAULT_PORT) {
29
+ if (filePath && !isValidFilePath(filePath)) {
30
+ throw new specification_file_1.SpecificationFileNotFound(filePath);
31
+ }
32
+ const baseDir = path_1.default.dirname(path_1.default.resolve(filePath));
33
+ (0, bundler_1.default)(filePath).then((doc) => {
34
+ if (doc) {
35
+ bundleError = false;
36
+ }
37
+ }).catch((err) => {
38
+ if (suppressLogs) {
39
+ console.log(defaultErrorMessage);
40
+ }
41
+ else {
42
+ console.log(err);
43
+ }
44
+ });
45
+ const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
46
+ const app = (0, next_1.default)({
47
+ dev: false,
48
+ dir: studioPath,
49
+ conf: {
50
+ distDir: 'build',
51
+ },
52
+ });
53
+ const handle = app.getRequestHandler();
54
+ const wsServer = new ws_1.WebSocketServer({ noServer: true });
55
+ wsServer.on('connection', (socket) => {
56
+ sockets.push(socket);
57
+ sendQueuedMessages();
58
+ });
59
+ wsServer.on('close', (socket) => {
60
+ sockets.splice(sockets.findIndex(s => s === socket));
61
+ });
62
+ app.prepare().then(() => {
63
+ if (filePath && !bundleError) {
64
+ messageQueue.push(JSON.stringify({
65
+ type: 'preview:connected',
66
+ code: 'Preview server connected'
67
+ }));
68
+ sendQueuedMessages();
69
+ findPathsToWatchFromSchemaRef(filePath, baseDir);
70
+ filePathsToWatch.add(path_1.default.resolve(baseDir, filePath));
71
+ chokidar_1.default.watch([...filePathsToWatch]).on('all', (event) => {
72
+ switch (event) {
73
+ case 'add':
74
+ (0, bundler_1.default)([filePath], {
75
+ base,
76
+ baseDir: baseDirectory,
77
+ xOrigin,
78
+ }).then((intitalDocument) => {
79
+ messageQueue.push(JSON.stringify({
80
+ type: 'preview:file:added',
81
+ code: (path_1.default.extname(filePath) === '.yaml' || path_1.default.extname(filePath) === '.yml') ?
82
+ intitalDocument.yml() : intitalDocument.string()
83
+ }));
84
+ sendQueuedMessages();
85
+ }).catch((e) => {
86
+ if (suppressLogs) {
87
+ console.log(defaultErrorMessage);
88
+ }
89
+ else {
90
+ console.log(e);
91
+ }
92
+ });
93
+ break;
94
+ case 'change':
95
+ (0, bundler_1.default)([filePath], {
96
+ base,
97
+ baseDir: baseDirectory,
98
+ xOrigin,
99
+ }).then((modifiedDocument) => {
100
+ messageQueue.push(JSON.stringify({
101
+ type: 'preview:file:changed',
102
+ code: (path_1.default.extname(filePath) === '.yaml' || path_1.default.extname(filePath) === '.yml') ?
103
+ modifiedDocument.yml() : modifiedDocument.string()
104
+ }));
105
+ sendQueuedMessages();
106
+ }).catch((error) => {
107
+ if (suppressLogs) {
108
+ console.log(defaultErrorMessage);
109
+ }
110
+ else {
111
+ console.log(error);
112
+ }
113
+ });
114
+ break;
115
+ case 'unlink':
116
+ messageQueue.push(JSON.stringify({
117
+ type: 'preview:file:deleted',
118
+ filePath,
119
+ }));
120
+ sendQueuedMessages();
121
+ break;
122
+ }
123
+ });
124
+ }
125
+ const server = (0, http_1.createServer)((req, res) => handle(req, res));
126
+ server.on('upgrade', (request, socket, head) => {
127
+ if (request.url === '/preview-server' && request.headers['origin'] === `http://localhost:${port}`) {
128
+ console.log('🔗 WebSocket connection established for the preview.');
129
+ wsServer.handleUpgrade(request, socket, head, (sock) => {
130
+ wsServer.emit('connection', sock, request);
131
+ });
132
+ }
133
+ else {
134
+ console.log('🔗 WebSocket connection not established.');
135
+ socket.destroy();
136
+ }
137
+ });
138
+ if (!bundleError) {
139
+ server.listen(port, () => {
140
+ const url = `http://localhost:${port}?previewServer=${port}&studio-version=${package_json_1.version}`;
141
+ console.log(`🎉 Connected to Preview Server running at ${(0, picocolors_1.blueBright)(url)}.`);
142
+ console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
143
+ console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the server.`);
144
+ if (filePath) {
145
+ for (const entry of filePathsToWatch) {
146
+ console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(entry)}`);
147
+ }
148
+ }
149
+ else {
150
+ console.warn('Warning: No file was provided, and we couldn\'t find a default file (like "asyncapi.yaml" or "asyncapi.json") in the current folder. Starting Studio with a blank workspace.');
151
+ }
152
+ if (!bundleError) {
153
+ (0, open_1.default)(url);
154
+ }
155
+ }).on('error', (error) => {
156
+ console.error(`Failed to start server on port ${port}:`, error.message);
157
+ });
158
+ }
159
+ });
160
+ }
161
+ function sendQueuedMessages() {
162
+ while (messageQueue.length && sockets.length) {
163
+ const nextMessage = messageQueue.shift();
164
+ for (const socket of sockets) {
165
+ socket.send(nextMessage);
166
+ }
167
+ }
168
+ }
169
+ function isLocalRefAPath(key, value) {
170
+ return (typeof value === 'string' && key === '$ref' &&
171
+ (value.startsWith('.') || value.startsWith('./') ||
172
+ value.startsWith('../') || !value.startsWith('#')));
173
+ }
174
+ function findPathsToWatchFromSchemaRef(filePath, baseDir) {
175
+ if (filePath && !isValidFilePath(filePath)) {
176
+ throw new specification_file_1.SpecificationFileNotFound(filePath);
177
+ }
178
+ const document = js_yaml_1.default.load((0, fs_1.readFileSync)(filePath, 'utf-8'));
179
+ const stack = [document];
180
+ while (stack.length > 0) {
181
+ const current = stack.pop();
182
+ if (current === null || typeof current !== 'object') {
183
+ continue;
184
+ }
185
+ for (const [key, value] of Object.entries(current)) {
186
+ if (isLocalRefAPath(key, value)) {
187
+ const absolutePath = path_1.default.resolve(baseDir, value);
188
+ filePathsToWatch.add(absolutePath);
189
+ }
190
+ if (value !== null && typeof value === 'object') {
191
+ stack.push(value);
192
+ }
193
+ }
194
+ }
195
+ }
@@ -1451,6 +1451,78 @@
1451
1451
  "index.js"
1452
1452
  ]
1453
1453
  },
1454
+ "start:preview": {
1455
+ "aliases": [],
1456
+ "args": {
1457
+ "spec-file": {
1458
+ "description": "the path to the file to be opened with studio or context name",
1459
+ "name": "spec-file",
1460
+ "required": true
1461
+ }
1462
+ },
1463
+ "description": "starts a new local instance of Studio in minimal state bundling all the refs of the schema file and with no editing allowed.",
1464
+ "flags": {
1465
+ "help": {
1466
+ "char": "h",
1467
+ "description": "Show CLI help.",
1468
+ "name": "help",
1469
+ "allowNo": false,
1470
+ "type": "boolean"
1471
+ },
1472
+ "port": {
1473
+ "char": "p",
1474
+ "description": "port in which to start Studio in the preview mode",
1475
+ "name": "port",
1476
+ "hasDynamicHelp": false,
1477
+ "multiple": false,
1478
+ "type": "option"
1479
+ },
1480
+ "base": {
1481
+ "char": "b",
1482
+ "description": "Path to the file which will act as a base. This is required when some properties need to be overwritten while bundling with the file.",
1483
+ "name": "base",
1484
+ "hasDynamicHelp": false,
1485
+ "multiple": false,
1486
+ "type": "option"
1487
+ },
1488
+ "baseDir": {
1489
+ "char": "d",
1490
+ "description": "One relative/absolute path to directory relative to which paths to AsyncAPI Documents that should be bundled will be resolved.",
1491
+ "name": "baseDir",
1492
+ "hasDynamicHelp": false,
1493
+ "multiple": false,
1494
+ "type": "option"
1495
+ },
1496
+ "xOrigin": {
1497
+ "char": "x",
1498
+ "description": "Pass this switch to generate properties \"x-origin\" that will contain historical values of dereferenced \"$ref\"s.",
1499
+ "name": "xOrigin",
1500
+ "allowNo": false,
1501
+ "type": "boolean"
1502
+ },
1503
+ "suppressLogs": {
1504
+ "char": "l",
1505
+ "description": "Pass this to suppress the detiled error logs.",
1506
+ "name": "suppressLogs",
1507
+ "allowNo": false,
1508
+ "type": "boolean"
1509
+ }
1510
+ },
1511
+ "hasDynamicHelp": false,
1512
+ "hiddenAliases": [],
1513
+ "id": "start:preview",
1514
+ "pluginAlias": "@asyncapi/cli",
1515
+ "pluginName": "@asyncapi/cli",
1516
+ "pluginType": "core",
1517
+ "strict": true,
1518
+ "isESM": false,
1519
+ "relativePath": [
1520
+ "lib",
1521
+ "commands",
1522
+ "start",
1523
+ "preview.js"
1524
+ ]
1525
+ },
1454
1526
  "start:studio": {
1455
1527
  "aliases": [],
1456
1528
  "args": {
@@ -1485,6 +1557,13 @@
1485
1557
  "hasDynamicHelp": false,
1486
1558
  "multiple": false,
1487
1559
  "type": "option"
1560
+ },
1561
+ "no-interactive": {
1562
+ "description": "disable prompts for this command which asks for file path if not passed via the arguments.",
1563
+ "name": "no-interactive",
1564
+ "required": false,
1565
+ "allowNo": false,
1566
+ "type": "boolean"
1488
1567
  }
1489
1568
  },
1490
1569
  "hasDynamicHelp": false,
@@ -1776,5 +1855,5 @@
1776
1855
  ]
1777
1856
  }
1778
1857
  },
1779
- "version": "3.0.1"
1858
+ "version": "3.1.1"
1780
1859
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@asyncapi/cli",
3
3
  "description": "All in one CLI for all AsyncAPI tools",
4
- "version": "3.0.1",
4
+ "version": "3.1.1",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"
@@ -19,7 +19,7 @@
19
19
  "@asyncapi/parser": "^3.3.0",
20
20
  "@asyncapi/protobuf-schema-parser": "^3.5.1",
21
21
  "@asyncapi/raml-dt-schema-parser": "^4.0.24",
22
- "@asyncapi/studio": "^0.23.1",
22
+ "@asyncapi/studio": "^0.24.2",
23
23
  "@changesets/changelog-git": "^0.2.0",
24
24
  "@clack/prompts": "^0.7.0",
25
25
  "@oclif/core": "^4.2.9",