@asyncapi/cli 3.1.1 → 3.3.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/README.md +4 -0
- package/assets/create-glee-app/templates/default/package-lock.json +1185 -676
- package/assets/create-glee-app/templates/tutorial/package-lock.json +1148 -554
- package/assets/create-template/templates/default/package-lock.json +55 -132
- 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 +6 -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 +3 -1
- package/lib/{core → apps/cli/internal}/flags/validate.flags.js +11 -3
- 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 +124 -1
- package/package.json +37 -22
- package/lib/commands/convert.js +0 -132
- package/lib/commands/validate.js +0 -45
- 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 -33
- package/lib/core/parser.js +0 -176
- /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
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.analyticsFlags = void 0;
|
|
4
|
-
const core_1 = require("@oclif/core");
|
|
5
|
-
const analyticsFlags = () => {
|
|
6
|
-
return {
|
|
7
|
-
help: core_1.Flags.help({ char: 'h' }),
|
|
8
|
-
disable: core_1.Flags.boolean({ char: 'd', description: 'disable analytics', default: false }),
|
|
9
|
-
enable: core_1.Flags.boolean({ char: 'e', description: 'enable analytics', default: false }),
|
|
10
|
-
status: core_1.Flags.boolean({ char: 's', description: 'show current status of analytics' }),
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
exports.analyticsFlags = analyticsFlags;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.previewFlags = void 0;
|
|
4
|
-
const core_1 = require("@oclif/core");
|
|
5
|
-
const previewFlags = () => {
|
|
6
|
-
return {
|
|
7
|
-
help: core_1.Flags.help({ char: 'h' }),
|
|
8
|
-
port: core_1.Flags.integer({ char: 'p', description: 'port in which to start Studio in the preview mode' }),
|
|
9
|
-
base: core_1.Flags.string({ char: 'b', description: 'Path to the file which will act as a base. This is required when some properties need to be overwritten while bundling with the file.' }),
|
|
10
|
-
baseDir: core_1.Flags.string({ char: 'd', description: 'One relative/absolute path to directory relative to which paths to AsyncAPI Documents that should be bundled will be resolved.' }),
|
|
11
|
-
xOrigin: core_1.Flags.boolean({ char: 'x', description: 'Pass this switch to generate properties "x-origin" that will contain historical values of dereferenced "$ref"s.' }),
|
|
12
|
-
suppressLogs: core_1.Flags.boolean({ char: 'l', description: 'Pass this to suppress the detiled error logs.', default: false })
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
exports.previewFlags = previewFlags;
|
package/lib/core/parser.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { convertToOldAPI } from '@asyncapi/parser/cjs';
|
|
2
|
-
import { OutputFormat } from '@stoplight/spectral-cli/dist/services/config';
|
|
3
|
-
import type { Diagnostic } from '@asyncapi/parser/cjs';
|
|
4
|
-
import type Command from './base';
|
|
5
|
-
import type { Specification } from './models/SpecificationFile';
|
|
6
|
-
export type SeverityKind = 'error' | 'warn' | 'info' | 'hint';
|
|
7
|
-
export { convertToOldAPI };
|
|
8
|
-
export interface ValidationFlagsOptions {
|
|
9
|
-
logDiagnostics?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare enum ValidationStatus {
|
|
12
|
-
INVALID = "invalid",
|
|
13
|
-
VALID = "valid"
|
|
14
|
-
}
|
|
15
|
-
export declare function validationFlags({ logDiagnostics }?: ValidationFlagsOptions): {
|
|
16
|
-
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
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<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
|
-
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
|
-
};
|
|
21
|
-
export interface ValidateOptions {
|
|
22
|
-
'log-diagnostics'?: boolean;
|
|
23
|
-
'diagnostics-format'?: `${OutputFormat}`;
|
|
24
|
-
'fail-severity'?: SeverityKind;
|
|
25
|
-
'output'?: string;
|
|
26
|
-
}
|
|
27
|
-
export declare function validate(command: Command, specFile: Specification, options?: ValidateOptions): Promise<"invalid" | "valid">;
|
|
28
|
-
export declare function parse(command: Command, specFile: Specification, options?: ValidateOptions): Promise<{
|
|
29
|
-
document: import("@asyncapi/parser/cjs").AsyncAPIDocumentInterface | undefined;
|
|
30
|
-
diagnostics: import("@stoplight/spectral-core").ISpectralDiagnostic[];
|
|
31
|
-
status: "invalid" | "valid";
|
|
32
|
-
}>;
|
|
33
|
-
export declare function formatOutput(diagnostics: Diagnostic[], format: `${OutputFormat}`, failSeverity: SeverityKind): string;
|
package/lib/core/parser.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationStatus = exports.convertToOldAPI = void 0;
|
|
4
|
-
exports.validationFlags = validationFlags;
|
|
5
|
-
exports.validate = validate;
|
|
6
|
-
exports.parse = parse;
|
|
7
|
-
exports.formatOutput = formatOutput;
|
|
8
|
-
const tslib_1 = require("tslib");
|
|
9
|
-
const avro_schema_parser_1 = require("@asyncapi/avro-schema-parser");
|
|
10
|
-
const openapi_schema_parser_1 = require("@asyncapi/openapi-schema-parser");
|
|
11
|
-
const cjs_1 = require("@asyncapi/parser/cjs");
|
|
12
|
-
Object.defineProperty(exports, "convertToOldAPI", { enumerable: true, get: function () { return cjs_1.convertToOldAPI; } });
|
|
13
|
-
const raml_dt_schema_parser_1 = require("@asyncapi/raml-dt-schema-parser");
|
|
14
|
-
const core_1 = require("@oclif/core");
|
|
15
|
-
const protobuf_schema_parser_1 = require("@asyncapi/protobuf-schema-parser");
|
|
16
|
-
const spectral_core_1 = require("@stoplight/spectral-core");
|
|
17
|
-
const config_1 = require("@stoplight/spectral-cli/dist/services/config");
|
|
18
|
-
const spectral_formatters_1 = require("@stoplight/spectral-formatters");
|
|
19
|
-
const chalk_1 = require("chalk");
|
|
20
|
-
const fs_1 = require("fs");
|
|
21
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
22
|
-
const { writeFile } = fs_1.promises;
|
|
23
|
-
const formatExtensions = {
|
|
24
|
-
stylish: '.txt',
|
|
25
|
-
json: '.json',
|
|
26
|
-
junit: '.xml',
|
|
27
|
-
html: '.html',
|
|
28
|
-
text: '.txt',
|
|
29
|
-
teamcity: '.txt',
|
|
30
|
-
pretty: '.txt',
|
|
31
|
-
};
|
|
32
|
-
const validFormats = ['stylish', 'json', 'junit', 'html', 'text', 'teamcity', 'pretty'];
|
|
33
|
-
const parser = new cjs_1.Parser({
|
|
34
|
-
__unstable: {
|
|
35
|
-
resolver: {
|
|
36
|
-
cache: false,
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
parser.registerSchemaParser((0, avro_schema_parser_1.AvroSchemaParser)());
|
|
41
|
-
parser.registerSchemaParser((0, openapi_schema_parser_1.OpenAPISchemaParser)());
|
|
42
|
-
parser.registerSchemaParser((0, raml_dt_schema_parser_1.RamlDTSchemaParser)());
|
|
43
|
-
parser.registerSchemaParser((0, protobuf_schema_parser_1.ProtoBuffSchemaParser)());
|
|
44
|
-
var ValidationStatus;
|
|
45
|
-
(function (ValidationStatus) {
|
|
46
|
-
ValidationStatus["INVALID"] = "invalid";
|
|
47
|
-
ValidationStatus["VALID"] = "valid";
|
|
48
|
-
})(ValidationStatus || (exports.ValidationStatus = ValidationStatus = {}));
|
|
49
|
-
function validationFlags({ logDiagnostics = true } = {}) {
|
|
50
|
-
return {
|
|
51
|
-
'log-diagnostics': core_1.Flags.boolean({
|
|
52
|
-
description: 'log validation diagnostics or not',
|
|
53
|
-
default: logDiagnostics,
|
|
54
|
-
allowNo: true,
|
|
55
|
-
}),
|
|
56
|
-
'diagnostics-format': core_1.Flags.option({
|
|
57
|
-
description: 'format to use for validation diagnostics',
|
|
58
|
-
options: Object.values(config_1.OutputFormat),
|
|
59
|
-
default: config_1.OutputFormat.STYLISH,
|
|
60
|
-
})(),
|
|
61
|
-
'fail-severity': core_1.Flags.option({
|
|
62
|
-
description: 'diagnostics of this level or above will trigger a failure exit code',
|
|
63
|
-
options: ['error', 'warn', 'info', 'hint'],
|
|
64
|
-
default: 'error',
|
|
65
|
-
})(),
|
|
66
|
-
output: core_1.Flags.string({
|
|
67
|
-
description: 'The output file name. Omitting this flag the result will be printed in the console.',
|
|
68
|
-
char: 'o'
|
|
69
|
-
})
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function validate(command_1, specFile_1) {
|
|
73
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* (command, specFile, options = {}) {
|
|
74
|
-
const diagnostics = yield parser.validate(specFile.text(), { source: specFile.getSource() });
|
|
75
|
-
return logDiagnostics(diagnostics, command, specFile, options);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function parse(command_1, specFile_1) {
|
|
79
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* (command, specFile, options = {}) {
|
|
80
|
-
const { document, diagnostics } = yield parser.parse(specFile.text(), { source: specFile.getSource() });
|
|
81
|
-
const status = logDiagnostics(diagnostics, command, specFile, options);
|
|
82
|
-
return { document, diagnostics, status };
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function logDiagnostics(diagnostics, command, specFile, options = {}) {
|
|
86
|
-
var _a, _b;
|
|
87
|
-
const logDiagnostics = options['log-diagnostics'];
|
|
88
|
-
const failSeverity = (_a = options['fail-severity']) !== null && _a !== void 0 ? _a : 'error';
|
|
89
|
-
const diagnosticsFormat = (_b = options['diagnostics-format']) !== null && _b !== void 0 ? _b : 'stylish';
|
|
90
|
-
const sourceString = specFile.toSourceString();
|
|
91
|
-
const hasIssues = diagnostics.length > 0;
|
|
92
|
-
const isFailSeverity = hasIssues && hasFailSeverity(diagnostics, failSeverity);
|
|
93
|
-
if (logDiagnostics) {
|
|
94
|
-
logGovernanceMessage(command, sourceString, hasIssues, isFailSeverity);
|
|
95
|
-
outputDiagnostics(command, diagnostics, diagnosticsFormat, failSeverity, options);
|
|
96
|
-
}
|
|
97
|
-
return isFailSeverity ? ValidationStatus.INVALID : ValidationStatus.VALID;
|
|
98
|
-
}
|
|
99
|
-
function logGovernanceMessage(command, sourceString, hasIssues, isFailSeverity) {
|
|
100
|
-
if (!hasIssues) {
|
|
101
|
-
command.log(`\n${sourceString} is valid! ${sourceString} and referenced documents don't have governance issues.`);
|
|
102
|
-
}
|
|
103
|
-
else if (isFailSeverity) {
|
|
104
|
-
command.logToStderr(`\n${sourceString} and/or referenced documents have governance issues.`);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
command.log(`\n${sourceString} is valid but has (itself and/or referenced documents) governance issues.`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function outputDiagnostics(command, diagnostics, diagnosticsFormat, failSeverity, options) {
|
|
111
|
-
const diagnosticsOutput = formatOutput(diagnostics, diagnosticsFormat, failSeverity);
|
|
112
|
-
if (options.output) {
|
|
113
|
-
writeValidationDiagnostic(options.output, command, diagnosticsFormat, diagnosticsOutput);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
command.log(diagnosticsOutput);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function formatOutput(diagnostics, format, failSeverity) {
|
|
120
|
-
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
121
|
-
const options = { failSeverity: diagnosticSeverity !== -1 ? diagnosticSeverity : cjs_1.DiagnosticSeverity.Error };
|
|
122
|
-
switch (format) {
|
|
123
|
-
case 'stylish': return formatStylish(diagnostics, options);
|
|
124
|
-
case 'json': return (0, spectral_formatters_1.json)(diagnostics, options);
|
|
125
|
-
case 'junit': return (0, spectral_formatters_1.junit)(diagnostics, options);
|
|
126
|
-
case 'html': return (0, spectral_formatters_1.html)(diagnostics, options);
|
|
127
|
-
case 'text': return (0, spectral_formatters_1.text)(diagnostics, options);
|
|
128
|
-
case 'teamcity': return (0, spectral_formatters_1.teamcity)(diagnostics, options);
|
|
129
|
-
case 'pretty': return (0, spectral_formatters_1.pretty)(diagnostics, options);
|
|
130
|
-
default: return (0, spectral_formatters_1.stylish)(diagnostics, options);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function formatStylish(diagnostics, options) {
|
|
134
|
-
const groupedDiagnostics = diagnostics.reduce((acc, diagnostic) => {
|
|
135
|
-
const severity = diagnostic.severity;
|
|
136
|
-
if (!acc[severity]) {
|
|
137
|
-
acc[severity] = [];
|
|
138
|
-
}
|
|
139
|
-
acc[severity].push(diagnostic);
|
|
140
|
-
return acc;
|
|
141
|
-
}, {});
|
|
142
|
-
return Object.entries(groupedDiagnostics).map(([severity, diagnostics]) => {
|
|
143
|
-
return `${getSeverityTitle(Number(severity))} ${(0, spectral_formatters_1.stylish)(diagnostics, options)}`;
|
|
144
|
-
}).join('\n');
|
|
145
|
-
}
|
|
146
|
-
function getSeverityTitle(severity) {
|
|
147
|
-
switch (severity) {
|
|
148
|
-
case cjs_1.DiagnosticSeverity.Error: return (0, chalk_1.red)('Errors');
|
|
149
|
-
case cjs_1.DiagnosticSeverity.Warning: return (0, chalk_1.yellow)('Warnings');
|
|
150
|
-
case cjs_1.DiagnosticSeverity.Information: return (0, chalk_1.cyan)('Information');
|
|
151
|
-
case cjs_1.DiagnosticSeverity.Hint: return (0, chalk_1.green)('Hints');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function hasFailSeverity(diagnostics, failSeverity) {
|
|
155
|
-
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
156
|
-
return diagnostics.some(diagnostic => diagnostic.severity <= diagnosticSeverity);
|
|
157
|
-
}
|
|
158
|
-
function writeValidationDiagnostic(outputPath, command, format, formatOutput) {
|
|
159
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
if (!validFormats.includes(format)) {
|
|
161
|
-
command.logToStderr(`Invalid diagnostics format: "${format}"`);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const expectedExtension = formatExtensions[format];
|
|
165
|
-
const actualExtension = path_1.default.extname(outputPath);
|
|
166
|
-
// Validate file extension against diagnostics format
|
|
167
|
-
if (expectedExtension && (actualExtension !== expectedExtension)) {
|
|
168
|
-
command.logToStderr(`Invalid file extension for format "${format}". Expected extension: "${expectedExtension}"`);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
yield writeFile(path_1.default.resolve(process.cwd(), outputPath), formatOutput, {
|
|
172
|
-
encoding: 'utf-8',
|
|
173
|
-
}).catch(err => console.log(err));
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|