@asyncapi/cli 2.4.0 → 2.5.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.
@@ -6,7 +6,6 @@ const global_flags_1 = require("../../core/flags/global.flags");
6
6
  class Versions extends base_1.default {
7
7
  run() {
8
8
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- var _a;
10
9
  const dependencies = [];
11
10
  let dependency = '';
12
11
  // Preparation of the array with all dependencies '@asyncapi/*' along with
@@ -20,7 +19,7 @@ class Versions extends base_1.default {
20
19
  try {
21
20
  // Goofy name `importedPJSON` is chosen to distinguish from name `pjson`
22
21
  // used in `@oclif` source code.
23
- const importedPJSON = yield (_a = `${key}/package.json`, Promise.resolve().then(() => tslib_1.__importStar(require(_a))));
22
+ const importedPJSON = yield Promise.resolve().then(() => tslib_1.__importStar(require(`${key}/package.json`)));
24
23
  dependencies.push(`${key}/${importedPJSON.default.version}`);
25
24
  }
26
25
  catch (e) {
@@ -5,7 +5,7 @@ export default class Diff extends Command {
5
5
  static flags: {
6
6
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
7
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
8
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
9
9
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
10
10
  format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
11
11
  type: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -18,6 +18,7 @@ export default class Template extends Command {
18
18
  'registry-url': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
19
19
  'registry-auth': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
20
20
  'registry-token': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
21
+ 'use-new-generator': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
22
  };
22
23
  static args: {
23
24
  asyncapi: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
@@ -33,6 +34,7 @@ export default class Template extends Command {
33
34
  private disableHooksParser;
34
35
  private mapBaseURLParser;
35
36
  private generate;
37
+ private generateUsingNewGenerator;
36
38
  private runWatchMode;
37
39
  private watcherHandler;
38
40
  private getMapBaseUrlToFolderResolver;
@@ -6,6 +6,7 @@ const base_1 = tslib_1.__importDefault(require("../../core/base"));
6
6
  // eslint-disable-next-line
7
7
  // @ts-ignore
8
8
  const generator_1 = tslib_1.__importDefault(require("@asyncapi/generator"));
9
+ const generator_v2_1 = tslib_1.__importDefault(require("generator-v2"));
9
10
  const path_1 = tslib_1.__importDefault(require("path"));
10
11
  const os_1 = tslib_1.__importDefault(require("os"));
11
12
  const fs_1 = tslib_1.__importDefault(require("fs"));
@@ -114,7 +115,12 @@ class Template extends base_1.default {
114
115
  this.error(`${template} template does not support AsyncAPI v3 documents, please checkout ${v3IssueLink}`);
115
116
  }
116
117
  }
117
- yield this.generate(asyncapi, template, output, options, genOption, interactive);
118
+ if (flags['use-new-generator']) {
119
+ yield this.generateUsingNewGenerator(asyncapi, template, output, options, genOption, interactive);
120
+ }
121
+ else {
122
+ yield this.generate(asyncapi, template, output, options, genOption, interactive);
123
+ }
118
124
  if (watchTemplate) {
119
125
  const watcherHandler = this.watcherHandler(asyncapi, template, output, options, genOption, interactive);
120
126
  yield this.runWatchMode(asyncapi, template, output, watcherHandler);
@@ -281,6 +287,31 @@ class Template extends base_1.default {
281
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`);
282
288
  });
283
289
  }
290
+ generateUsingNewGenerator(asyncapi, template, output, options, genOption, interactive = true) {
291
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
292
+ let specification;
293
+ try {
294
+ specification = yield (0, SpecificationFile_1.load)(asyncapi);
295
+ }
296
+ catch (err) {
297
+ return this.error(new validation_error_1.ValidationError({
298
+ type: 'invalid-file',
299
+ filepath: asyncapi,
300
+ }), { exit: 1 });
301
+ }
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');
305
+ try {
306
+ yield generator.generateFromString(specification.text(), Object.assign(Object.assign({}, genOption), { path: asyncapi }));
307
+ }
308
+ catch (err) {
309
+ s.stop('Generation failed');
310
+ throw new generator_error_1.GeneratorError(err);
311
+ }
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`);
313
+ });
314
+ }
284
315
  runWatchMode(asyncapi, template, output, watchHandler) {
285
316
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
286
317
  const specification = yield (0, SpecificationFile_1.load)(asyncapi);
@@ -5,7 +5,7 @@ export default class Models extends Command {
5
5
  static flags: {
6
6
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
7
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
8
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
9
9
  'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
10
  pyDantic: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
11
  javaIncludeComments: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -5,7 +5,7 @@ export default class Validate extends Command {
5
5
  score: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
6
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
7
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
8
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
9
9
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
10
10
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
11
  };
package/lib/core/base.js CHANGED
@@ -56,6 +56,7 @@ class default_1 extends core_1.Command {
56
56
  try {
57
57
  const { document } = yield this.parser.parse(rawDocument);
58
58
  if (document !== undefined) {
59
+ // @ts-ignore
59
60
  metadata = (0, asyncapi_adoption_metrics_1.MetadataFromDocument)(document, metadata);
60
61
  }
61
62
  }
@@ -7,7 +7,7 @@ export declare class SpecificationFileNotFound extends SpecificationFileError {
7
7
  export declare class SpecificationURLNotFound extends SpecificationFileError {
8
8
  constructor(URL: string);
9
9
  }
10
- type From = 'file' | 'url' | 'context' | 'invalid file';
10
+ declare type From = 'file' | 'url' | 'context' | 'invalid file';
11
11
  export declare class ErrorLoadingSpec extends Error {
12
12
  private readonly errorMessages;
13
13
  constructor(from?: From, param?: string);
@@ -1,4 +1,4 @@
1
- type ErrorType = 'parser-error' | 'invalid-file' | 'no-spec-found';
1
+ declare type ErrorType = 'parser-error' | 'invalid-file' | 'no-spec-found';
2
2
  interface IValidationErrorInput {
3
3
  type: ErrorType;
4
4
  err?: any;
@@ -1,7 +1,7 @@
1
1
  export declare const diffFlags: () => {
2
2
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
3
3
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
4
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
4
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
5
5
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
6
6
  format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
7
7
  type: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -13,4 +13,5 @@ export declare const fromTemplateFlags: () => {
13
13
  'registry-url': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
14
14
  'registry-auth': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
15
15
  'registry-token': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
16
+ 'use-new-generator': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
17
  };
@@ -55,6 +55,10 @@ const fromTemplateFlags = () => {
55
55
  }),
56
56
  'registry-token': core_1.Flags.string({
57
57
  description: 'The npm registry authentication token, that can be passed instead of base64 encoded username and password'
58
+ }),
59
+ 'use-new-generator': core_1.Flags.boolean({
60
+ default: false,
61
+ description: 'Use v2 generator, for generating from newer templates'
58
62
  })
59
63
  };
60
64
  };
@@ -1,7 +1,7 @@
1
1
  export declare const modelsFlags: () => {
2
2
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
3
3
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
4
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
4
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
5
5
  'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
6
  pyDantic: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
7
  javaIncludeComments: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -1,4 +1,4 @@
1
- export declare const watchFlag: (description?: string) => import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
1
+ export declare const watchFlag: (description?: string | undefined) => import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
2
2
  export declare const helpFlag: () => {
3
3
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
4
4
  };
@@ -2,7 +2,7 @@ export declare const validateFlags: () => {
2
2
  score: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
3
3
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
4
4
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
5
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
5
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
6
6
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
7
7
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
8
  };
@@ -1,6 +1,6 @@
1
1
  import Command from './base';
2
2
  import { Specification } from './models/SpecificationFile';
3
- export type SpecWatcherParams = {
3
+ export declare type SpecWatcherParams = {
4
4
  spec: Specification;
5
5
  handler: Command;
6
6
  handlerName: string;
@@ -3,7 +3,7 @@ import { OutputFormat } from '@stoplight/spectral-cli/dist/services/config';
3
3
  import type { Diagnostic } from '@asyncapi/parser/cjs';
4
4
  import type Command from './base';
5
5
  import type { Specification } from './models/SpecificationFile';
6
- export type SeverityKind = 'error' | 'warn' | 'info' | 'hint';
6
+ export declare type SeverityKind = 'error' | 'warn' | 'info' | 'hint';
7
7
  export { convertToOldAPI };
8
8
  export interface ValidationFlagsOptions {
9
9
  logDiagnostics?: boolean;
@@ -15,7 +15,7 @@ export declare enum ValidationStatus {
15
15
  export declare function validationFlags({ logDiagnostics }?: ValidationFlagsOptions): {
16
16
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
17
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
18
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
18
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
19
19
  };
20
20
  export interface ValidateOptions {
21
21
  'log-diagnostics'?: boolean;
@@ -673,6 +673,12 @@
673
673
  "hasDynamicHelp": false,
674
674
  "multiple": false,
675
675
  "type": "option"
676
+ },
677
+ "use-new-generator": {
678
+ "description": "Use v2 generator, for generating from newer templates",
679
+ "name": "use-new-generator",
680
+ "allowNo": false,
681
+ "type": "boolean"
676
682
  }
677
683
  },
678
684
  "hasDynamicHelp": false,
@@ -1614,5 +1620,5 @@
1614
1620
  ]
1615
1621
  }
1616
1622
  },
1617
- "version": "2.4.0"
1623
+ "version": "2.5.0"
1618
1624
  }
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.4.0",
4
+ "version": "2.5.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"
@@ -10,14 +10,14 @@
10
10
  "dependencies": {
11
11
  "@asyncapi/avro-schema-parser": "^3.0.23",
12
12
  "@asyncapi/bundler": "^0.6.3",
13
- "@asyncapi/converter": "^1.6.1",
13
+ "@asyncapi/converter": "^1.6.2",
14
14
  "@asyncapi/diff": "^0.4.1",
15
15
  "@asyncapi/generator": "^1.17.25",
16
16
  "@asyncapi/modelina": "^3.7.0",
17
17
  "@asyncapi/modelina-cli": "^4.0.0-next.48",
18
18
  "@asyncapi/openapi-schema-parser": "^3.0.24",
19
19
  "@asyncapi/optimizer": "^1.0.3",
20
- "@asyncapi/parser": "^3.1.0",
20
+ "@asyncapi/parser": "^3.3.0",
21
21
  "@asyncapi/protobuf-schema-parser": "^3.2.13",
22
22
  "@asyncapi/raml-dt-schema-parser": "^4.0.24",
23
23
  "@asyncapi/studio": "^0.20.0",
@@ -33,6 +33,7 @@
33
33
  "chokidar": "^3.5.2",
34
34
  "fast-levenshtein": "^3.0.0",
35
35
  "fs-extra": "^11.1.0",
36
+ "generator-v2": "npm:@asyncapi/generator@^2.4.1",
36
37
  "indent-string": "^4.0.0",
37
38
  "inquirer": "^8.2.0",
38
39
  "js-yaml": "^4.1.0",
@@ -52,6 +53,7 @@
52
53
  },
53
54
  "devDependencies": {
54
55
  "@asyncapi/minimaltemplate": "./test/fixtures/minimaltemplate",
56
+ "@asyncapi/newtemplate": "./test/fixtures/newtemplate",
55
57
  "@babel/core": "^7.19.3",
56
58
  "@oclif/test": "^2",
57
59
  "@swc/core": "^1.3.2",
@@ -156,7 +158,7 @@
156
158
  "generate:assets": "npm run generate:readme:toc && npm run generate:commands",
157
159
  "generate:commands": "npm run generate:readme:create && npm run generate:readme:commands && node ./scripts/updateUsageDocs.js && rimraf ./scripts/README.md",
158
160
  "generate:readme:toc": "markdown-toc -i README.md",
159
- "lint": "eslint --max-warnings 0 --config .eslintrc .",
161
+ "lint": "eslint --max-warnings 5 --config .eslintrc .",
160
162
  "lint:fix": "eslint --max-warnings 5 --config .eslintrc . --fix",
161
163
  "pack:macos": "oclif pack macos && npm run pack:rename",
162
164
  "pack:linux": "oclif pack deb && npm run pack:rename",