@asyncapi/cli 3.2.0 → 3.4.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.
- package/assets/create-template/templates/default/package-lock.json +4 -3
- package/lib/apps/api/app.d.ts +15 -0
- package/lib/apps/api/app.js +89 -0
- package/lib/apps/api/configs/development.json +16 -0
- package/lib/apps/api/configs/production.json +16 -0
- package/lib/apps/api/configs/test.json +16 -0
- package/lib/apps/api/constants.d.ts +1 -0
- package/lib/apps/api/constants.js +4 -0
- package/lib/apps/api/controllers/bundle.controller.d.ts +7 -0
- package/lib/apps/api/controllers/bundle.controller.js +44 -0
- package/lib/apps/api/controllers/convert.controller.d.ts +11 -0
- package/lib/apps/api/controllers/convert.controller.js +69 -0
- package/lib/apps/api/controllers/diff.controller.d.ts +7 -0
- package/lib/apps/api/controllers/diff.controller.js +42 -0
- package/lib/apps/api/controllers/docs.controller.d.ts +6 -0
- package/lib/apps/api/controllers/docs.controller.js +24 -0
- package/lib/apps/api/controllers/generate.controller.d.ts +22 -0
- package/lib/apps/api/controllers/generate.controller.js +176 -0
- package/lib/apps/api/controllers/help.controller.d.ts +6 -0
- package/lib/apps/api/controllers/help.controller.js +101 -0
- package/lib/apps/api/controllers/parse.controller.d.ts +10 -0
- package/lib/apps/api/controllers/parse.controller.js +35 -0
- package/lib/apps/api/controllers/validate.controller.d.ts +10 -0
- package/lib/apps/api/controllers/validate.controller.js +50 -0
- package/lib/apps/api/exceptions/problem.exception.d.ts +14 -0
- package/lib/apps/api/exceptions/problem.exception.js +10 -0
- package/lib/apps/api/index.d.ts +9 -0
- package/lib/apps/api/index.js +21 -0
- package/lib/apps/api/middlewares/problem.middleware.d.ts +6 -0
- package/lib/apps/api/middlewares/problem.middleware.js +27 -0
- package/lib/apps/api/middlewares/validation.middleware.d.ts +12 -0
- package/lib/apps/api/middlewares/validation.middleware.js +236 -0
- package/lib/apps/api/server.d.ts +3 -0
- package/lib/apps/api/server.js +19 -0
- package/lib/{commands → apps/cli/commands}/bundle.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/bundle.js +3 -3
- package/lib/{commands → apps/cli/commands}/config/analytics.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/analytics.js +4 -3
- package/lib/{commands → apps/cli/commands}/config/context/add.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/add.js +12 -6
- package/lib/{commands → apps/cli/commands}/config/context/current.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/current.js +4 -4
- package/lib/{commands → apps/cli/commands}/config/context/edit.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/edit.js +12 -6
- package/lib/{commands → apps/cli/commands}/config/context/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/init.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/init.js +7 -4
- package/lib/{commands → apps/cli/commands}/config/context/list.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/list.js +4 -4
- package/lib/{commands → apps/cli/commands}/config/context/remove.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/remove.js +8 -5
- package/lib/{commands → apps/cli/commands}/config/context/use.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/use.js +8 -5
- package/lib/{commands → apps/cli/commands}/config/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/config/versions.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/versions.js +2 -2
- package/lib/{commands → apps/cli/commands}/convert.d.ts +2 -7
- package/lib/apps/cli/commands/convert.js +85 -0
- package/lib/{commands → apps/cli/commands}/diff.d.ts +11 -2
- package/lib/{commands → apps/cli/commands}/diff.js +85 -31
- package/lib/{commands → apps/cli/commands}/format.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/format.js +4 -4
- package/lib/{commands → apps/cli/commands}/generate/fromTemplate.d.ts +4 -5
- package/lib/{commands → apps/cli/commands}/generate/fromTemplate.js +89 -122
- package/lib/{commands → apps/cli/commands}/generate/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/generate/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/generate/models.d.ts +6 -1
- package/lib/{commands → apps/cli/commands}/generate/models.js +48 -9
- package/lib/{commands → apps/cli/commands}/new/file.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/file.js +11 -8
- package/lib/{commands → apps/cli/commands}/new/glee.d.ts +2 -2
- package/lib/{commands → apps/cli/commands}/new/glee.js +4 -4
- package/lib/{commands → apps/cli/commands}/new/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/new/template.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/template.js +10 -8
- package/lib/{commands → apps/cli/commands}/optimize.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/optimize.js +71 -30
- package/lib/{commands → apps/cli/commands}/pretty.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/pretty.js +8 -5
- package/lib/apps/cli/commands/start/api.d.ts +11 -0
- package/lib/apps/cli/commands/start/api.js +23 -0
- package/lib/{commands → apps/cli/commands}/start/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/start/preview.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/preview.js +9 -6
- package/lib/{commands → apps/cli/commands}/start/studio.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/studio.js +10 -7
- package/lib/{commands → apps/cli/commands}/validate.d.ts +4 -2
- package/lib/apps/cli/commands/validate.js +94 -0
- package/lib/{core → apps/cli/internal}/base.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/base.js +12 -4
- package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
- package/lib/{core → apps/cli/internal}/flags/config/context.flags.js +1 -1
- package/lib/{core → apps/cli/internal}/flags/convert.flags.js +9 -2
- package/lib/{core → apps/cli/internal}/flags/diff.flags.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/flags/diff.flags.js +3 -3
- package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.js +12 -12
- package/lib/{core → apps/cli/internal}/flags/generate/models.flags.js +2 -2
- package/lib/{core → apps/cli/internal}/flags/global.flags.js +1 -1
- package/lib/{core → apps/cli/internal}/flags/new/file.flags.js +7 -2
- package/lib/{core → apps/cli/internal}/flags/optimize.flags.js +24 -4
- package/lib/apps/cli/internal/flags/parser.flags.d.ts +10 -0
- package/lib/apps/cli/internal/flags/parser.flags.js +28 -0
- package/lib/{core → apps/cli/internal}/flags/proxy.flags.js +3 -3
- package/lib/apps/cli/internal/flags/start/api.flags.d.ts +5 -0
- package/lib/apps/cli/internal/flags/start/api.flags.js +20 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.js +31 -0
- package/lib/{core → apps/cli/internal}/flags/start/studio.flags.js +9 -2
- package/lib/{core → apps/cli/internal}/flags/validate.flags.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/flags/validate.flags.js +2 -2
- package/lib/{core → apps/cli/internal}/globals.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/globals.js +2 -4
- package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.js +14 -4
- package/lib/{core → domains}/models/Context.js +1 -1
- package/lib/{core → domains}/models/Preview.js +35 -19
- package/lib/{core → domains}/models/SpecificationFile.d.ts +2 -2
- package/lib/{core → domains}/models/SpecificationFile.js +8 -5
- package/lib/{core → domains}/models/Studio.js +4 -4
- package/lib/domains/services/archiver.service.d.ts +17 -0
- package/lib/domains/services/archiver.service.js +53 -0
- package/lib/domains/services/base.service.d.ts +6 -0
- package/lib/domains/services/base.service.js +26 -0
- package/lib/domains/services/convert.service.d.ts +12 -0
- package/lib/domains/services/convert.service.js +65 -0
- package/lib/domains/services/generator.service.d.ts +15 -0
- package/lib/domains/services/generator.service.js +95 -0
- package/lib/domains/services/validation.service.d.ts +54 -0
- package/lib/domains/services/validation.service.js +288 -0
- package/lib/{core/errors → errors}/specification-file.js +1 -1
- package/lib/{core/errors → errors}/validation-error.js +6 -5
- package/lib/interfaces/index.d.ts +87 -0
- package/lib/interfaces/index.js +7 -0
- package/lib/utils/ajv.d.ts +2 -0
- package/lib/utils/ajv.js +18 -0
- package/lib/utils/app-openapi.d.ts +4 -0
- package/lib/utils/app-openapi.js +28 -0
- package/lib/{core/utils/generator.js → utils/fileWatcher.js} +8 -2
- package/lib/utils/logger.d.ts +6 -0
- package/lib/utils/logger.js +33 -0
- package/lib/utils/retrieve-language.d.ts +1 -0
- package/lib/utils/retrieve-language.js +9 -0
- package/lib/utils/temp-dir.d.ts +2 -0
- package/lib/utils/temp-dir.js +25 -0
- package/oclif.manifest.json +109 -1
- package/package.json +37 -10
- package/scripts/releasePackagesRename.js +16 -8
- package/lib/commands/convert.js +0 -132
- package/lib/commands/validate.js +0 -47
- package/lib/core/flags/bundle.flags.js +0 -14
- package/lib/core/flags/config/analytics.flags.js +0 -13
- package/lib/core/flags/start/preview.flags.js +0 -15
- package/lib/core/parser.d.ts +0 -35
- package/lib/core/parser.js +0 -230
- /package/lib/{core → apps/cli/internal}/flags/bundle.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/config/analytics.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/config/context.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/convert.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/format.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/format.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/generate/models.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/global.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/file.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/template.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/template.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/optimize.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/pretty.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/pretty.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/proxy.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/start/preview.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/start/studio.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.d.ts +0 -0
- /package/lib/{core → domains}/models/Context.d.ts +0 -0
- /package/lib/{core → domains}/models/Preview.d.ts +0 -0
- /package/lib/{core → domains}/models/Studio.d.ts +0 -0
- /package/lib/{core/errors → errors}/context-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/context-error.js +0 -0
- /package/lib/{core/errors → errors}/diff-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/diff-error.js +0 -0
- /package/lib/{core/errors → errors}/generator-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/generator-error.js +0 -0
- /package/lib/{core/errors → errors}/specification-file.d.ts +0 -0
- /package/lib/{core/errors → errors}/validation-error.d.ts +0 -0
- /package/lib/{core/utils/generator.d.ts → utils/fileWatcher.d.ts} +0 -0
- /package/lib/{core/utils → utils}/scoreCalculator.d.ts +0 -0
- /package/lib/{core/utils → utils}/scoreCalculator.js +0 -0
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.successMessage = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
6
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
7
7
|
const path_1 = require("path");
|
|
8
|
-
const SpecificationFile_1 = require("
|
|
8
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
9
9
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
10
|
-
const template_flags_1 = require("../../
|
|
10
|
+
const template_flags_1 = require("../../internal/flags/new/template.flags");
|
|
11
11
|
const picocolors_1 = require("picocolors");
|
|
12
12
|
const jsonfile_1 = tslib_1.__importDefault(require("jsonfile"));
|
|
13
13
|
const path_2 = tslib_1.__importDefault(require("path"));
|
|
@@ -35,9 +35,9 @@ class template extends base_1.default {
|
|
|
35
35
|
run() {
|
|
36
36
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
const { flags } = yield this.parse(template); // NOSONAR
|
|
38
|
-
const { name: projectName, template: templateName
|
|
38
|
+
const { name: projectName, template: templateName } = flags;
|
|
39
39
|
const PROJECT_DIRECTORY = (0, path_1.join)(process.cwd(), projectName);
|
|
40
|
-
const templateDirectory = (0, path_1.resolve)(__dirname, '
|
|
40
|
+
const templateDirectory = (0, path_1.resolve)(__dirname, '../../../../../assets/create-template/templates/', templateName);
|
|
41
41
|
{
|
|
42
42
|
try {
|
|
43
43
|
yield fs_1.promises.mkdir(PROJECT_DIRECTORY);
|
|
@@ -82,16 +82,18 @@ function copyAndModify(templateDirectory, PROJECT_DIRECTORY, projectName) {
|
|
|
82
82
|
yield fs_extra_1.default.copy(templateDirectory, PROJECT_DIRECTORY, {
|
|
83
83
|
filter: (src) => {
|
|
84
84
|
return !src.endsWith('package.json');
|
|
85
|
-
}
|
|
85
|
+
},
|
|
86
86
|
});
|
|
87
87
|
const packageData = yield jsonfile_1.default.readFile(packageJsonPath);
|
|
88
|
-
if (
|
|
88
|
+
if (packageData.generator && 'renderer' in packageData.generator) {
|
|
89
89
|
packageData.generator.renderer = 'react';
|
|
90
90
|
}
|
|
91
91
|
if (packageData.name) {
|
|
92
92
|
packageData.name = projectName;
|
|
93
93
|
}
|
|
94
|
-
yield fs_extra_1.default.writeJSON(`${PROJECT_DIRECTORY}/package.json`, packageData, {
|
|
94
|
+
yield fs_extra_1.default.writeJSON(`${PROJECT_DIRECTORY}/package.json`, packageData, {
|
|
95
|
+
spaces: 2,
|
|
96
|
+
});
|
|
95
97
|
}
|
|
96
98
|
catch (err) {
|
|
97
99
|
console.error('Error:', err);
|
|
@@ -4,15 +4,15 @@ exports.Outputs = exports.DisableOptimizations = exports.Optimizations = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
6
|
const optimizer_1 = require("@asyncapi/optimizer");
|
|
7
|
-
const base_1 = tslib_1.__importDefault(require("../
|
|
8
|
-
const validation_error_1 = require("
|
|
9
|
-
const SpecificationFile_1 = require("
|
|
7
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
8
|
+
const validation_error_1 = require("../../../errors/validation-error");
|
|
9
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
10
10
|
const inquirer = tslib_1.__importStar(require("inquirer"));
|
|
11
11
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
12
12
|
const fs_1 = require("fs");
|
|
13
13
|
const parser_1 = require("@asyncapi/parser");
|
|
14
|
-
const optimize_flags_1 = require("../
|
|
15
|
-
const proxy_flags_1 = require("../
|
|
14
|
+
const optimize_flags_1 = require("../internal/flags/optimize.flags");
|
|
15
|
+
const proxy_flags_1 = require("../internal/flags/proxy.flags");
|
|
16
16
|
const { writeFile } = fs_1.promises;
|
|
17
17
|
var Optimizations;
|
|
18
18
|
(function (Optimizations) {
|
|
@@ -63,7 +63,7 @@ class Optimize extends base_1.default {
|
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
this.error(new validation_error_1.ValidationError({
|
|
66
|
-
type: 'no-spec-found'
|
|
66
|
+
type: 'no-spec-found',
|
|
67
67
|
}));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -84,7 +84,9 @@ class Optimize extends base_1.default {
|
|
|
84
84
|
this.disableOptimizations = flags.ignore;
|
|
85
85
|
this.outputMethod = flags.output;
|
|
86
86
|
this.metricsMetadata.optimized = false;
|
|
87
|
-
if (!(((_a = report.moveDuplicatesToComponents) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
87
|
+
if (!(((_a = report.moveDuplicatesToComponents) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
88
|
+
((_b = report.removeComponents) === null || _b === void 0 ? void 0 : _b.length) ||
|
|
89
|
+
((_c = report.reuseComponents) === null || _c === void 0 ? void 0 : _c.length))) {
|
|
88
90
|
this.log(`🎉 Great news! Your file at ${(_d = this.specFile.getFilePath()) !== null && _d !== void 0 ? _d : this.specFile.getFileURL()} is already optimized.`);
|
|
89
91
|
return;
|
|
90
92
|
}
|
|
@@ -93,16 +95,18 @@ class Optimize extends base_1.default {
|
|
|
93
95
|
yield this.interactiveRun(report);
|
|
94
96
|
}
|
|
95
97
|
try {
|
|
96
|
-
const optimizedDocument = optimizer.getOptimizedDocument({
|
|
98
|
+
const optimizedDocument = optimizer.getOptimizedDocument({
|
|
99
|
+
rules: {
|
|
97
100
|
moveDuplicatesToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_DUPLICATES_TO_COMPONENTS),
|
|
98
101
|
moveAllToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_ALL_TO_COMPONENTS),
|
|
99
102
|
removeComponents: this.selectedOptimizations.includes(Optimizations.REMOVE_COMPONENTS),
|
|
100
|
-
reuseComponents: this.selectedOptimizations.includes(Optimizations.REUSE_COMPONENTS)
|
|
103
|
+
reuseComponents: this.selectedOptimizations.includes(Optimizations.REUSE_COMPONENTS),
|
|
101
104
|
},
|
|
102
105
|
disableOptimizationFor: {
|
|
103
|
-
schema: this.disableOptimizations.includes(DisableOptimizations.SCHEMA)
|
|
106
|
+
schema: this.disableOptimizations.includes(DisableOptimizations.SCHEMA),
|
|
104
107
|
},
|
|
105
|
-
output: optimizer_1.Output.YAML
|
|
108
|
+
output: optimizer_1.Output.YAML,
|
|
109
|
+
});
|
|
106
110
|
this.collectMetricsData(report);
|
|
107
111
|
const specPath = this.specFile.getFilePath();
|
|
108
112
|
let newPath = '';
|
|
@@ -123,7 +127,9 @@ class Optimize extends base_1.default {
|
|
|
123
127
|
this.log(`✅ Success! Your optimized file has been created at ${chalk_1.default.blue({ newPath })}.`);
|
|
124
128
|
break;
|
|
125
129
|
case Outputs.OVERWRITE:
|
|
126
|
-
yield writeFile(specPath !== null && specPath !== void 0 ? specPath : 'asyncapi.yaml', optimizedDocument, {
|
|
130
|
+
yield writeFile(specPath !== null && specPath !== void 0 ? specPath : 'asyncapi.yaml', optimizedDocument, {
|
|
131
|
+
encoding: 'utf8',
|
|
132
|
+
});
|
|
127
133
|
this.log(`✅ Success! Your original file at ${specPath} has been updated.`);
|
|
128
134
|
break;
|
|
129
135
|
}
|
|
@@ -166,63 +172,95 @@ class Optimize extends base_1.default {
|
|
|
166
172
|
const totalMove = (_e = report.moveAllToComponents) === null || _e === void 0 ? void 0 : _e.filter((e) => e.action === 'move').length;
|
|
167
173
|
this.log(`${chalk_1.default.green(totalMove)} components can be moved to the components sections.\nthe following changes will be made:`);
|
|
168
174
|
this.showOptimizations(report.moveAllToComponents);
|
|
169
|
-
choices.push({
|
|
175
|
+
choices.push({
|
|
176
|
+
name: 'move all $refs to components section',
|
|
177
|
+
value: Optimizations.MOVE_ALL_TO_COMPONENTS,
|
|
178
|
+
});
|
|
170
179
|
}
|
|
171
180
|
if (canMoveDuplicates) {
|
|
172
181
|
const totalMove = (_f = report.moveDuplicatesToComponents) === null || _f === void 0 ? void 0 : _f.filter((e) => e.action === 'move').length;
|
|
173
182
|
this.log(`\n${chalk_1.default.green(totalMove)} components can be moved to the components sections.\nthe following changes will be made:`);
|
|
174
183
|
this.showOptimizations(report.moveDuplicatesToComponents);
|
|
175
|
-
choices.push({
|
|
184
|
+
choices.push({
|
|
185
|
+
name: 'move to components section',
|
|
186
|
+
value: Optimizations.MOVE_DUPLICATES_TO_COMPONENTS,
|
|
187
|
+
});
|
|
176
188
|
}
|
|
177
189
|
if (canRemove) {
|
|
178
190
|
const totalMove = (_g = report.removeComponents) === null || _g === void 0 ? void 0 : _g.length;
|
|
179
191
|
this.log(`${chalk_1.default.green(totalMove)} unused components can be removed.\nthe following changes will be made:`);
|
|
180
192
|
this.showOptimizations(report.removeComponents);
|
|
181
|
-
choices.push({
|
|
193
|
+
choices.push({
|
|
194
|
+
name: 'remove components',
|
|
195
|
+
value: Optimizations.REMOVE_COMPONENTS,
|
|
196
|
+
});
|
|
182
197
|
}
|
|
183
198
|
if (canReuse) {
|
|
184
199
|
const totalMove = (_h = report.reuseComponents) === null || _h === void 0 ? void 0 : _h.length;
|
|
185
200
|
this.log(`${chalk_1.default.green(totalMove)} components can be reused.\nthe following changes will be made:`);
|
|
186
201
|
this.showOptimizations(report.reuseComponents);
|
|
187
|
-
choices.push({
|
|
202
|
+
choices.push({
|
|
203
|
+
name: 'reuse components',
|
|
204
|
+
value: Optimizations.REUSE_COMPONENTS,
|
|
205
|
+
});
|
|
188
206
|
}
|
|
189
207
|
if ((_j = this.disableOptimizations) === null || _j === void 0 ? void 0 : _j.includes(DisableOptimizations.SCHEMA)) {
|
|
190
|
-
choices.push({
|
|
208
|
+
choices.push({
|
|
209
|
+
name: 'Do not ignore schema',
|
|
210
|
+
value: DisableOptimizations.SCHEMA,
|
|
211
|
+
});
|
|
191
212
|
}
|
|
192
213
|
else {
|
|
193
|
-
choices.push({
|
|
214
|
+
choices.push({
|
|
215
|
+
name: 'Ignore schema',
|
|
216
|
+
value: DisableOptimizations.SCHEMA,
|
|
217
|
+
});
|
|
194
218
|
}
|
|
195
|
-
const optimizationRes = yield inquirer.prompt([
|
|
219
|
+
const optimizationRes = yield inquirer.prompt([
|
|
220
|
+
{
|
|
196
221
|
name: 'optimization',
|
|
197
222
|
message: 'select the type of optimization that you want to apply:',
|
|
198
223
|
type: 'checkbox',
|
|
199
224
|
default: 'all',
|
|
200
|
-
choices
|
|
201
|
-
}
|
|
225
|
+
choices,
|
|
226
|
+
},
|
|
227
|
+
]);
|
|
202
228
|
if (optimizationRes.optimization.includes('schema')) {
|
|
203
229
|
if ((_k = this.disableOptimizations) === null || _k === void 0 ? void 0 : _k.includes(DisableOptimizations.SCHEMA)) {
|
|
204
|
-
this.disableOptimizations = (_l = this.disableOptimizations) === null || _l === void 0 ? void 0 : _l.filter(opt => opt !== DisableOptimizations.SCHEMA);
|
|
230
|
+
this.disableOptimizations = (_l = this.disableOptimizations) === null || _l === void 0 ? void 0 : _l.filter((opt) => opt !== DisableOptimizations.SCHEMA);
|
|
205
231
|
}
|
|
206
232
|
else {
|
|
207
|
-
this.disableOptimizations = [
|
|
233
|
+
this.disableOptimizations = [
|
|
234
|
+
...(this.disableOptimizations || []),
|
|
235
|
+
DisableOptimizations.SCHEMA,
|
|
236
|
+
];
|
|
208
237
|
}
|
|
209
238
|
}
|
|
210
239
|
this.selectedOptimizations = optimizationRes.optimization;
|
|
211
|
-
const outputRes = yield inquirer.prompt([
|
|
240
|
+
const outputRes = yield inquirer.prompt([
|
|
241
|
+
{
|
|
212
242
|
name: 'output',
|
|
213
243
|
message: 'where do you want to save the result:',
|
|
214
244
|
type: 'list',
|
|
215
245
|
default: 'log to terminal',
|
|
216
|
-
choices: [
|
|
217
|
-
|
|
246
|
+
choices: [
|
|
247
|
+
{ name: 'log to terminal', value: Outputs.TERMINAL },
|
|
248
|
+
{ name: 'create new file', value: Outputs.NEW_FILE },
|
|
249
|
+
{ name: 'update original file', value: Outputs.OVERWRITE },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
218
253
|
this.outputMethod = outputRes.output;
|
|
219
254
|
});
|
|
220
255
|
}
|
|
221
256
|
collectMetricsData(report) {
|
|
222
257
|
var _a;
|
|
223
258
|
for (const availableOptimization in report) {
|
|
224
|
-
const availableOptimizationKebabCase = availableOptimization
|
|
225
|
-
|
|
259
|
+
const availableOptimizationKebabCase = availableOptimization
|
|
260
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
261
|
+
.toLowerCase(); // optimization flags are kebab case
|
|
262
|
+
if (availableOptimization.length &&
|
|
263
|
+
((_a = this.selectedOptimizations) === null || _a === void 0 ? void 0 : _a.includes(availableOptimizationKebabCase))) {
|
|
226
264
|
this.metricsMetadata[`optimization_${availableOptimization}`] = true;
|
|
227
265
|
this.metricsMetadata.optimized = true;
|
|
228
266
|
}
|
|
@@ -235,10 +273,13 @@ Optimize.examples = [
|
|
|
235
273
|
'asyncapi optimize ./asyncapi.yaml --no-tty',
|
|
236
274
|
'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --optimization=reuse-components --optimization=move-all-to-components --no-tty',
|
|
237
275
|
'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty',
|
|
238
|
-
'asyncapi optimize ./asyncapi.yaml --ignore=schema'
|
|
276
|
+
'asyncapi optimize ./asyncapi.yaml --ignore=schema',
|
|
239
277
|
];
|
|
240
278
|
Optimize.flags = Object.assign(Object.assign({}, (0, optimize_flags_1.optimizeFlags)()), (0, proxy_flags_1.proxyFlags)());
|
|
241
279
|
Optimize.args = {
|
|
242
|
-
'spec-file': core_1.Args.string({
|
|
280
|
+
'spec-file': core_1.Args.string({
|
|
281
|
+
description: 'spec path, url, or context-name',
|
|
282
|
+
required: false,
|
|
283
|
+
}),
|
|
243
284
|
};
|
|
244
285
|
exports.default = Optimize;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Command from '../
|
|
1
|
+
import Command from '../internal/base';
|
|
2
2
|
export default class Pretty extends Command {
|
|
3
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[];
|
|
@@ -4,10 +4,10 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const yaml = tslib_1.__importStar(require("yaml"));
|
|
7
|
-
const base_1 = tslib_1.__importDefault(require("../
|
|
8
|
-
const SpecificationFile_1 = require("
|
|
9
|
-
const validation_error_1 = require("
|
|
10
|
-
const pretty_flags_1 = require("../
|
|
7
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
8
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
9
|
+
const validation_error_1 = require("../../../errors/validation-error");
|
|
10
|
+
const pretty_flags_1 = require("../internal/flags/pretty.flags");
|
|
11
11
|
class Pretty extends base_1.default {
|
|
12
12
|
run() {
|
|
13
13
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -62,6 +62,9 @@ Pretty.examples = [
|
|
|
62
62
|
];
|
|
63
63
|
Pretty.flags = (0, pretty_flags_1.prettyFlags)();
|
|
64
64
|
Pretty.args = {
|
|
65
|
-
'spec-file': core_1.Args.string({
|
|
65
|
+
'spec-file': core_1.Args.string({
|
|
66
|
+
description: 'spec path, url, or context-name',
|
|
67
|
+
required: true,
|
|
68
|
+
}),
|
|
66
69
|
};
|
|
67
70
|
exports.default = Pretty;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
|
+
export default class Api extends Command {
|
|
3
|
+
static readonly description = "starts the AsyncAPI server API.";
|
|
4
|
+
static readonly flags: {
|
|
5
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
|
+
mode: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
};
|
|
9
|
+
static readonly args: {};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
process.env['NODE_CONFIG_DIR'] = `${__dirname}/../../../api/configs`;
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
6
|
+
const api_flags_1 = require("../../internal/flags/start/api.flags");
|
|
7
|
+
const app_1 = require("../../../../apps/api/app");
|
|
8
|
+
const api_1 = require("../../../../apps/api");
|
|
9
|
+
class Api extends base_1.default {
|
|
10
|
+
run() {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const { flags } = yield this.parse(Api);
|
|
13
|
+
const app = new app_1.App(api_1.CONTROLLERS, flags.port || 3000, // Default port if not specified
|
|
14
|
+
flags.mode);
|
|
15
|
+
yield app.init();
|
|
16
|
+
app.listen();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
Api.description = 'starts the AsyncAPI server API.';
|
|
21
|
+
Api.flags = (0, api_flags_1.apiFlags)();
|
|
22
|
+
Api.args = {};
|
|
23
|
+
exports.default = Api;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
6
|
class Start extends base_1.default {
|
|
7
7
|
run() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Command from '../../
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
2
|
export default class PreviewStudio extends Command {
|
|
3
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
4
|
static readonly flags: {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
6
|
-
const preview_flags_1 = require("../../
|
|
7
|
-
const SpecificationFile_1 = require("
|
|
8
|
-
const Preview_1 = require("
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
6
|
+
const preview_flags_1 = require("../../internal/flags/start/preview.flags");
|
|
7
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
8
|
+
const Preview_1 = require("../../../../domains/models/Preview");
|
|
9
9
|
class PreviewStudio extends base_1.default {
|
|
10
10
|
run() {
|
|
11
11
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -14,7 +14,7 @@ class PreviewStudio extends base_1.default {
|
|
|
14
14
|
let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
|
|
15
15
|
const previewPort = flags.port;
|
|
16
16
|
if (!filePath) {
|
|
17
|
-
filePath = (
|
|
17
|
+
filePath = (yield (0, SpecificationFile_1.load)()).getFilePath();
|
|
18
18
|
this.log(`Loaded the specification from: ${filePath}`);
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
@@ -33,6 +33,9 @@ class PreviewStudio extends base_1.default {
|
|
|
33
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
34
|
PreviewStudio.flags = (0, preview_flags_1.previewFlags)();
|
|
35
35
|
PreviewStudio.args = {
|
|
36
|
-
'spec-file': core_1.Args.string({
|
|
36
|
+
'spec-file': core_1.Args.string({
|
|
37
|
+
description: 'the path to the file to be opened with studio or context name',
|
|
38
|
+
required: true,
|
|
39
|
+
}),
|
|
37
40
|
};
|
|
38
41
|
exports.default = PreviewStudio;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
5
|
-
const Studio_1 = require("
|
|
6
|
-
const SpecificationFile_1 = require("
|
|
7
|
-
const studio_flags_1 = require("../../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
|
+
const Studio_1 = require("../../../../domains/models/Studio");
|
|
6
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
7
|
+
const studio_flags_1 = require("../../internal/flags/start/studio.flags");
|
|
8
8
|
const core_1 = require("@oclif/core");
|
|
9
9
|
const prompts_1 = require("@clack/prompts");
|
|
10
10
|
class StartStudio extends base_1.default {
|
|
@@ -25,7 +25,7 @@ class StartStudio extends base_1.default {
|
|
|
25
25
|
}
|
|
26
26
|
if (!filePath) {
|
|
27
27
|
try {
|
|
28
|
-
filePath = (
|
|
28
|
+
filePath = (yield (0, SpecificationFile_1.load)()).getFilePath();
|
|
29
29
|
this.log(`Loaded specification from: ${filePath}`);
|
|
30
30
|
}
|
|
31
31
|
catch (error) {
|
|
@@ -72,7 +72,7 @@ class StartStudio extends base_1.default {
|
|
|
72
72
|
message: 'Enter the port in which to start Studio',
|
|
73
73
|
defaultValue: '3210',
|
|
74
74
|
placeholder: '3210',
|
|
75
|
-
validate: (value) =>
|
|
75
|
+
validate: (value) => !value ? 'The port number is required' : undefined,
|
|
76
76
|
}));
|
|
77
77
|
}
|
|
78
78
|
if ((0, prompts_1.isCancel)(port)) {
|
|
@@ -86,6 +86,9 @@ class StartStudio extends base_1.default {
|
|
|
86
86
|
StartStudio.description = 'starts a new local instance of Studio';
|
|
87
87
|
StartStudio.flags = (0, studio_flags_1.studioFlags)();
|
|
88
88
|
StartStudio.args = {
|
|
89
|
-
'spec-file': core_1.Args.string({
|
|
89
|
+
'spec-file': core_1.Args.string({
|
|
90
|
+
description: 'spec path, url, or context-name',
|
|
91
|
+
required: false,
|
|
92
|
+
}),
|
|
90
93
|
};
|
|
91
94
|
exports.default = StartStudio;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import Command from '../
|
|
1
|
+
import Command from '../internal/base';
|
|
2
2
|
export default class Validate extends Command {
|
|
3
3
|
static description: string;
|
|
4
|
+
private validationService;
|
|
4
5
|
static flags: {
|
|
5
6
|
proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
6
7
|
proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
@@ -9,7 +10,7 @@ export default class Validate extends Command {
|
|
|
9
10
|
suppressAllWarnings: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
11
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
12
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
12
|
-
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"
|
|
13
|
+
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
13
14
|
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
15
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
15
16
|
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
@@ -18,4 +19,5 @@ export default class Validate extends Command {
|
|
|
18
19
|
'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
19
20
|
};
|
|
20
21
|
run(): Promise<void>;
|
|
22
|
+
private handleDiagnostics;
|
|
21
23
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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("../internal/base"));
|
|
6
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
7
|
+
const globals_1 = require("../internal/globals");
|
|
8
|
+
const validate_flags_1 = require("../internal/flags/validate.flags");
|
|
9
|
+
const proxy_flags_1 = require("../internal/flags/proxy.flags");
|
|
10
|
+
const validation_service_1 = require("../../../domains/services/validation.service");
|
|
11
|
+
class Validate extends base_1.default {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.validationService = new validation_service_1.ValidationService();
|
|
15
|
+
}
|
|
16
|
+
run() {
|
|
17
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
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
|
+
}
|
|
27
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
28
|
+
const watchMode = flags.watch;
|
|
29
|
+
if (watchMode) {
|
|
30
|
+
(0, globals_1.specWatcher)({
|
|
31
|
+
spec: this.specFile,
|
|
32
|
+
handler: this,
|
|
33
|
+
handlerName: 'validate',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// Prepare validate options
|
|
37
|
+
const validateOptions = Object.assign(Object.assign({}, flags), { suppressWarnings: flags['suppressWarnings'], suppressAllWarnings: flags['suppressAllWarnings'] });
|
|
38
|
+
const result = yield this.validationService.validateDocument(this.specFile, validateOptions);
|
|
39
|
+
if (!result.success) {
|
|
40
|
+
this.error(result.error || 'Validation failed', { exit: 1 });
|
|
41
|
+
}
|
|
42
|
+
this.metricsMetadata.validation_result = result;
|
|
43
|
+
if (flags['score']) {
|
|
44
|
+
this.log(`The score of the asyncapi document is ${(_a = result.data) === null || _a === void 0 ? void 0 : _a.score}`);
|
|
45
|
+
}
|
|
46
|
+
if (flags['log-diagnostics']) {
|
|
47
|
+
yield this.handleDiagnostics(result, flags);
|
|
48
|
+
}
|
|
49
|
+
if (((_b = result.data) === null || _b === void 0 ? void 0 : _b.status) === validation_service_1.ValidationStatus.INVALID) {
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
handleDiagnostics(result, flags) {
|
|
55
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
57
|
+
const diagnosticsFormat = (_a = flags['diagnostics-format']) !== null && _a !== void 0 ? _a : 'stylish';
|
|
58
|
+
const hasIssues = (_c = (((_b = result.data) === null || _b === void 0 ? void 0 : _b.diagnostics) && result.data.diagnostics.length > 0)) !== null && _c !== void 0 ? _c : false;
|
|
59
|
+
const isFailSeverity = ((_d = result.data) === null || _d === void 0 ? void 0 : _d.status) === validation_service_1.ValidationStatus.INVALID;
|
|
60
|
+
const sourceString = ((_e = this.specFile) === null || _e === void 0 ? void 0 : _e.toSourceString()) || '';
|
|
61
|
+
const governanceMessage = this.validationService.generateGovernanceMessage(sourceString, hasIssues, isFailSeverity);
|
|
62
|
+
if (isFailSeverity) {
|
|
63
|
+
this.logToStderr(governanceMessage);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.log(governanceMessage);
|
|
67
|
+
}
|
|
68
|
+
const diagnosticsOutput = this.validationService.formatDiagnosticsOutput(((_f = result.data) === null || _f === void 0 ? void 0 : _f.diagnostics) || [], diagnosticsFormat, (_g = flags['fail-severity']) !== null && _g !== void 0 ? _g : 'error');
|
|
69
|
+
if (flags.output) {
|
|
70
|
+
const { success, error } = yield this.validationService.saveDiagnosticsToFile(flags.output, diagnosticsFormat, diagnosticsOutput);
|
|
71
|
+
if (!success) {
|
|
72
|
+
this.logToStderr(error || 'Failed to save diagnostics to file', {
|
|
73
|
+
exit: 1,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.log(`Diagnostics saved to ${flags.output}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.log(diagnosticsOutput);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
Validate.description = 'validate asyncapi file';
|
|
87
|
+
Validate.flags = Object.assign(Object.assign({}, (0, validate_flags_1.validateFlags)()), (0, proxy_flags_1.proxyFlags)());
|
|
88
|
+
Validate.args = {
|
|
89
|
+
'spec-file': core_1.Args.string({
|
|
90
|
+
description: 'spec path, url, or context-name',
|
|
91
|
+
required: false,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
exports.default = Validate;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
import { MetricMetadata, Recorder } from '@smoya/asyncapi-adoption-metrics';
|
|
3
3
|
import { Parser } from '@asyncapi/parser';
|
|
4
|
-
import { Specification } from '
|
|
4
|
+
import { Specification } from '../../../domains/models/SpecificationFile';
|
|
5
5
|
export default abstract class extends Command {
|
|
6
6
|
recorder: Promise<Recorder>;
|
|
7
7
|
parser: Parser;
|
|
@@ -60,6 +60,7 @@ class default_1 extends core_1.Command {
|
|
|
60
60
|
try {
|
|
61
61
|
const { document } = yield this.parser.parse(rawDocument);
|
|
62
62
|
if (document !== undefined) {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
63
64
|
// @ts-ignore
|
|
64
65
|
metadata = (0, asyncapi_adoption_metrics_1.MetadataFromDocument)(document, metadata);
|
|
65
66
|
}
|
|
@@ -132,13 +133,19 @@ class default_1 extends core_1.Command {
|
|
|
132
133
|
recorderFromEnv(prefix) {
|
|
133
134
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
134
135
|
let sink = new DiscardSink();
|
|
135
|
-
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH ||
|
|
136
|
+
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH ||
|
|
137
|
+
(0, path_1.join)((0, os_1.homedir)(), '.asyncapi-analytics');
|
|
136
138
|
if (!(0, fs_extra_1.existsSync)(analyticsConfigFile)) {
|
|
137
|
-
yield writeFile(analyticsConfigFile, JSON.stringify({
|
|
139
|
+
yield writeFile(analyticsConfigFile, JSON.stringify({
|
|
140
|
+
analyticsEnabled: 'true',
|
|
141
|
+
infoMessageShown: 'false',
|
|
142
|
+
userID: (0, uuid_1.v4)(),
|
|
143
|
+
}), { encoding: 'utf8' });
|
|
138
144
|
}
|
|
139
145
|
const analyticsConfigFileContent = JSON.parse(yield readFile((0, path_1.resolve)(analyticsConfigFile), { encoding: 'utf8' }));
|
|
140
146
|
this.metricsMetadata['user'] = analyticsConfigFileContent.userID;
|
|
141
|
-
if (analyticsConfigFileContent.analyticsEnabled !== 'false' &&
|
|
147
|
+
if (analyticsConfigFileContent.analyticsEnabled !== 'false' &&
|
|
148
|
+
process.env.CI !== 'true') {
|
|
142
149
|
switch (process.env.NODE_ENV) {
|
|
143
150
|
case 'development':
|
|
144
151
|
// NODE_ENV set to `development` in bin/run
|
|
@@ -149,7 +156,8 @@ class default_1 extends core_1.Command {
|
|
|
149
156
|
break;
|
|
150
157
|
case 'production':
|
|
151
158
|
// NODE_ENV set to `production` in bin/run_bin, which is specified in 'bin' package.json section
|
|
152
|
-
sink = new asyncapi_adoption_metrics_1.NewRelicSink(process.env.ASYNCAPI_METRICS_NEWRELIC_KEY ||
|
|
159
|
+
sink = new asyncapi_adoption_metrics_1.NewRelicSink(process.env.ASYNCAPI_METRICS_NEWRELIC_KEY ||
|
|
160
|
+
'eu01xx73a8521047150dd9414f6aedd2FFFFNRAL');
|
|
153
161
|
if (analyticsConfigFileContent.infoMessageShown === 'false') {
|
|
154
162
|
this.log('\nAsyncAPI anonymously tracks command executions to improve the specification and tools, ensuring no sensitive data reaches our servers. It aids in comprehending how AsyncAPI tools are used and adopted, facilitating ongoing improvements to our specifications and tools.\n\nTo disable tracking, please run the following command:\n asyncapi config analytics --disable\n\nOnce disabled, if you want to enable tracking back again then run:\n asyncapi config analytics --enable\n');
|
|
155
163
|
analyticsConfigFileContent.infoMessageShown = 'true';
|