@asyncapi/cli 2.14.1 → 2.16.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.
@@ -4,6 +4,8 @@ export default class Convert extends Command {
4
4
  static metricsMetadata: any;
5
5
  static description: string;
6
6
  static flags: {
7
+ proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
7
9
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
8
10
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
11
  format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -12,6 +14,8 @@ export default class Convert extends Command {
12
14
  };
13
15
  static args: {
14
16
  'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
17
+ proxyHost: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
18
+ proxyPort: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
15
19
  };
16
20
  run(): Promise<void>;
17
21
  private handleConversion;
@@ -10,6 +10,7 @@ const SpecificationFile_1 = require("../core/models/SpecificationFile");
10
10
  const specification_file_1 = require("../core/errors/specification-file");
11
11
  const converter_1 = require("@asyncapi/converter");
12
12
  const picocolors_1 = require("picocolors");
13
+ const proxy_flags_1 = require("../core/flags/proxy.flags");
13
14
  // @ts-ignore
14
15
  const specs_1 = tslib_1.__importDefault(require("@asyncapi/specs"));
15
16
  const convert_flags_1 = require("../core/flags/convert.flags");
@@ -18,7 +19,13 @@ class Convert extends base_1.default {
18
19
  run() {
19
20
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
20
21
  const { args, flags } = yield this.parse(Convert);
21
- const filePath = args['spec-file'];
22
+ let filePath = args['spec-file'];
23
+ const proxyHost = flags['proxyHost'];
24
+ const proxyPort = flags['proxyPort'];
25
+ if (proxyHost && proxyPort) {
26
+ const proxyUrl = `http://${proxyHost}:${proxyPort}`;
27
+ filePath = `${filePath}+${proxyUrl}`; // Update filePath with proxyUrl
28
+ }
22
29
  let convertedFile;
23
30
  let convertedFileFormatted;
24
31
  try {
@@ -119,7 +126,9 @@ class Convert extends base_1.default {
119
126
  exports.default = Convert;
120
127
  Convert.metricsMetadata = {};
121
128
  Convert.description = 'Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI';
122
- Convert.flags = (0, convert_flags_1.convertFlags)(latestVersion);
129
+ Convert.flags = Object.assign(Object.assign({}, (0, convert_flags_1.convertFlags)(latestVersion)), (0, proxy_flags_1.proxyFlags)());
123
130
  Convert.args = {
124
131
  'spec-file': core_1.Args.string({ description: 'spec path, url, or context-name', required: false }),
132
+ proxyHost: core_1.Args.string({ description: 'Name of the Proxy Host', required: false }),
133
+ proxyPort: core_1.Args.string({ description: 'Name of the Port of the ProxyHost', required: false }),
125
134
  };
@@ -116,7 +116,7 @@ class Template extends base_1.default {
116
116
  }
117
117
  }
118
118
  if (flags['use-new-generator']) {
119
- yield this.generateUsingNewGenerator(asyncapi, template, output, options, genOption, interactive);
119
+ yield this.generateUsingNewGenerator(asyncapi, template, output, options, genOption);
120
120
  }
121
121
  else {
122
122
  yield this.generate(asyncapi, template, output, options, genOption, interactive);
@@ -287,7 +287,7 @@ class Template extends base_1.default {
287
287
  s.stop(`${(0, picocolors_1.yellow)('Check out your shiny new generated files at ') + (0, picocolors_1.magenta)(output) + (0, picocolors_1.yellow)('.')}\n`);
288
288
  });
289
289
  }
290
- generateUsingNewGenerator(asyncapi, template, output, options, genOption, interactive = true) {
290
+ generateUsingNewGenerator(asyncapi, template, output, options, genOption) {
291
291
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
292
292
  let specification;
293
293
  try {
@@ -300,16 +300,15 @@ class Template extends base_1.default {
300
300
  }), { exit: 1 });
301
301
  }
302
302
  const generator = new generator_v2_1.default(template, output || path_1.default.resolve(os_1.default.tmpdir(), 'asyncapi-generator'), options);
303
- const s = interactive ? (0, prompts_1.spinner)() : { start: () => null, stop: (string) => console.log(string) };
304
- s.start('Generation in progress. Keep calm and wait a bit');
303
+ this.log('Generation in progress. Keep calm and wait a bit');
305
304
  try {
306
305
  yield generator.generateFromString(specification.text(), Object.assign(Object.assign({}, genOption), { path: asyncapi }));
307
306
  }
308
307
  catch (err) {
309
- s.stop('Generation failed');
308
+ this.log('Generation failed');
310
309
  throw new generator_error_1.GeneratorError(err);
311
310
  }
312
- s.stop(`${(0, picocolors_1.yellow)('Check out your shiny new generated files at ') + (0, picocolors_1.magenta)(output) + (0, picocolors_1.yellow)('.')}\n`);
311
+ this.log(`${(0, picocolors_1.yellow)('Check out your shiny new generated files at ') + (0, picocolors_1.magenta)(output) + (0, picocolors_1.yellow)('.')}\n`);
313
312
  });
314
313
  }
315
314
  runWatchMode(asyncapi, template, output, watchHandler) {
@@ -45,19 +45,30 @@ class Models extends base_1.default {
45
45
  };
46
46
  const s = (0, prompts_1.spinner)();
47
47
  s.start('Generating models...');
48
- const generatedModels = yield (0, modelina_cli_1.generateModels)(Object.assign(Object.assign({}, flags), { output }), document, logger, language);
49
- if (output !== 'stdout') {
50
- const generatedModelStrings = generatedModels.map((model) => { return model.modelName; });
51
- s.stop((0, picocolors_1.green)(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`));
52
- return;
48
+ try {
49
+ const generatedModels = yield (0, modelina_cli_1.generateModels)(Object.assign(Object.assign({}, flags), { output }), document, logger, language);
50
+ if (output !== 'stdout') {
51
+ const generatedModelStrings = generatedModels.map((model) => { return model.modelName; });
52
+ s.stop((0, picocolors_1.green)(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`));
53
+ return;
54
+ }
55
+ const generatedModelStrings = generatedModels.map((model) => {
56
+ return `
57
+ ## Model name: ${model.modelName}
58
+ ${model.result}
59
+ `;
60
+ });
61
+ s.stop((0, picocolors_1.green)(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`));
62
+ }
63
+ catch (error) {
64
+ s.stop((0, picocolors_1.green)('Failed to generate models'));
65
+ if (error instanceof Error) {
66
+ this.error(error.message);
67
+ }
68
+ else {
69
+ this.error('An unknown error occurred during model generation.');
70
+ }
53
71
  }
54
- const generatedModelStrings = generatedModels.map((model) => {
55
- return `
56
- ## Model name: ${model.modelName}
57
- ${model.result}
58
- `;
59
- });
60
- s.stop((0, picocolors_1.green)(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`));
61
72
  });
