@asyncapi-actions-test/trusted-publishing-test_asyncapi-cli 4.1.3
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/LICENSE +201 -0
- package/README.md +117 -0
- package/assets/create-template/templates/default/asyncapi.yaml +34 -0
- package/assets/create-template/templates/default/package-lock.json +4062 -0
- package/assets/create-template/templates/default/package.json +10 -0
- package/assets/create-template/templates/default/readme.md +4 -0
- package/assets/create-template/templates/default/template/index.js +11 -0
- package/assets/examples/adeo-kafka-request-reply-asyncapi.yml +298 -0
- package/assets/examples/anyof-asyncapi.yml +36 -0
- package/assets/examples/application-headers-asyncapi.yml +86 -0
- package/assets/examples/correlation-id-asyncapi.yml +180 -0
- package/assets/examples/default-example.json +51 -0
- package/assets/examples/default-example.yaml +31 -0
- package/assets/examples/examples.json +82 -0
- package/assets/examples/gitter-streaming-asyncapi.yml +178 -0
- package/assets/examples/kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml +388 -0
- package/assets/examples/kraken-websocket-request-reply-multiple-channels-asyncapi.yml +394 -0
- package/assets/examples/mercure-asyncapi.yml +58 -0
- package/assets/examples/not-asyncapi.yml +29 -0
- package/assets/examples/oneof-asyncapi.yml +57 -0
- package/assets/examples/operation-security-asyncapi.yml +117 -0
- package/assets/examples/rpc-client-asyncapi.yml +72 -0
- package/assets/examples/rpc-server-asyncapi.yml +69 -0
- package/assets/examples/simple-asyncapi.yml +31 -0
- package/assets/examples/slack-rtm-asyncapi.yml +982 -0
- package/assets/examples/streetlights-kafka-asyncapi.yml +199 -0
- package/assets/examples/streetlights-mqtt-asyncapi.yml +253 -0
- package/assets/examples/streetlights-operation-security-asyncapi.yml +240 -0
- package/assets/examples/tutorial.yml +41 -0
- package/assets/examples/websocket-gemini-asyncapi.yml +301 -0
- package/assets/logo.png +0 -0
- package/assets/server-api.png +0 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +12 -0
- package/bin/run.cmd +3 -0
- package/bin/run_bin +13 -0
- package/bin/run_bin.cmd +3 -0
- package/lib/apps/api/app.d.ts +15 -0
- package/lib/apps/api/app.js +91 -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 +174 -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/controllers/version.controller.d.ts +8 -0
- package/lib/apps/api/controllers/version.controller.js +69 -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 +10 -0
- package/lib/apps/api/index.js +23 -0
- package/lib/apps/api/middlewares/logger.middleware.d.ts +2 -0
- package/lib/apps/api/middlewares/logger.middleware.js +12 -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 +245 -0
- package/lib/apps/api/server.d.ts +3 -0
- package/lib/apps/api/server.js +19 -0
- package/lib/apps/cli/commands/bundle.d.ts +15 -0
- package/lib/apps/cli/commands/bundle.js +75 -0
- package/lib/apps/cli/commands/config/analytics.d.ts +11 -0
- package/lib/apps/cli/commands/config/analytics.js +61 -0
- package/lib/apps/cli/commands/config/auth/add.d.ts +13 -0
- package/lib/apps/cli/commands/config/auth/add.js +68 -0
- package/lib/apps/cli/commands/config/context/add.d.ts +13 -0
- package/lib/apps/cli/commands/config/context/add.js +46 -0
- package/lib/apps/cli/commands/config/context/current.d.ts +8 -0
- package/lib/apps/cli/commands/config/context/current.js +37 -0
- package/lib/apps/cli/commands/config/context/edit.d.ts +12 -0
- package/lib/apps/cli/commands/config/context/edit.js +44 -0
- package/lib/apps/cli/commands/config/context/index.d.ts +5 -0
- package/lib/apps/cli/commands/config/context/index.js +16 -0
- package/lib/apps/cli/commands/config/context/init.d.ts +12 -0
- package/lib/apps/cli/commands/config/context/init.js +31 -0
- package/lib/apps/cli/commands/config/context/list.d.ts +8 -0
- package/lib/apps/cli/commands/config/context/list.js +36 -0
- package/lib/apps/cli/commands/config/context/remove.d.ts +11 -0
- package/lib/apps/cli/commands/config/context/remove.js +39 -0
- package/lib/apps/cli/commands/config/context/use.d.ts +11 -0
- package/lib/apps/cli/commands/config/context/use.js +40 -0
- package/lib/apps/cli/commands/config/index.d.ts +5 -0
- package/lib/apps/cli/commands/config/index.js +16 -0
- package/lib/apps/cli/commands/config/versions.d.ts +8 -0
- package/lib/apps/cli/commands/config/versions.js +56 -0
- package/lib/apps/cli/commands/convert.d.ts +21 -0
- package/lib/apps/cli/commands/convert.js +85 -0
- package/lib/apps/cli/commands/diff.d.ts +36 -0
- package/lib/apps/cli/commands/diff.js +335 -0
- package/lib/apps/cli/commands/format.d.ts +18 -0
- package/lib/apps/cli/commands/format.js +97 -0
- package/lib/apps/cli/commands/generate/client.d.ts +30 -0
- package/lib/apps/cli/commands/generate/client.js +94 -0
- package/lib/apps/cli/commands/generate/fromTemplate.d.ts +29 -0
- package/lib/apps/cli/commands/generate/fromTemplate.js +91 -0
- package/lib/apps/cli/commands/generate/index.d.ts +5 -0
- package/lib/apps/cli/commands/generate/index.js +15 -0
- package/lib/apps/cli/commands/generate/models.d.ts +16 -0
- package/lib/apps/cli/commands/generate/models.js +166 -0
- package/lib/apps/cli/commands/new/file.d.ts +16 -0
- package/lib/apps/cli/commands/new/file.js +180 -0
- package/lib/apps/cli/commands/new/index.d.ts +5 -0
- package/lib/apps/cli/commands/new/index.js +15 -0
- package/lib/apps/cli/commands/new/template.d.ts +18 -0
- package/lib/apps/cli/commands/new/template.js +102 -0
- package/lib/apps/cli/commands/optimize.d.ts +41 -0
- package/lib/apps/cli/commands/optimize.js +289 -0
- package/lib/apps/cli/commands/pretty.d.ts +12 -0
- package/lib/apps/cli/commands/pretty.js +70 -0
- package/lib/apps/cli/commands/start/api.d.ts +11 -0
- package/lib/apps/cli/commands/start/api.js +23 -0
- package/lib/apps/cli/commands/start/index.d.ts +5 -0
- package/lib/apps/cli/commands/start/index.js +15 -0
- package/lib/apps/cli/commands/start/preview.d.ts +17 -0
- package/lib/apps/cli/commands/start/preview.js +41 -0
- package/lib/apps/cli/commands/start/studio.d.ts +16 -0
- package/lib/apps/cli/commands/start/studio.js +94 -0
- package/lib/apps/cli/commands/validate.d.ts +23 -0
- package/lib/apps/cli/commands/validate.js +95 -0
- package/lib/apps/cli/internal/args/generate.args.d.ts +3 -0
- package/lib/apps/cli/internal/args/generate.args.js +10 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.d.ts +42 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.js +119 -0
- package/lib/apps/cli/internal/base.d.ts +20 -0
- package/lib/apps/cli/internal/base.js +173 -0
- package/lib/apps/cli/internal/flags/bundle.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.d.ts +6 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
- package/lib/apps/cli/internal/flags/config/context.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/config/context.flags.js +16 -0
- package/lib/apps/cli/internal/flags/convert.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/convert.flags.js +32 -0
- package/lib/apps/cli/internal/flags/diff.flags.d.ts +13 -0
- package/lib/apps/cli/internal/flags/diff.flags.js +29 -0
- package/lib/apps/cli/internal/flags/format.flags.d.ts +6 -0
- package/lib/apps/cli/internal/flags/format.flags.js +22 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.js +8 -0
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.js +8 -0
- package/lib/apps/cli/internal/flags/generate/models.flags.d.ts +1 -0
- package/lib/apps/cli/internal/flags/generate/models.flags.js +14 -0
- package/lib/apps/cli/internal/flags/generate/sharedFlags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/sharedFlags.js +57 -0
- package/lib/apps/cli/internal/flags/global.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/global.flags.js +18 -0
- package/lib/apps/cli/internal/flags/new/file.flags.d.ts +8 -0
- package/lib/apps/cli/internal/flags/new/file.flags.js +20 -0
- package/lib/apps/cli/internal/flags/new/template.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/new/template.flags.js +28 -0
- package/lib/apps/cli/internal/flags/optimize.flags.d.ts +21 -0
- package/lib/apps/cli/internal/flags/optimize.flags.js +51 -0
- 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/apps/cli/internal/flags/pretty.flags.d.ts +3 -0
- package/lib/apps/cli/internal/flags/pretty.flags.js +13 -0
- package/lib/apps/cli/internal/flags/proxy.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/proxy.flags.js +17 -0
- 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.d.ts +9 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.js +32 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.js +25 -0
- package/lib/apps/cli/internal/flags/validate.flags.d.ts +11 -0
- package/lib/apps/cli/internal/flags/validate.flags.js +22 -0
- package/lib/apps/cli/internal/globals.d.ts +10 -0
- package/lib/apps/cli/internal/globals.js +46 -0
- package/lib/apps/cli/internal/hooks/command_not_found/myhook.d.ts +4 -0
- package/lib/apps/cli/internal/hooks/command_not_found/myhook.js +85 -0
- package/lib/domains/models/Context.d.ts +21 -0
- package/lib/domains/models/Context.js +321 -0
- package/lib/domains/models/Preview.d.ts +2 -0
- package/lib/domains/models/Preview.js +227 -0
- package/lib/domains/models/SpecificationFile.d.ts +40 -0
- package/lib/domains/models/SpecificationFile.js +295 -0
- package/lib/domains/models/Studio.d.ts +2 -0
- package/lib/domains/models/Studio.js +182 -0
- package/lib/domains/models/generate/ClientLanguages.d.ts +12 -0
- package/lib/domains/models/generate/ClientLanguages.js +17 -0
- package/lib/domains/models/generate/Flags.d.ts +9 -0
- package/lib/domains/models/generate/Flags.js +2 -0
- 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/config.service.d.ts +42 -0
- package/lib/domains/services/config.service.js +95 -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 +75 -0
- package/lib/domains/services/validation.service.d.ts +54 -0
- package/lib/domains/services/validation.service.js +375 -0
- package/lib/errors/context-error.d.ts +26 -0
- package/lib/errors/context-error.js +71 -0
- package/lib/errors/diff-error.d.ts +9 -0
- package/lib/errors/diff-error.js +27 -0
- package/lib/errors/generator-error.d.ts +3 -0
- package/lib/errors/generator-error.js +11 -0
- package/lib/errors/specification-file.d.ts +18 -0
- package/lib/errors/specification-file.js +65 -0
- package/lib/errors/validation-error.d.ts +11 -0
- package/lib/errors/validation-error.js +55 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -0
- 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/utils/generate/flags.d.ts +2 -0
- package/lib/utils/generate/flags.js +14 -0
- package/lib/utils/generate/mapBaseUrl.d.ts +6 -0
- package/lib/utils/generate/mapBaseUrl.js +34 -0
- package/lib/utils/generate/parseParams.d.ts +3 -0
- package/lib/utils/generate/parseParams.js +58 -0
- package/lib/utils/generate/prompts.d.ts +4 -0
- package/lib/utils/generate/prompts.js +77 -0
- package/lib/utils/generate/registry.d.ts +2 -0
- package/lib/utils/generate/registry.js +30 -0
- package/lib/utils/generate/watcher.d.ts +51 -0
- package/lib/utils/generate/watcher.js +230 -0
- 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/scoreCalculator.d.ts +2 -0
- package/lib/utils/scoreCalculator.js +22 -0
- package/lib/utils/temp-dir.d.ts +2 -0
- package/lib/utils/temp-dir.js +26 -0
- package/oclif.manifest.json +2137 -0
- package/openapi.yaml +713 -0
- package/package.json +203 -0
- package/scripts/enableAutoComplete.js +160 -0
- package/scripts/fetch-asyncapi-example.js +126 -0
- package/scripts/generateTypesForGenerateCommand.js +40 -0
- package/scripts/releasePackagesRename.js +88 -0
- package/scripts/updateUsageDocs.js +73 -0
|
@@ -0,0 +1,91 @@
|
|
|
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 BaseGeneratorCommand_1 = require("../../internal/base/BaseGeneratorCommand");
|
|
6
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
7
|
+
const validation_error_1 = require("../../../../errors/validation-error");
|
|
8
|
+
const generator_error_1 = require("../../../../errors/generator-error");
|
|
9
|
+
const prompts_1 = require("@clack/prompts");
|
|
10
|
+
const picocolors_1 = require("picocolors");
|
|
11
|
+
const fromTemplate_flags_1 = require("../../internal/flags/generate/fromTemplate.flags");
|
|
12
|
+
const flags_1 = require("../../../../utils/generate/flags");
|
|
13
|
+
const prompts_2 = require("../../../../utils/generate/prompts");
|
|
14
|
+
class Template extends BaseGeneratorCommand_1.BaseGeneratorCommand {
|
|
15
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
16
|
+
run() {
|
|
17
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
const { args, flags } = yield this.parse(Template); // NOSONAR
|
|
20
|
+
const interactive = !flags['no-interactive'];
|
|
21
|
+
let asyncapi = (_a = args['asyncapi']) !== null && _a !== void 0 ? _a : '';
|
|
22
|
+
let template = (_b = args['template']) !== null && _b !== void 0 ? _b : '';
|
|
23
|
+
let output = flags.output;
|
|
24
|
+
const { proxyPort, proxyHost } = flags;
|
|
25
|
+
if (interactive) {
|
|
26
|
+
(0, prompts_1.intro)((0, picocolors_1.inverse)('AsyncAPI Generator'));
|
|
27
|
+
const parsedArgs = yield this.parseArgs(args, output);
|
|
28
|
+
asyncapi = parsedArgs.asyncapi;
|
|
29
|
+
template = parsedArgs.template;
|
|
30
|
+
output = parsedArgs.output;
|
|
31
|
+
}
|
|
32
|
+
const parsedFlags = (0, flags_1.parseGeneratorFlags)(flags['disable-hook'], flags['param'], flags['map-base-url'], flags['registry-url'], flags['registry-auth'], flags['registry-token']);
|
|
33
|
+
const options = yield this.buildGeneratorOptions(flags, parsedFlags);
|
|
34
|
+
// Apply proxy configuration using base class method
|
|
35
|
+
asyncapi = this.applyProxyConfiguration(asyncapi, proxyHost, proxyPort);
|
|
36
|
+
const asyncapiInput = yield this.loadAsyncAPIInput(asyncapi);
|
|
37
|
+
this.specFile = asyncapiInput;
|
|
38
|
+
this.metricsMetadata.template = template;
|
|
39
|
+
const watchTemplate = flags['watch'];
|
|
40
|
+
const genOption = this.buildGenOption(flags, parsedFlags);
|
|
41
|
+
let specification;
|
|
42
|
+
try {
|
|
43
|
+
specification = yield (0, SpecificationFile_1.load)(asyncapi);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
return this.error(new validation_error_1.ValidationError({
|
|
47
|
+
// eslint-disable-next-line sonarjs/no-duplicate-string
|
|
48
|
+
type: 'invalid-file',
|
|
49
|
+
filepath: asyncapi,
|
|
50
|
+
}), { exit: 1 });
|
|
51
|
+
}
|
|
52
|
+
const result = yield this.generatorService.generate(specification, template, output, options, // GeneratorService expects different options interface
|
|
53
|
+
genOption, interactive);
|
|
54
|
+
if (!result.success) {
|
|
55
|
+
throw new generator_error_1.GeneratorError(new Error(result.error));
|
|
56
|
+
}
|
|
57
|
+
// Output logs in non-interactive mode
|
|
58
|
+
if (!interactive && ((_c = result.data) === null || _c === void 0 ? void 0 : _c.logs)) {
|
|
59
|
+
for (const log of result.data.logs) {
|
|
60
|
+
this.log(log);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (watchTemplate) {
|
|
64
|
+
yield this.handleWatchMode(asyncapi, template, output, options, genOption, interactive);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
parseArgs(args, output) {
|
|
69
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
// Use base class method for common args
|
|
71
|
+
const commonArgs = yield this.parseCommonArgs(args, output);
|
|
72
|
+
let template = args['template'];
|
|
73
|
+
if (!template) {
|
|
74
|
+
template = yield (0, prompts_2.promptForTemplate)();
|
|
75
|
+
}
|
|
76
|
+
this.handleCancellation(template);
|
|
77
|
+
return {
|
|
78
|
+
asyncapi: commonArgs.asyncapi,
|
|
79
|
+
template,
|
|
80
|
+
output: commonArgs.output
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
Template.description = 'Generates whatever you want using templates compatible with AsyncAPI Generator.';
|
|
86
|
+
Template.examples = [
|
|
87
|
+
'asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --param version=1.0.0 singleFile=true --output ./docs --force-write',
|
|
88
|
+
];
|
|
89
|
+
Template.flags = Object.assign(Object.assign({}, (0, fromTemplate_flags_1.fromTemplateFlags)()), BaseGeneratorCommand_1.BaseGeneratorCommand.flags);
|
|
90
|
+
Template.args = Object.assign(Object.assign({}, BaseGeneratorCommand_1.BaseGeneratorCommand.args), { template: core_1.Args.string({ description: '- Name of the generator template like for example @asyncapi/html-template or https://github.com/asyncapi/html-template', required: false }) });
|
|
91
|
+
exports.default = Template;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
class Generate extends base_1.default {
|
|
7
|
+
run() {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const help = new core_1.Help(this.config);
|
|
10
|
+
help.showHelp(['generate', '--help']);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
Generate.description = 'Generate typed models or other things like clients, applications or docs using AsyncAPI Generator templates.';
|
|
15
|
+
exports.default = Generate;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
|
+
import { Specification } from '../../../../domains/models/SpecificationFile';
|
|
3
|
+
import { ValidationStatus } from '../../../../domains/services/validation.service';
|
|
4
|
+
import { Diagnostic } from '@asyncapi/parser/cjs';
|
|
5
|
+
export default class Models extends Command {
|
|
6
|
+
static description: string;
|
|
7
|
+
private validationService;
|
|
8
|
+
static readonly args: any;
|
|
9
|
+
static readonly flags: {
|
|
10
|
+
proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
|
+
proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
private parseArgs;
|
|
15
|
+
handleGovernanceMessage(document: Specification, diagnostics: Diagnostic[], status: ValidationStatus): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
6
|
+
const prompts_1 = require("@clack/prompts");
|
|
7
|
+
const picocolors_1 = require("picocolors");
|
|
8
|
+
const modelina_cli_1 = require("@asyncapi/modelina-cli");
|
|
9
|
+
const models_flags_1 = require("../../internal/flags/generate/models.flags");
|
|
10
|
+
const proxy_flags_1 = require("../../internal/flags/proxy.flags");
|
|
11
|
+
const validation_service_1 = require("../../../../domains/services/validation.service");
|
|
12
|
+
class Models extends base_1.default {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.validationService = new validation_service_1.ValidationService();
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
18
|
+
run() {
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const { args, flags } = yield this.parse(Models);
|
|
21
|
+
let { language, file } = args;
|
|
22
|
+
let { output } = flags;
|
|
23
|
+
const { proxyPort, proxyHost } = flags;
|
|
24
|
+
const interactive = !flags['no-interactive'];
|
|
25
|
+
if (!interactive) {
|
|
26
|
+
(0, prompts_1.intro)((0, picocolors_1.inverse)('AsyncAPI Generate Models'));
|
|
27
|
+
const parsedArgs = yield this.parseArgs(args, output);
|
|
28
|
+
language = parsedArgs.language;
|
|
29
|
+
file = parsedArgs.file;
|
|
30
|
+
output = parsedArgs.output;
|
|
31
|
+
}
|
|
32
|
+
if (proxyHost && proxyPort) {
|
|
33
|
+
const proxyUrl = `http://${proxyHost}:${proxyPort}`;
|
|
34
|
+
file = `${file}+${proxyUrl}`;
|
|
35
|
+
}
|
|
36
|
+
const inputFile = (yield (0, SpecificationFile_1.load)(file)) || (yield (0, SpecificationFile_1.load)());
|
|
37
|
+
const result = yield this.validationService.parseDocument(inputFile, {}, flags);
|
|
38
|
+
if (!result.success) {
|
|
39
|
+
this.error(`Failed to parse the AsyncAPI document: ${result.error}`, {
|
|
40
|
+
exit: 1,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else if (!result.data) {
|
|
44
|
+
this.error('No data returned from parsing the AsyncAPI document.', {
|
|
45
|
+
exit: 1,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const { document, diagnostics, status } = result.data;
|
|
49
|
+
if (!document || status === 'invalid') {
|
|
50
|
+
const severityErrors = diagnostics.filter((obj) => obj.severity === 0);
|
|
51
|
+
this.log(`Input is not a correct AsyncAPI document so it cannot be processed.${this.validationService.formatDiagnosticsOutput(severityErrors, 'stylish', 'error')}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (flags['log-diagnostics'] && inputFile) {
|
|
55
|
+
this.handleGovernanceMessage(inputFile, diagnostics, status);
|
|
56
|
+
this.log(this.validationService.formatDiagnosticsOutput(diagnostics, flags['diagnostics-format'], flags['fail-severity']));
|
|
57
|
+
}
|
|
58
|
+
const logger = {
|
|
59
|
+
info: (message) => {
|
|
60
|
+
this.log(message);
|
|
61
|
+
},
|
|
62
|
+
debug: (message) => {
|
|
63
|
+
this.debug(message);
|
|
64
|
+
},
|
|
65
|
+
warn: (message) => {
|
|
66
|
+
this.warn(message);
|
|
67
|
+
},
|
|
68
|
+
error: (message) => {
|
|
69
|
+
this.error(message);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const s = (0, prompts_1.spinner)();
|
|
73
|
+
s.start('Generating models...');
|
|
74
|
+
try {
|
|
75
|
+
const generatedModels = yield (0, modelina_cli_1.generateModels)(Object.assign(Object.assign({}, flags), { output }), document, logger, language);
|
|
76
|
+
if (output && output !== 'stdout') {
|
|
77
|
+
const generatedModelStrings = generatedModels.map((model) => {
|
|
78
|
+
return model.modelName;
|
|
79
|
+
});
|
|
80
|
+
s.stop((0, picocolors_1.green)(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const generatedModelStrings = generatedModels.map((model) => {
|
|
84
|
+
return `
|
|
85
|
+
## Model name: ${model.modelName}
|
|
86
|
+
${model.result}
|
|
87
|
+
`;
|
|
88
|
+
});
|
|
89
|
+
s.stop((0, picocolors_1.green)(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`));
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
s.stop((0, picocolors_1.green)('Failed to generate models'));
|
|
93
|
+
if (error instanceof Error) {
|
|
94
|
+
this.error(error.message);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.error('An unknown error occurred during model generation.');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
parseArgs(args, output) {
|
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
let { language, file } = args;
|
|
105
|
+
let askForOutput = false;
|
|
106
|
+
const operationCancelled = 'Operation cancelled by the user.';
|
|
107
|
+
if (!language) {
|
|
108
|
+
language = yield (0, prompts_1.select)({
|
|
109
|
+
message: 'Select the language you want to generate models for',
|
|
110
|
+
options: Object.keys(modelina_cli_1.Languages).map((key) => ({
|
|
111
|
+
value: key,
|
|
112
|
+
label: key,
|
|
113
|
+
hint: modelina_cli_1.Languages[key],
|
|
114
|
+
})),
|
|
115
|
+
});
|
|
116
|
+
askForOutput = true;
|
|
117
|
+
}
|
|
118
|
+
if ((0, prompts_1.isCancel)(language)) {
|
|
119
|
+
(0, prompts_1.cancel)(operationCancelled);
|
|
120
|
+
this.exit();
|
|
121
|
+
}
|
|
122
|
+
if (!file) {
|
|
123
|
+
file = yield (0, prompts_1.text)({
|
|
124
|
+
message: 'Enter the path or URL to the AsyncAPI document',
|
|
125
|
+
defaultValue: 'asyncapi.yaml',
|
|
126
|
+
placeholder: 'asyncapi.yaml',
|
|
127
|
+
});
|
|
128
|
+
askForOutput = true;
|
|
129
|
+
}
|
|
130
|
+
if ((0, prompts_1.isCancel)(file)) {
|
|
131
|
+
(0, prompts_1.cancel)(operationCancelled);
|
|
132
|
+
this.exit();
|
|
133
|
+
}
|
|
134
|
+
if (!output && askForOutput) {
|
|
135
|
+
output = (yield (0, prompts_1.text)({
|
|
136
|
+
message: 'Enter the output directory or stdout to write the models to',
|
|
137
|
+
defaultValue: 'stdout',
|
|
138
|
+
placeholder: 'stdout',
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
if ((0, prompts_1.isCancel)(output)) {
|
|
142
|
+
(0, prompts_1.cancel)(operationCancelled);
|
|
143
|
+
this.exit();
|
|
144
|
+
}
|
|
145
|
+
return { language, file, output: output !== null && output !== void 0 ? output : 'stdout' };
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
handleGovernanceMessage(document, diagnostics, status) {
|
|
149
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const sourceString = document.toSourceString();
|
|
151
|
+
const hasIssues = diagnostics && diagnostics.length > 0;
|
|
152
|
+
const isFailSeverity = status === validation_service_1.ValidationStatus.INVALID;
|
|
153
|
+
const governanceMessage = this.validationService.generateGovernanceMessage(sourceString, hasIssues, isFailSeverity);
|
|
154
|
+
if (isFailSeverity) {
|
|
155
|
+
this.logToStderr(governanceMessage);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.log(governanceMessage);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
Models.description = 'Generates typed models';
|
|
164
|
+
Models.args = modelina_cli_1.ModelinaArgs;
|
|
165
|
+
Models.flags = Object.assign(Object.assign({}, (0, models_flags_1.modelsFlags)()), (0, proxy_flags_1.proxyFlags)());
|
|
166
|
+
exports.default = Models;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
|
+
export default class NewFile extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
|
+
'file-name': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
example: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
studio: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
'no-tty': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
static examples: string[];
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
runInteractive(): Promise<void>;
|
|
15
|
+
createAsyncapiFile(fileName: string, selectedTemplate: string): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
6
|
+
const inquirer = tslib_1.__importStar(require("inquirer"));
|
|
7
|
+
const Studio_1 = require("../../../../domains/models/Studio");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
10
|
+
const picocolors_1 = require("picocolors");
|
|
11
|
+
const file_flags_1 = require("../../internal/flags/new/file.flags");
|
|
12
|
+
const { writeFile, readFile } = fs_1.promises;
|
|
13
|
+
const DEFAULT_ASYNCAPI_FILE_NAME = 'asyncapi.yaml';
|
|
14
|
+
const DEFAULT_ASYNCAPI_YAML_TEMPLATE = 'default-example.yaml';
|
|
15
|
+
const DEFAULT_ASYNCAPI_JSON_TEMPLATE = 'default-example.json';
|
|
16
|
+
function loadExampleFile() {
|
|
17
|
+
const exampleFiles = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '../../../../../assets/examples/examples.json'), { encoding: 'utf8' });
|
|
18
|
+
return JSON.parse(exampleFiles);
|
|
19
|
+
}
|
|
20
|
+
function getExamplesFlagDescription() {
|
|
21
|
+
const examples = loadExampleFile();
|
|
22
|
+
let description = 'name of the example to use. Available examples are:';
|
|
23
|
+
for (const example of examples) {
|
|
24
|
+
description += `\n\t - ${example.value}`;
|
|
25
|
+
}
|
|
26
|
+
return description;
|
|
27
|
+
}
|
|
28
|
+
class NewFile extends base_1.default {
|
|
29
|
+
run() {
|
|
30
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const { flags } = yield this.parse(NewFile); // NOSONAR
|
|
32
|
+
const isTTY = process.stdout.isTTY;
|
|
33
|
+
if (!flags['no-tty'] && isTTY) {
|
|
34
|
+
return this.runInteractive();
|
|
35
|
+
}
|
|
36
|
+
const fileName = flags['file-name'] || DEFAULT_ASYNCAPI_FILE_NAME;
|
|
37
|
+
// Determine template based on file extension
|
|
38
|
+
let default_template;
|
|
39
|
+
if (fileName.endsWith('.json')) {
|
|
40
|
+
default_template = DEFAULT_ASYNCAPI_JSON_TEMPLATE;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
default_template = DEFAULT_ASYNCAPI_YAML_TEMPLATE;
|
|
44
|
+
}
|
|
45
|
+
const template = flags['example'] || default_template;
|
|
46
|
+
yield this.createAsyncapiFile(fileName, template);
|
|
47
|
+
if (flags.studio) {
|
|
48
|
+
if (isTTY) {
|
|
49
|
+
(0, Studio_1.start)(fileName, flags.port || Studio_1.DEFAULT_PORT);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.warn('Warning: --studio flag was passed but the terminal is not interactive. Ignoring...');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/* eslint-disable sonarjs/cognitive-complexity */
|
|
58
|
+
runInteractive() {
|
|
59
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
// NOSONAR
|
|
61
|
+
const { flags } = yield this.parse(NewFile); // NOSONAR
|
|
62
|
+
let fileName = flags['file-name'];
|
|
63
|
+
let selectedTemplate = flags['example'];
|
|
64
|
+
let openStudio = flags.studio;
|
|
65
|
+
let examples = [];
|
|
66
|
+
const questions = [];
|
|
67
|
+
if (!fileName) {
|
|
68
|
+
questions.push({
|
|
69
|
+
name: 'filename',
|
|
70
|
+
message: 'name of the file?',
|
|
71
|
+
type: 'input',
|
|
72
|
+
default: DEFAULT_ASYNCAPI_FILE_NAME,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const exampleFiles = yield readFile((0, path_1.resolve)(__dirname, '../../assets/examples/examples.json'), { encoding: 'utf8' });
|
|
77
|
+
examples = JSON.parse(exampleFiles);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// no examples found
|
|
81
|
+
}
|
|
82
|
+
if (!selectedTemplate && examples.length > 0) {
|
|
83
|
+
questions.push({
|
|
84
|
+
name: 'use-example',
|
|
85
|
+
message: 'would you like to start your new file from one of our examples?',
|
|
86
|
+
type: 'confirm',
|
|
87
|
+
default: true,
|
|
88
|
+
});
|
|
89
|
+
questions.push({
|
|
90
|
+
type: 'list',
|
|
91
|
+
name: 'selectedTemplate',
|
|
92
|
+
message: 'What example would you like to use?',
|
|
93
|
+
choices: examples,
|
|
94
|
+
when: (answers) => {
|
|
95
|
+
return answers['use-example'];
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (openStudio === undefined) {
|
|
100
|
+
questions.push({
|
|
101
|
+
name: 'studio',
|
|
102
|
+
message: 'open in Studio?',
|
|
103
|
+
type: 'confirm',
|
|
104
|
+
default: true,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (questions.length) {
|
|
108
|
+
const answers = yield inquirer.prompt(questions);
|
|
109
|
+
if (!fileName) {
|
|
110
|
+
fileName = answers.filename;
|
|
111
|
+
}
|
|
112
|
+
if (!selectedTemplate) {
|
|
113
|
+
selectedTemplate = answers.selectedTemplate;
|
|
114
|
+
}
|
|
115
|
+
if (openStudio === undefined) {
|
|
116
|
+
openStudio = answers.studio;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
fileName = fileName || DEFAULT_ASYNCAPI_FILE_NAME;
|
|
120
|
+
// Determine template based on file extension
|
|
121
|
+
let default_template;
|
|
122
|
+
if (fileName.endsWith('.json')) {
|
|
123
|
+
default_template = DEFAULT_ASYNCAPI_JSON_TEMPLATE;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
default_template = DEFAULT_ASYNCAPI_YAML_TEMPLATE;
|
|
127
|
+
}
|
|
128
|
+
selectedTemplate = selectedTemplate || default_template;
|
|
129
|
+
yield this.createAsyncapiFile(fileName, selectedTemplate);
|
|
130
|
+
fileName = fileName.includes('.') ? fileName : `${fileName}.yaml`;
|
|
131
|
+
if (openStudio) {
|
|
132
|
+
(0, Studio_1.start)(fileName, flags.port || Studio_1.DEFAULT_PORT);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
createAsyncapiFile(fileName, selectedTemplate) {
|
|
137
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const asyncApiFile = yield readFile((0, path_1.resolve)(__dirname, '../../../../../assets/examples/', selectedTemplate), { encoding: 'utf8' });
|
|
139
|
+
let fileNameToWriteToDisk;
|
|
140
|
+
if (!fileName.includes('.')) {
|
|
141
|
+
fileNameToWriteToDisk = `${fileName}.yaml`;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const extension = fileName.split('.')[1];
|
|
145
|
+
if (extension === 'yml' || extension === 'yaml' || extension === 'json') {
|
|
146
|
+
fileNameToWriteToDisk = fileName;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
console.log('CLI Support only yml, yaml and json extension for file');
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const content = yield readFile(fileNameToWriteToDisk, {
|
|
155
|
+
encoding: 'utf8',
|
|
156
|
+
});
|
|
157
|
+
if (content !== undefined) {
|
|
158
|
+
console.log(`A file named ${fileNameToWriteToDisk} already exists. Please choose a different name.`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
if (e.code === 'EACCES') {
|
|
164
|
+
this.error('Permission has been denied to access the file.');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
yield writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' });
|
|
168
|
+
console.log(`The ${(0, picocolors_1.cyan)(fileNameToWriteToDisk)} has been successfully created.`);
|
|
169
|
+
this.specFile = yield (0, SpecificationFile_1.load)(fileNameToWriteToDisk);
|
|
170
|
+
this.metricsMetadata.selected_template = selectedTemplate;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
NewFile.description = 'Creates a new asyncapi file';
|
|
175
|
+
NewFile.flags = (0, file_flags_1.fileFlags)(getExamplesFlagDescription());
|
|
176
|
+
NewFile.examples = [
|
|
177
|
+
'asyncapi new\t - start creation of a file in interactive mode',
|
|
178
|
+
'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',
|
|
179
|
+
];
|
|
180
|
+
exports.default = NewFile;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
class New extends base_1.default {
|
|
7
|
+
run() {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const help = new core_1.Help(this.config);
|
|
10
|
+
help.showHelp(['new', '--help']);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
New.description = 'Create a new AsyncAPI project, specification files, or templates for clients and applications.';
|
|
15
|
+
exports.default = New;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
|
+
export declare const successMessage: (projectName: string) => string;
|
|
3
|
+
export default class template extends Command {
|
|
4
|
+
static description: string;
|
|
5
|
+
protected commandName: string;
|
|
6
|
+
static readonly successMessage: (projectName: string) => string;
|
|
7
|
+
static readonly errorMessages: {
|
|
8
|
+
alreadyExists: (projectName: string) => string;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
12
|
+
name: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
13
|
+
template: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
+
file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
+
'force-write': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
};
|
|
17
|
+
run(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.successMessage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
9
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
10
|
+
const template_flags_1 = require("../../internal/flags/new/template.flags");
|
|
11
|
+
const picocolors_1 = require("picocolors");
|
|
12
|
+
const jsonfile_1 = tslib_1.__importDefault(require("jsonfile"));
|
|
13
|
+
const path_2 = tslib_1.__importDefault(require("path"));
|
|
14
|
+
const successMessage = (projectName) => `🎉 Your template is succesfully created
|
|
15
|
+
⏩ Next steps: follow the instructions ${(0, picocolors_1.cyan)('below')} to manage your project:
|
|
16
|
+
|
|
17
|
+
cd ${projectName}\t\t ${(0, picocolors_1.gray)('# Navigate to the project directory')}
|
|
18
|
+
npm install\t\t ${(0, picocolors_1.gray)('# Install the project dependencies')}
|
|
19
|
+
asyncapi generate fromTemplate <templateName> ../${projectName} \t\t ${(0, picocolors_1.gray)('# Execute the template from anasyncapi document')}
|
|
20
|
+
|
|
21
|
+
You can also open the project in your favourite editor and start tweaking it.
|
|
22
|
+
`;
|
|
23
|
+
exports.successMessage = successMessage;
|
|
24
|
+
const errorMessages = {
|
|
25
|
+
alreadyExists: (projectName) => `Unable to create the project because the directory "${(0, picocolors_1.cyan)(projectName)}" already exists at "${process.cwd()}/${projectName}".
|
|
26
|
+
To specify a different name for the new project, please run the command below with a unique project name:
|
|
27
|
+
|
|
28
|
+
${(0, picocolors_1.gray)('asyncapi new template --name ') + (0, picocolors_1.gray)(projectName) + (0, picocolors_1.gray)('-1')}`,
|
|
29
|
+
};
|
|
30
|
+
class template extends base_1.default {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
this.commandName = 'template';
|
|
34
|
+
}
|
|
35
|
+
run() {
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const { flags } = yield this.parse(template); // NOSONAR
|
|
38
|
+
const { name: projectName, template: templateName } = flags;
|
|
39
|
+
const PROJECT_DIRECTORY = (0, path_1.join)(process.cwd(), projectName);
|
|
40
|
+
const templateDirectory = (0, path_1.resolve)(__dirname, '../../../../../assets/create-template/templates/', templateName);
|
|
41
|
+
{
|
|
42
|
+
try {
|
|
43
|
+
yield fs_1.promises.mkdir(PROJECT_DIRECTORY);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
switch (err.code) {
|
|
47
|
+
case 'EEXIST':
|
|
48
|
+
this.error(errorMessages.alreadyExists(projectName));
|
|
49
|
+
break;
|
|
50
|
+
case 'EACCES':
|
|
51
|
+
this.error(`Unable to create the project. We tried to access the "${PROJECT_DIRECTORY}" directory but it was not possible due to file access permissions. Please check the write permissions of your current working directory ("${process.cwd()}").`);
|
|
52
|
+
break;
|
|
53
|
+
case 'EPERM':
|
|
54
|
+
this.error(`Unable to create the project. We tried to create the "${PROJECT_DIRECTORY}" directory but the operation requires elevated privileges. Please check the privileges for your current user.`);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
yield copyAndModify(templateDirectory, PROJECT_DIRECTORY, projectName);
|
|
62
|
+
this.log((0, exports.successMessage)(projectName));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
this.error(`Unable to create the project. Please check the following message for further info about the error:\n\n${err}`);
|
|
66
|
+
}
|
|
67
|
+
this.specFile = yield (0, SpecificationFile_1.load)(`${templateDirectory}/asyncapi.yaml`);
|
|
68
|
+
this.metricsMetadata.template = flags.template;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
template.description = 'Creates a new template';
|
|
74
|
+
template.successMessage = exports.successMessage;
|
|
75
|
+
template.errorMessages = errorMessages;
|
|
76
|
+
template.flags = (0, template_flags_1.templateFlags)();
|
|
77
|
+
exports.default = template;
|
|
78
|
+
function copyAndModify(templateDirectory, PROJECT_DIRECTORY, projectName) {
|
|
79
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const packageJsonPath = path_2.default.join(templateDirectory, 'package.json');
|
|
81
|
+
try {
|
|
82
|
+
yield fs_extra_1.default.copy(templateDirectory, PROJECT_DIRECTORY, {
|
|
83
|
+
filter: (src) => {
|
|
84
|
+
return !src.endsWith('package.json');
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
const packageData = yield jsonfile_1.default.readFile(packageJsonPath);
|
|
88
|
+
if (packageData.generator && 'renderer' in packageData.generator) {
|
|
89
|
+
packageData.generator.renderer = 'react';
|
|
90
|
+
}
|
|
91
|
+
if (packageData.name) {
|
|
92
|
+
packageData.name = projectName;
|
|
93
|
+
}
|
|
94
|
+
yield fs_extra_1.default.writeJSON(`${PROJECT_DIRECTORY}/package.json`, packageData, {
|
|
95
|
+
spaces: 2,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.error('Error:', err);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|