62
73
  }
63
74
  parseArgs(args, output) {
@@ -155,5 +155,5 @@ NewFile.description = 'Creates a new asyncapi file';
155
155
  NewFile.flags = (0, file_flags_1.fileFlags)(getExamplesFlagDescription());
156
156
  NewFile.examples = [
157
157
  'asyncapi new\t - start creation of a file in interactive mode',
158
- 'asyncapi new --file-name=my-asyncapi.yml --example=default-example.yml --no-tty\t - create a new file with a specific name, using one of the examples and without interactive mode'
158
+ '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'
159
159
  ];
@@ -22,6 +22,8 @@ export default class Optimize extends Command {
22
22
  outputMethod?: Outputs;
23
23
  static examples: string[];
24
24
  static flags: {
25
+ proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
26
+ proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
25
27
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
26
28
  optimization: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
27
29
  ignore: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -30,6 +32,8 @@ export default class Optimize extends Command {
30
32
  };
31
33
  static args: {
32
34
  'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
35
+ proxyHost: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
36
+ proxyPort: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
33
37
  };
34
38
  parser: Parser;
35
39
  run(): Promise<void>;
@@ -12,6 +12,7 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));
12
12
  const fs_1 = require("fs");
13
13
  const parser_1 = require("@asyncapi/parser");
14
14
  const optimize_flags_1 = require("../core/flags/optimize.flags");
15
+ const proxy_flags_1 = require("../core/flags/proxy.flags");
15
16
  const { writeFile } = fs_1.promises;
16
17
  var Optimizations;
17
18
  (function (Optimizations) {
@@ -40,15 +41,26 @@ class Optimize extends base_1.default {
40
41
  var _a, _b, _c, _d;
41
42
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
43
  const { args, flags } = yield this.parse(Optimize); //NOSONAR
43
- const filePath = args['spec-file'];
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
+ }
44
51
  try {
45
52
  this.specFile = yield (0, SpecificationFile_1.load)(filePath);
46
53
  }
47
54
  catch (err) {
48
- this.error(new validation_error_1.ValidationError({
49
- type: 'invalid-file',
50
- filepath: filePath,
51
- }));
55
+ if (err.message.includes('Failed to download')) {
56
+ throw new Error('Proxy Connection Error: Unable to establish a connection to the proxy check hostName or PortNumber.');
57
+ }
58
+ else {
59
+ this.error(new validation_error_1.ValidationError({
60
+ type: 'invalid-file',
61
+ filepath: filePath,
62
+ }));
63
+ }
52
64
  }
53
65
  let optimizer;
54
66
  let report;
@@ -221,7 +233,9 @@ Optimize.examples = [
221
233
  'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty',
222
234
  'asyncapi optimize ./asyncapi.yaml --ignore=schema'
223
235
  ];
224
- Optimize.flags = (0, optimize_flags_1.optimizeFlags)();
236
+ Optimize.flags = Object.assign(Object.assign({}, (0, optimize_flags_1.optimizeFlags)()), (0, proxy_flags_1.proxyFlags)());
225
237
  Optimize.args = {
226
238
  'spec-file': core_1.Args.string({ description: 'spec path, url, or context-name', required: false }),
239
+ proxyHost: core_1.Args.string({ description: 'Name of the Proxy Host', required: false }),
240
+ proxyPort: core_1.Args.string({ description: 'Name of the Port of the ProxyHost', required: false }),
227
241
  };
@@ -1,6 +1,6 @@
1
1
  import Command from '../core/base';
2
2
  export default class Pretty extends Command {
3
- static readonly description = "Format AsyncAPI specification file";
3
+ static readonly description = "Beautify the AsyncAPI spec file (indentation, styling) in place or output the formatted spec to a new file.";
4
4
  static readonly examples: string[];
5
5
  static readonly flags: {
6
6
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -56,7 +56,7 @@ class Pretty extends base_1.default {
56
56
  }
57
57
  }
58
58
  exports.default = Pretty;
59
- Pretty.description = 'Format AsyncAPI specification file';
59
+ Pretty.description = 'Beautify the AsyncAPI spec file (indentation, styling) in place or output the formatted spec to a new file.';
60
60
  Pretty.examples = [
61
61
  'asyncapi pretty ./asyncapi.yaml',
62
62
  'asyncapi pretty ./asyncapi.yaml --output formatted-asyncapi.yaml',
@@ -6,5 +6,8 @@ export default class StartStudio extends Command {
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
8
  };
9
+ static readonly args: {
10
+ 'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
11
+ };
9
12
  run(): Promise<void>;
10
13
  }
@@ -5,13 +5,35 @@ const base_1 = tslib_1.__importDefault(require("../../core/base"));
5
5
  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
+ const core_1 = require("@oclif/core");
8
9
  class StartStudio extends base_1.default {
9
10
  run() {
11
+ var _a;
10
12
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
- const { flags } = yield this.parse(StartStudio);
12
- const filePath = flags.file || (yield (0, SpecificationFile_1.load)()).getFilePath();
13
+ const { args, flags } = yield this.parse(StartStudio);
14
+ if (flags.file) {
15
+ 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
+ }
17
+ let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
13
18
  const port = flags.port;
14
- this.specFile = yield (0, SpecificationFile_1.load)(filePath);
19
+ if (!filePath) {
20
+ try {
21
+ filePath = ((yield (0, SpecificationFile_1.load)()).getFilePath());
22
+ this.log(`Loaded specification from: ${filePath}`);
23
+ }
24
+ catch (error) {
25
+ filePath = '';
26
+ this.error('No file specified.');
27
+ }
28
+ }
29
+ try {
30
+ this.specFile = yield (0, SpecificationFile_1.load)(filePath);
31
+ }
32
+ catch (error) {
33
+ if (filePath) {
34
+ this.error(error);
35
+ }
36
+ }
15
37
  this.metricsMetadata.port = port;
16
38
  (0, Studio_1.start)(filePath, port);
17
39
  });
@@ -20,3 +42,6 @@ class StartStudio extends base_1.default {
20
42
  exports.default = StartStudio;
21
43
  StartStudio.description = 'starts a new local instance of Studio';
22
44
  StartStudio.flags = (0, studio_flags_1.studioFlags)();
45
+ StartStudio.args = {
46
+ 'spec-file': core_1.Args.string({ description: 'spec path, url, or context-name', required: false }),
47
+ };
@@ -2,6 +2,8 @@ import Command from '../core/base';
2
2
  export default class Validate extends Command {
3
3
  static description: string;
4
4
  static flags: {
5
+ proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
6
+ proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
5
7
  score: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
8
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
9
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -12,6 +14,8 @@ export default class Validate extends Command {
12
14
  };
13
15
  static args: {
14
16
  'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
17
+ proxyHost: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
18
+ proxyPort: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
15
19
  };
16
20
  run(): Promise<void>;
17
21
  }
@@ -7,19 +7,25 @@ const parser_1 = require("../core/parser");
7
7
  const SpecificationFile_1 = require("../core/models/SpecificationFile");
8
8
  const globals_1 = require("../core/globals");
9
9
  const validate_flags_1 = require("../core/flags/validate.flags");
10
+ const proxy_flags_1 = require("../core/flags/proxy.flags");
10
11
  const scoreCalculator_1 = require("../core/utils/scoreCalculator");
11
12
  class Validate extends base_1.default {
12
13
  run() {
13
14
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
15
  const { args, flags } = yield this.parse(Validate); //NOSONAR
15
- const filePath = args['spec-file'];
16
+ let filePath = args['spec-file'];
17
+ const proxyHost = flags['proxyHost'];
18
+ const proxyPort = flags['proxyPort'];
19
+ if (proxyHost && proxyPort) {
20
+ const proxyUrl = `http://${proxyHost}:${proxyPort}`;
21
+ filePath = `${filePath}+${proxyUrl}`; // Update filePath with proxyUrl
22
+ }
23
+ this.specFile = yield (0, SpecificationFile_1.load)(filePath);
16
24
  const watchMode = flags.watch;
17
25
  if (flags['score']) {
18
- this.specFile = yield (0, SpecificationFile_1.load)(filePath);
19
26
  const { document } = yield (0, parser_1.parse)(this, this.specFile);
20
27
  this.log(`The score of the asyncapi document is ${yield (0, scoreCalculator_1.calculateScore)(document)}`);
21
28
  }
22
- this.specFile = yield (0, SpecificationFile_1.load)(filePath);
23
29
  if (watchMode) {
24
30
  (0, globals_1.specWatcher)({ spec: this.specFile, handler: this, handlerName: 'validate' });
25
31
  }
@@ -33,7 +39,9 @@ class Validate extends base_1.default {
33
39
  }
34
40
  exports.default = Validate;
35
41
  Validate.description = 'validate asyncapi file';
36
- Validate.flags = (0, validate_flags_1.validateFlags)();
42
+ Validate.flags = Object.assign(Object.assign({}, (0, validate_flags_1.validateFlags)()), (0, proxy_flags_1.proxyFlags)());
37
43
  Validate.args = {
38
44
  'spec-file': core_1.Args.string({ description: 'spec path, url, or context-name', required: false }),
45
+ proxyHost: core_1.Args.string({ description: 'Name of the Proxy Host', required: false }),
46
+ proxyPort: core_1.Args.string({ description: 'Name of the Port of the ProxyHost', required: false }),
39
47
  };
package/lib/core/base.js CHANGED
@@ -43,6 +43,10 @@ class default_1 extends core_1.Command {
43
43
  return 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
+ }
46
50
  if (e instanceof Error) {
47
51
  this.logToStderr(`${e.name}: ${e.message}`);
48
52
  process.exitCode = 1;
@@ -0,0 +1,4 @@
1
+ export declare const proxyFlags: () => {
2
+ proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
3
+ proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
4
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.proxyFlags = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ const proxyFlags = () => {
6
+ return {
7
+ proxyHost: core_1.Flags.string({
8
+ description: 'Name of the ProxyHost',
9
+ required: false
10
+ }),
11
+ proxyPort: core_1.Flags.string({
12
+ description: 'Port number number for the proxyHost.',
13
+ required: false
14
+ })
15
+ };
16
+ };
17
+ exports.proxyFlags = proxyFlags;
@@ -5,7 +5,7 @@ const core_1 = require("@oclif/core");
5
5
  const studioFlags = () => {
6
6
  return {
7
7
  help: core_1.Flags.help({ char: 'h' }),
8
- file: core_1.Flags.string({ char: 'f', description: 'path to the AsyncAPI file to link with Studio' }),
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
10
  };
11
11
  };
@@ -10,6 +10,7 @@ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
10
10
  const Context_1 = require("./Context");
11
11
  const specification_file_1 = require("../errors/specification-file");
12
12
  const context_error_1 = require("../errors/context-error");
13
+ const https_proxy_agent_1 = require("https-proxy-agent");
13
14
  const { readFile, lstat } = fs_1.promises;
14
15
  const allowedFileNames = [
15
16
  'asyncapi.json',
@@ -80,16 +81,41 @@ class Specification {
80
81
  static fromURL(URLpath) {
81
82
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
82
83
  let response;
84
+ const delimiter = '+';
85
+ let targetUrl = URLpath;
86
+ let proxyUrl = '';
87
+ // Check if URLpath contains a proxy URL
88
+ if (URLpath.includes(delimiter)) {
89
+ [targetUrl, proxyUrl] = URLpath.split(delimiter);
90
+ }
83
91
  try {
84
- response = yield (0, node_fetch_1.default)(URLpath, { method: 'GET' });
85
- if (!response.ok) {
86
- throw new specification_file_1.ErrorLoadingSpec('url', URLpath);
92
+ // Validate the target URL
93
+ new url_1.URL(targetUrl);
94
+ const fetchOptions = { method: 'GET' };
95
+ // If proxy URL is provided, create a proxy agent
96
+ if (proxyUrl) {
97
+ try {
98
+ new url_1.URL(proxyUrl);
99
+ const proxyAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl);
100
+ fetchOptions.agent = proxyAgent;
101
+ response = yield (0, node_fetch_1.default)(targetUrl, fetchOptions);
102
+ }
103
+ catch (err) {
104
+ throw new Error('Proxy Connection Error: Unable to establish a connection to the proxy check hostName or PortNumber');
105
+ }
106
+ }
107
+ else {
108
+ response = yield (0, node_fetch_1.default)(targetUrl);
109
+ if (!response.ok) {
110
+ throw new specification_file_1.ErrorLoadingSpec('url', targetUrl);
111
+ }
87
112
  }
88
113
  }
89
114
  catch (error) {
90
- throw new specification_file_1.ErrorLoadingSpec('url', URLpath);
115
+ console.log(error);
116
+ throw new specification_file_1.ErrorLoadingSpec('url', targetUrl);
91
117
  }
92
- return new Specification(yield (response === null || response === void 0 ? void 0 : response.text()), { fileURL: URLpath });
118
+ return new Specification(yield (response === null || response === void 0 ? void 0 : response.text()), { fileURL: targetUrl });
93
119
  });
94
120
  }
95
121
  }
@@ -20,30 +20,32 @@ function isValidFilePath(filePath) {
20
20
  return (0, fs_1.existsSync)(filePath);
21
21
  }
22
22
  function start(filePath, port = exports.DEFAULT_PORT) {
23
- if (!isValidFilePath(filePath)) {
23
+ if (filePath && !isValidFilePath(filePath)) {
24
24
  throw new specification_file_1.SpecificationFileNotFound(filePath);
25
25
  }
26
- chokidar_1.default.watch(filePath).on('all', (event, path) => {
27
- switch (event) {
28
- case 'add':
29
- case 'change':
30
- getFileContent(path).then((code) => {
26
+ if (filePath) {
27
+ chokidar_1.default.watch(filePath).on('all', (event, path) => {
28
+ switch (event) {
29
+ case 'add':
30
+ case 'change':
31
+ getFileContent(path).then((code) => {
32
+ messageQueue.push(JSON.stringify({
33
+ type: 'file:changed',
34
+ code,
35
+ }));
36
+ sendQueuedMessages();
37
+ });
38
+ break;
39
+ case 'unlink':
31
40
  messageQueue.push(JSON.stringify({
32
- type: 'file:changed',
33
- code,
41
+ type: 'file:deleted',
42
+ filePath,
34
43
  }));
35
44
  sendQueuedMessages();
36
- });
37
- break;
38
- case 'unlink':
39
- messageQueue.push(JSON.stringify({
40
- type: 'file:deleted',
41
- filePath,
42
- }));
43
- sendQueuedMessages();
44
- break;
45
- }
46
- });
45
+ break;
46
+ }
47
+ });
48
+ }
47
49
  const server = (0, http_1.createServer)((request, response) => {
48
50
  //not all CLI users use npm. Some package managers put dependencies in different weird places
49
51
  //this is why we need to first figure out where exactly is the index.html located
@@ -67,17 +69,26 @@ function start(filePath, port = exports.DEFAULT_PORT) {
67
69
  const wsServer = new ws_1.WebSocketServer({ noServer: true });
68
70
  wsServer.on('connection', (socket) => {
69
71
  sockets.push(socket);
70
- getFileContent(filePath).then((code) => {
72
+ if (filePath) {
73
+ getFileContent(filePath).then((code) => {
74
+ messageQueue.push(JSON.stringify({
75
+ type: 'file:loaded',
76
+ code,
77
+ }));
78
+ sendQueuedMessages();
79
+ });
80
+ }
81
+ else {
71
82
  messageQueue.push(JSON.stringify({
72
83
  type: 'file:loaded',
73
- code,
84
+ code: '',
74
85
  }));
75
86
  sendQueuedMessages();
76
- });
87
+ }
77
88
  socket.on('message', (event) => {
78
89
  try {
79
90
  const json = JSON.parse(event);
80
- if (json.type === 'file:update') {
91
+ if (filePath && json.type === 'file:update') {
81
92
  saveFileContent(filePath, json.code);
82
93
  }
83
94
  else {
@@ -97,7 +108,12 @@ function start(filePath, port = exports.DEFAULT_PORT) {
97
108
  const url = `http://localhost:${port}?liveServer=${port}&studio-version=${package_json_1.version}`;
98
109
  console.log(`Studio is now running at ${url}.`);
99
110
  console.log(`You can open this URL in your web browser, and if needed, press ${(0, picocolors_1.gray)('Ctrl + C')} to stop the process.`);
100
- console.log(`Watching changes on file ${filePath}`);
111
+ if (filePath) {
112
+ console.log(`Watching changes on file ${filePath}`);
113
+ }
114
+ else {
115
+ 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.');
116
+ }
101
117
  (0, open_1.default)(url);
102
118
  });
103
119
  }
@@ -73,6 +73,16 @@
73
73
  "description": "spec path, url, or context-name",
74
74
  "name": "spec-file",
75
75
  "required": false
76
+ },
77
+ "proxyHost": {
78
+ "description": "Name of the Proxy Host",
79
+ "name": "proxyHost",
80
+ "required": false
81
+ },
82
+ "proxyPort": {
83
+ "description": "Name of the Port of the ProxyHost",
84
+ "name": "proxyPort",
85
+ "required": false
76
86
  }
77
87
  },
78
88
  "description": "Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI",
@@ -128,6 +138,22 @@
128
138
  "server"
129
139
  ],
130
140
  "type": "option"
141
+ },
142
+ "proxyHost": {
143
+ "description": "Name of the ProxyHost",
144
+ "name": "proxyHost",
145
+ "required": false,
146
+ "hasDynamicHelp": false,
147
+ "multiple": false,
148
+ "type": "option"
149
+ },
150
+ "proxyPort": {
151
+ "description": "Port number number for the proxyHost.",
152
+ "name": "proxyPort",
153
+ "required": false,
154
+ "hasDynamicHelp": false,
155
+ "multiple": false,
156
+ "type": "option"
131
157
  }
132
158
  },
133
159
  "hasDynamicHelp": false,
@@ -355,6 +381,16 @@
355
381
  "description": "spec path, url, or context-name",
356
382
  "name": "spec-file",
357
383
  "required": false
384
+ },
385
+ "proxyHost": {
386
+ "description": "Name of the Proxy Host",
387
+ "name": "proxyHost",
388
+ "required": false
389
+ },
390
+ "proxyPort": {
391
+ "description": "Name of the Port of the ProxyHost",
392
+ "name": "proxyPort",
393
+ "required": false
358
394
  }
359
395
  },
360
396
  "description": "optimize asyncapi specification file",
@@ -424,6 +460,22 @@
424
460
  "name": "no-tty",
425
461
  "allowNo": false,
426
462
  "type": "boolean"
463
+ },
464
+ "proxyHost": {
465
+ "description": "Name of the ProxyHost",
466
+ "name": "proxyHost",
467
+ "required": false,
468
+ "hasDynamicHelp": false,
469
+ "multiple": false,
470
+ "type": "option"
471
+ },
472
+ "proxyPort": {
473
+ "description": "Port number number for the proxyHost.",
474
+ "name": "proxyPort",
475
+ "required": false,
476
+ "hasDynamicHelp": false,
477
+ "multiple": false,
478
+ "type": "option"
427
479
  }
428
480
  },
429
481
  "hasDynamicHelp": false,
@@ -449,7 +501,7 @@
449
501
  "required": true
450
502
  }
451
503
  },
452
- "description": "Format AsyncAPI specification file",
504
+ "description": "Beautify the AsyncAPI spec file (indentation, styling) in place or output the formatted spec to a new file.",
453
505
  "examples": [
454
506
  "asyncapi pretty ./asyncapi.yaml",
455
507
  "asyncapi pretty ./asyncapi.yaml --output formatted-asyncapi.yaml"
@@ -485,6 +537,16 @@
485
537
  "description": "spec path, url, or context-name",
486
538
  "name": "spec-file",
487
539
  "required": false
540
+ },
541
+ "proxyHost": {
542
+ "description": "Name of the Proxy Host",
543
+ "name": "proxyHost",
544
+ "required": false
545
+ },
546
+ "proxyPort": {
547
+ "description": "Name of the Port of the ProxyHost",
548
+ "name": "proxyPort",
549
+ "required": false
488
550
  }
489
551
  },
490
552
  "description": "validate asyncapi file",
@@ -554,6 +616,22 @@
554
616
  "required": false,
555
617
  "allowNo": false,
556
618
  "type": "boolean"
619
+ },
620
+ "proxyHost": {
621
+ "description": "Name of the ProxyHost",
622
+ "name": "proxyHost",
623
+ "required": false,
624
+ "hasDynamicHelp": false,
625
+ "multiple": false,
626
+ "type": "option"
627
+ },
628
+ "proxyPort": {
629
+ "description": "Port number number for the proxyHost.",
630
+ "name": "proxyPort",
631
+ "required": false,
632
+ "hasDynamicHelp": false,
633
+ "multiple": false,
634
+ "type": "option"
557
635
  }
558
636
  },
559
637
  "hasDynamicHelp": false,
@@ -1132,7 +1210,7 @@
1132
1210
  "description": "Creates a new asyncapi file",
1133
1211
  "examples": [
1134
1212
  "asyncapi new\t - start creation of a file in interactive mode",
1135
- "asyncapi new --file-name=my-asyncapi.yml --example=default-example.yml --no-tty\t - create a new file with a specific name, using one of the examples and without interactive mode"
1213
+ "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"
1136
1214
  ],
1137
1215
  "flags": {
1138
1216
  "help": {
@@ -1262,7 +1340,7 @@
1262
1340
  "description": "Creates a new asyncapi file",
1263
1341
  "examples": [
1264
1342
  "asyncapi new\t - start creation of a file in interactive mode",
1265
- "asyncapi new --file-name=my-asyncapi.yml --example=default-example.yml --no-tty\t - create a new file with a specific name, using one of the examples and without interactive mode"
1343
+ "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"
1266
1344
  ],
1267
1345
  "flags": {
1268
1346
  "help": {
@@ -1416,7 +1494,13 @@
1416
1494
  },
1417
1495
  "start:studio": {
1418
1496
  "aliases": [],
1419
- "args": {},
1497
+ "args": {
1498
+ "spec-file": {
1499
+ "description": "spec path, url, or context-name",
1500
+ "name": "spec-file",
1501
+ "required": false
1502
+ }
1503
+ },
1420
1504
  "description": "starts a new local instance of Studio",
1421
1505
  "flags": {
1422
1506
  "help": {
@@ -1428,6 +1512,7 @@
1428
1512
  },
1429
1513
  "file": {
1430
1514
  "char": "f",
1515
+ "deprecated": true,
1431
1516
  "description": "path to the AsyncAPI file to link with Studio",
1432
1517
  "name": "file",
1433
1518
  "hasDynamicHelp": false,
@@ -1732,5 +1817,5 @@
1732
1817
  ]
1733
1818
  }
1734
1819
  },
1735
- "version": "2.14.1"
1820
+ "version": "2.16.0"
1736
1821
  }
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": "2.14.1",
4
+ "version": "2.16.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"
@@ -30,9 +30,9 @@
30
30
  "fast-levenshtein": "^3.0.0",
31
31
  "fs-extra": "^11.1.0",
32
32
  "generator-v2": "npm:@asyncapi/generator@^2.4.1",
33
+ "https-proxy-agent": "^7.0.6",
33
34
  "inquirer": "^8.2.0",
34
35
  "js-yaml": "^4.1.0",
35
- "lodash.template": "^4.4.0",
36
36
  "node-fetch": "^2.0.0",
37
37
  "oclif": "^4.2.0",
38
38
  "open": "^8.4.0",
@@ -56,7 +56,6 @@
56
56
  "@types/fs-extra": "^11.0.1",
57
57
  "@types/inquirer": "^8.1.3",
58
58
  "@types/js-yaml": "^4.0.5",
59
- "@types/lodash.template": "^4.4.4",
60
59
  "@types/mocha": "^10.0.2",
61
60
  "@types/node": "^10.17.60",
62
61
  "@types/node-fetch": "^2.5.12",