@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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.specWatcher = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
const GreenLog = chalk_1.default.hex('#00FF00');
|
|
8
|
+
const OrangeLog = chalk_1.default.hex('#FFA500');
|
|
9
|
+
const CHOKIDAR_CONFIG = {
|
|
10
|
+
// awaitWriteFinish: true // Used for large size specification files.
|
|
11
|
+
};
|
|
12
|
+
const WATCH_MESSAGES = {
|
|
13
|
+
logOnStart: (filePath) => console.log(GreenLog(`Watching AsyncAPI file at ${filePath}\n`)),
|
|
14
|
+
logOnChange: (handlerName) => console.log(OrangeLog(`Change detected, running ${handlerName}\n`)),
|
|
15
|
+
logOnAutoDisable: (docVersion = '') => console.log(OrangeLog(`Watch mode for ${docVersion || 'AsyncAPI'} file was not enabled.`), OrangeLog('\nINFO: Watch works only with files from local file system\n')),
|
|
16
|
+
};
|
|
17
|
+
const CHOKIDAR_INSTANCE_STORE = new Map();
|
|
18
|
+
const specWatcher = (params) => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (!params.spec.getFilePath()) {
|
|
21
|
+
return WATCH_MESSAGES.logOnAutoDisable(params.docVersion);
|
|
22
|
+
}
|
|
23
|
+
if (CHOKIDAR_INSTANCE_STORE.get((_a = params.label) !== null && _a !== void 0 ? _a : '_default')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const filePath = params.spec.getFilePath();
|
|
27
|
+
try {
|
|
28
|
+
WATCH_MESSAGES.logOnStart(filePath);
|
|
29
|
+
chokidar_1.default.watch(filePath, CHOKIDAR_CONFIG).on('change', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
if (params.handlerName) {
|
|
31
|
+
WATCH_MESSAGES.logOnChange(params.handlerName);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
yield params.handler.run();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
yield params.handler.catch(err);
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
CHOKIDAR_INSTANCE_STORE.set(params.label || '_default', true);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.log(error);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.specWatcher = specWatcher;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.closest = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const prompts_1 = require("@clack/prompts");
|
|
7
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
|
+
const fast_levenshtein_1 = tslib_1.__importDefault(require("fast-levenshtein"));
|
|
9
|
+
const closest = (target, possibilities) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
return (_b = (_a = possibilities
|
|
12
|
+
.map((id) => ({
|
|
13
|
+
distance: fast_levenshtein_1.default.get(target, id, { useCollator: true }),
|
|
14
|
+
id,
|
|
15
|
+
}))
|
|
16
|
+
.sort((a, b) => a.distance - b.distance)[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
|
|
17
|
+
};
|
|
18
|
+
exports.closest = closest;
|
|
19
|
+
const hook = function (opts) {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
if (opts.id === '--help') {
|
|
23
|
+
const help = new core_1.Help(this.config);
|
|
24
|
+
help.showHelp(['--help']);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const hiddenCommandIds = new Set(opts.config.commands.filter((c) => c.hidden).map((c) => c.id));
|
|
28
|
+
const commandIDs = [
|
|
29
|
+
...opts.config.commandIDs,
|
|
30
|
+
...opts.config.commands.flatMap((c) => c.aliases),
|
|
31
|
+
].filter((c) => !hiddenCommandIds.has(c));
|
|
32
|
+
if (commandIDs.length === 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// now we we return if the command id are not there.
|
|
36
|
+
let binHelp = `${opts.config.bin} --help`;
|
|
37
|
+
const idSplit = opts.id.split(':');
|
|
38
|
+
if (opts.config.findTopic(idSplit[0])) {
|
|
39
|
+
// if valid topic, update binHelp with topic
|
|
40
|
+
binHelp = `${binHelp} ${idSplit[0]}`;
|
|
41
|
+
}
|
|
42
|
+
//if there is a topic in the opts we just upgrade the our commnad like
|
|
43
|
+
// alter the suggestion in the help scenario so that help is the first command
|
|
44
|
+
// otherwise the user will be presented 'did you mean 'help'?' instead of 'did you mean "help <command>"?'
|
|
45
|
+
let suggestion = (/:?help:?/).test(opts.id)
|
|
46
|
+
? ['help', ...opts.id.split(':').filter((cmd) => cmd !== 'help')].join(':')
|
|
47
|
+
: (0, exports.closest)(opts.id, commandIDs);
|
|
48
|
+
let readableSuggestion = (0, core_1.toConfiguredId)(suggestion, this.config);
|
|
49
|
+
const originalCmd = (0, core_1.toConfiguredId)(opts.id, this.config);
|
|
50
|
+
this.warn(`${chalk_1.default.yellow(originalCmd)} is not a ${opts.config.bin} command.`);
|
|
51
|
+
let response;
|
|
52
|
+
try {
|
|
53
|
+
if (opts.id === 'help') {
|
|
54
|
+
readableSuggestion = '--help';
|
|
55
|
+
}
|
|
56
|
+
response = yield (0, prompts_1.confirm)({
|
|
57
|
+
message: `Did you mean ${chalk_1.default.blueBright(readableSuggestion)}? [y/n]`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
this.log('');
|
|
62
|
+
this.debug(error);
|
|
63
|
+
}
|
|
64
|
+
if (response === true) {
|
|
65
|
+
// this will split the original command from the suggested replacement, and gather the remaining args as varargs to help with situations like:
|
|
66
|
+
// confit set foo-bar -> confit:set:foo-bar -> config:set:foo-bar -> config:set foo-bar
|
|
67
|
+
let argv = ((_a = opts.argv) === null || _a === void 0 ? void 0 : _a.length)
|
|
68
|
+
? opts.argv
|
|
69
|
+
: opts.id.split(':').slice(suggestion.split(':').length);
|
|
70
|
+
if (suggestion.startsWith('help:')) {
|
|
71
|
+
// the args are the command/partial command you need help for (package:version)
|
|
72
|
+
// we created the suggestion variable to start with "help" so slice the first entry
|
|
73
|
+
argv = suggestion.split(':').slice(1);
|
|
74
|
+
// the command is just the word "help"
|
|
75
|
+
suggestion = 'help';
|
|
76
|
+
}
|
|
77
|
+
if (opts.id === 'help') {
|
|
78
|
+
return this.config.runCommand('--help');
|
|
79
|
+
}
|
|
80
|
+
return this.config.runCommand(suggestion, argv);
|
|
81
|
+
}
|
|
82
|
+
this.error(`Run ${chalk_1.default.bold.cyan(binHelp)} for a list of available commands.`, { exit: 127 });
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
exports.default = hook;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const DEFAULT_CONTEXT_FILE_PATH: string;
|
|
2
|
+
export declare let CONTEXT_FILE_PATH: string;
|
|
3
|
+
export interface IContextFile {
|
|
4
|
+
current?: string;
|
|
5
|
+
readonly store: {
|
|
6
|
+
[name: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface ICurrentContext {
|
|
10
|
+
readonly current: string;
|
|
11
|
+
readonly context: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function initContext(contextFilePath: string): Promise<string>;
|
|
14
|
+
export declare function loadContext(contextName?: string): Promise<string>;
|
|
15
|
+
export declare function addContext(contextName: string, pathToFile: string): Promise<void>;
|
|
16
|
+
export declare function removeContext(contextName: string): Promise<void>;
|
|
17
|
+
export declare function getCurrentContext(): Promise<ICurrentContext>;
|
|
18
|
+
export declare function setCurrentContext(contextName: string): Promise<void>;
|
|
19
|
+
export declare function editContext(contextName: string, pathToFile: string): Promise<void>;
|
|
20
|
+
export declare function loadContextFile(): Promise<IContextFile>;
|
|
21
|
+
export declare function isContextFileEmpty(fileContent: IContextFile): Promise<boolean>;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTEXT_FILE_PATH = exports.DEFAULT_CONTEXT_FILE_PATH = void 0;
|
|
4
|
+
exports.initContext = initContext;
|
|
5
|
+
exports.loadContext = loadContext;
|
|
6
|
+
exports.addContext = addContext;
|
|
7
|
+
exports.removeContext = removeContext;
|
|
8
|
+
exports.getCurrentContext = getCurrentContext;
|
|
9
|
+
exports.setCurrentContext = setCurrentContext;
|
|
10
|
+
exports.editContext = editContext;
|
|
11
|
+
exports.loadContextFile = loadContextFile;
|
|
12
|
+
exports.isContextFileEmpty = isContextFileEmpty;
|
|
13
|
+
const tslib_1 = require("tslib");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path = tslib_1.__importStar(require("path"));
|
|
16
|
+
const os = tslib_1.__importStar(require("os"));
|
|
17
|
+
const context_error_1 = require("../../errors/context-error");
|
|
18
|
+
const { readFile, writeFile } = fs_1.promises;
|
|
19
|
+
// `repoRootPath` is optimistically assigned current working directory's
|
|
20
|
+
// filesystem path because chances are it will become 'official' repository root
|
|
21
|
+
// down the execution.
|
|
22
|
+
//
|
|
23
|
+
// `REPO_ROOT_PATH` will be converted to a real constant after migration of the
|
|
24
|
+
// codebase to ES2022 or higher and introduction of construction
|
|
25
|
+
//
|
|
26
|
+
// const REPO_ROOT_PATH = await getRepoRootPath(process.cwd());
|
|
27
|
+
//
|
|
28
|
+
// See explanation of the situation with `CONTEXT_FILE_PATH` below.
|
|
29
|
+
let REPO_ROOT_PATH = process.cwd();
|
|
30
|
+
getRepoRootPath(process.cwd());
|
|
31
|
+
const DEFAULT_CONTEXT_FILENAME = '.asyncapi-cli';
|
|
32
|
+
const DEFAULT_CONTEXT_FILE_LOCATION = os.homedir();
|
|
33
|
+
exports.DEFAULT_CONTEXT_FILE_PATH = path.resolve(DEFAULT_CONTEXT_FILE_LOCATION, DEFAULT_CONTEXT_FILENAME);
|
|
34
|
+
const CONTEXT_FILENAME = process.env.CUSTOM_CONTEXT_FILENAME || DEFAULT_CONTEXT_FILENAME;
|
|
35
|
+
const CONTEXT_FILE_LOCATION = process.env.CUSTOM_CONTEXT_FILE_LOCATION || DEFAULT_CONTEXT_FILE_LOCATION;
|
|
36
|
+
// Usage of promises for assignment of their resolved values to constants is
|
|
37
|
+
// known to be troublesome:
|
|
38
|
+
// https://www.reddit.com/r/learnjavascript/comments/p7p7zw/assigning_data_from_a_promise_to_a_constant
|
|
39
|
+
//
|
|
40
|
+
// In this particular case and usage of ES6, there is a race condition during
|
|
41
|
+
// code execution, due to faster assignment of default values to
|
|
42
|
+
// `CONTEXT_FILE_PATH` than resolution of the promise. This is the cause
|
|
43
|
+
// `CONTEXT_FILE_PATH` will always pick default values for context file's path
|
|
44
|
+
// instead of waiting for resolution of the promise from `getContextFilePath()`.
|
|
45
|
+
// The situation might become better with use of top-level await which should
|
|
46
|
+
// pause code execution, until promise in construction
|
|
47
|
+
//
|
|
48
|
+
// const CONTEXT_FILE_PATH = await getContextFilePath() || path.resolve(CONTEXT_FILE_LOCATION, CONTEXT_FILENAME) || DEFAULT_CONTEXT_FILE_PATH;
|
|
49
|
+
//
|
|
50
|
+
// is resolved, but for this to be checked, all codebase (including
|
|
51
|
+
// `@oclif/core`) needs to be migrated to ES2022 or higher.
|
|
52
|
+
//
|
|
53
|
+
// Until then `CONTEXT_FILE_PATH` name is mimicking a `const` while right now it
|
|
54
|
+
// is a `let` reassigned inside of `getContextFilePath()`.
|
|
55
|
+
exports.CONTEXT_FILE_PATH = path.resolve(CONTEXT_FILE_LOCATION, CONTEXT_FILENAME) ||
|
|
56
|
+
exports.DEFAULT_CONTEXT_FILE_PATH;
|
|
57
|
+
// Sonar recognizes next line as a bug `Promises must be awaited, end with a
|
|
58
|
+
// call to .catch, or end with a call to .then with a rejection handler.` but
|
|
59
|
+
// due to absence of top-level await in ES6, this bug cannot be fixed without
|
|
60
|
+
// migrating the codebase to ES2022 or higher, thus suppressing Sonar analysis
|
|
61
|
+
// for this line.
|
|
62
|
+
getContextFilePath(); // NOSONAR
|
|
63
|
+
function initContext(contextFilePath) {
|
|
64
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const fileContent = {
|
|
66
|
+
store: {},
|
|
67
|
+
};
|
|
68
|
+
let contextWritePath = '';
|
|
69
|
+
// prettier-ignore
|
|
70
|
+
switch (contextFilePath) {
|
|
71
|
+
/* eslint-disable indent */
|
|
72
|
+
case '.':
|
|
73
|
+
contextWritePath = process.cwd() + path.sep + CONTEXT_FILENAME;
|
|
74
|
+
break;
|
|
75
|
+
case './':
|
|
76
|
+
contextWritePath = REPO_ROOT_PATH + path.sep + CONTEXT_FILENAME;
|
|
77
|
+
break;
|
|
78
|
+
// There are two variants of `~` case because tilde expansion in UNIX
|
|
79
|
+
// systems is not a guaranteed feature - sometimes `~` can return just `~`
|
|
80
|
+
// instead of home directory path.
|
|
81
|
+
// https://stackoverflow.com/questions/491877/how-to-find-a-users-home-directory-on-linux-or-unix#comment17161699_492669
|
|
82
|
+
case os.homedir():
|
|
83
|
+
contextWritePath = os.homedir() + path.sep + CONTEXT_FILENAME;
|
|
84
|
+
break;
|
|
85
|
+
case '~':
|
|
86
|
+
contextWritePath = os.homedir() + path.sep + CONTEXT_FILENAME;
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
contextWritePath = process.cwd() + path.sep + CONTEXT_FILENAME;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
yield writeFile(contextWritePath, JSON.stringify(fileContent), {
|
|
93
|
+
encoding: 'utf8',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
throw new context_error_1.ContextFileWriteError(contextWritePath);
|
|
98
|
+
}
|
|
99
|
+
return contextWritePath;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function loadContext(contextName) {
|
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const fileContent = yield loadContextFile();
|
|
105
|
+
if (contextName) {
|
|
106
|
+
const context = fileContent.store[String(contextName)];
|
|
107
|
+
if (!context) {
|
|
108
|
+
throw new context_error_1.ContextNotFoundError(contextName);
|
|
109
|
+
}
|
|
110
|
+
return context;
|
|
111
|
+
}
|
|
112
|
+
else if (fileContent.current) {
|
|
113
|
+
const context = fileContent.store[fileContent.current];
|
|
114
|
+
if (!context) {
|
|
115
|
+
throw new context_error_1.ContextNotFoundError(fileContent.current);
|
|
116
|
+
}
|
|
117
|
+
return context;
|
|
118
|
+
}
|
|
119
|
+
throw new context_error_1.MissingCurrentContextError();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function addContext(contextName, pathToFile) {
|
|
123
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const fileContent = yield loadContextFile();
|
|
125
|
+
// If context file already has context name similar to the one specified as
|
|
126
|
+
// an argument, notify user about it (throw `ContextAlreadyExistsError`
|
|
127
|
+
// error) and exit.
|
|
128
|
+
if (fileContent.store.hasOwnProperty.call(fileContent.store, contextName)) {
|
|
129
|
+
throw new context_error_1.ContextAlreadyExistsError(contextName, exports.CONTEXT_FILE_PATH);
|
|
130
|
+
}
|
|
131
|
+
fileContent.store[String(contextName)] = String(pathToFile);
|
|
132
|
+
yield saveContextFile(fileContent);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function removeContext(contextName) {
|
|
136
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const fileContent = yield loadContextFile();
|
|
138
|
+
if (yield isContextFileEmpty(fileContent)) {
|
|
139
|
+
throw new context_error_1.ContextFileEmptyError(exports.CONTEXT_FILE_PATH);
|
|
140
|
+
}
|
|
141
|
+
if (!fileContent.store[String(contextName)]) {
|
|
142
|
+
throw new context_error_1.ContextNotFoundError(contextName);
|
|
143
|
+
}
|
|
144
|
+
if (fileContent.current === contextName) {
|
|
145
|
+
delete fileContent.current;
|
|
146
|
+
}
|
|
147
|
+
delete fileContent.store[String(contextName)];
|
|
148
|
+
yield saveContextFile(fileContent);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function getCurrentContext() {
|
|
152
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const fileContent = yield loadContextFile();
|
|
154
|
+
if (yield isContextFileEmpty(fileContent)) {
|
|
155
|
+
throw new context_error_1.ContextFileEmptyError(exports.CONTEXT_FILE_PATH);
|
|
156
|
+
}
|
|
157
|
+
const context = yield loadContext();
|
|
158
|
+
return {
|
|
159
|
+
current: fileContent.current,
|
|
160
|
+
context,
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function setCurrentContext(contextName) {
|
|
165
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const fileContent = yield loadContextFile();
|
|
167
|
+
if (yield isContextFileEmpty(fileContent)) {
|
|
168
|
+
throw new context_error_1.ContextFileEmptyError(exports.CONTEXT_FILE_PATH);
|
|
169
|
+
}
|
|
170
|
+
if (!fileContent.store[String(contextName)]) {
|
|
171
|
+
throw new context_error_1.ContextNotFoundError(contextName);
|
|
172
|
+
}
|
|
173
|
+
fileContent.current = String(contextName);
|
|
174
|
+
yield saveContextFile(fileContent);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function editContext(contextName, pathToFile) {
|
|
178
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
// The expression is not wrapped in a `try...catch` block and is allowed to
|
|
180
|
+
// throw automatically because it is assumed that `loadContextFile()` works
|
|
181
|
+
// with a 100%-existing valid file in this case, thus if it threw anyway -
|
|
182
|
+
// some REAL error happened and user should know about it.
|
|
183
|
+
const fileContent = yield loadContextFile();
|
|
184
|
+
if (yield isContextFileEmpty(fileContent)) {
|
|
185
|
+
throw new context_error_1.ContextFileEmptyError(exports.CONTEXT_FILE_PATH);
|
|
186
|
+
}
|
|
187
|
+
fileContent.store[String(contextName)] = String(pathToFile);
|
|
188
|
+
yield saveContextFile(fileContent);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function loadContextFile() {
|
|
192
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
let fileContent;
|
|
194
|
+
// If the context file cannot be read then it's a 'MissingContextFileError'
|
|
195
|
+
// error.
|
|
196
|
+
try {
|
|
197
|
+
yield readFile(exports.CONTEXT_FILE_PATH, { encoding: 'utf8' });
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
throw new context_error_1.MissingContextFileError();
|
|
201
|
+
}
|
|
202
|
+
// If the context file cannot be parsed then it's a
|
|
203
|
+
// 'ContextFileWrongFormatError' error.
|
|
204
|
+
try {
|
|
205
|
+
fileContent = JSON.parse(yield readFile(exports.CONTEXT_FILE_PATH, { encoding: 'utf8' }));
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
// https://stackoverflow.com/questions/29797946/handling-bad-json-parse-in-node-safely
|
|
209
|
+
throw new context_error_1.ContextFileWrongFormatError(exports.CONTEXT_FILE_PATH);
|
|
210
|
+
}
|
|
211
|
+
// If the context file cannot be validated then it's a
|
|
212
|
+
// 'ContextFileWrongFormatError' error.
|
|
213
|
+
if (!(yield isContextFileValid(fileContent))) {
|
|
214
|
+
throw new context_error_1.ContextFileWrongFormatError(exports.CONTEXT_FILE_PATH);
|
|
215
|
+
}
|
|
216
|
+
return fileContent;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function saveContextFile(fileContent) {
|
|
220
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
try {
|
|
222
|
+
yield writeFile(exports.CONTEXT_FILE_PATH, JSON.stringify({
|
|
223
|
+
current: fileContent.current,
|
|
224
|
+
store: fileContent.store,
|
|
225
|
+
}), { encoding: 'utf8' });
|
|
226
|
+
}
|
|
227
|
+
catch (e) {
|
|
228
|
+
throw new context_error_1.ContextFileWriteError(exports.CONTEXT_FILE_PATH);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function getRepoRootPath(repoRootPath) {
|
|
233
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
// Asynchronous `fs.exists()` is deprecated, asynchronous `fs.stat()`
|
|
235
|
+
// introduces race condition, thus synchronous functions are used.
|
|
236
|
+
let pathToCheck = `${repoRootPath}${path.sep}.git`;
|
|
237
|
+
// If directory where `init` was requested in, happens to contain `.git`
|
|
238
|
+
// directory, then it surely is a root of repository, no need to search
|
|
239
|
+
// further and `REPO_ROOT_PATH` will remain as it was.
|
|
240
|
+
if ((0, fs_1.existsSync)(pathToCheck) && (0, fs_1.lstatSync)(pathToCheck).isDirectory()) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
// Directory where `init` was requested in, did not happen to contain `.git`
|
|
244
|
+
// directory, so preparation for iterating through array of filesystem paths
|
|
245
|
+
// is started.
|
|
246
|
+
const repoRootPathArray = repoRootPath.split(path.sep);
|
|
247
|
+
// Last element in array is thrown away because it is already known that it
|
|
248
|
+
// does not contain directory `.git`.
|
|
249
|
+
repoRootPathArray.pop();
|
|
250
|
+
// Backwards search of the array of filesystem paths will now be performed.
|
|
251
|
+
let i = repoRootPathArray.length - 1;
|
|
252
|
+
while (i > 0) {
|
|
253
|
+
pathToCheck = `${repoRootPathArray.join(path.sep)}${path.sep}.git`;
|
|
254
|
+
if ((0, fs_1.existsSync)(pathToCheck) && (0, fs_1.lstatSync)(pathToCheck).isDirectory()) {
|
|
255
|
+
REPO_ROOT_PATH = repoRootPathArray.join(path.sep);
|
|
256
|
+
return REPO_ROOT_PATH;
|
|
257
|
+
}
|
|
258
|
+
// Last (`0th`) element is an empty string, so if directory `.git` was not
|
|
259
|
+
// found on 1st element (last actual directory in filesystem), the search
|
|
260
|
+
// does not need to continue and `REPO_ROOT_PATH` will remain having the
|
|
261
|
+
// value of current (where `init` was requested in) directory.
|
|
262
|
+
if (i === 1) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
repoRootPathArray.pop();
|
|
266
|
+
i--;
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
function getContextFilePath() {
|
|
272
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
const currentPath = process
|
|
274
|
+
.cwd()
|
|
275
|
+
.slice(REPO_ROOT_PATH.length + 1)
|
|
276
|
+
.split(path.sep);
|
|
277
|
+
currentPath.unshift(REPO_ROOT_PATH);
|
|
278
|
+
for (let i = currentPath.length; i >= 0; i--) {
|
|
279
|
+
const currentPathString = currentPath[0]
|
|
280
|
+
? currentPath.join(path.sep) + path.sep + CONTEXT_FILENAME
|
|
281
|
+
: os.homedir() + path.sep + CONTEXT_FILENAME;
|
|
282
|
+
// This `try...catch` is a part of `for` loop and is used only to swallow
|
|
283
|
+
// errors if the file does not exist or cannot be read, to continue
|
|
284
|
+
// uninterrupted execution of the loop.
|
|
285
|
+
try {
|
|
286
|
+
// If a file is found which can be read and passed validation as a
|
|
287
|
+
// legitimate context file, then it is considered a legitimate context
|
|
288
|
+
// file indeed.
|
|
289
|
+
const fileContent = JSON.parse(
|
|
290
|
+
//we do not use await readFile because getContextFilePath cannot be called inside async function
|
|
291
|
+
(0, fs_1.readFileSync)(currentPathString, { encoding: 'utf8' }));
|
|
292
|
+
if (fileContent &&
|
|
293
|
+
(yield isContextFileValid(fileContent))) {
|
|
294
|
+
exports.CONTEXT_FILE_PATH = currentPathString;
|
|
295
|
+
return exports.CONTEXT_FILE_PATH;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
catch (e) { } // eslint-disable-line
|
|
299
|
+
currentPath.pop();
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
function isContextFileValid(fileContent) {
|
|
305
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
// Validation of context file's format against interface `IContextFile`.
|
|
307
|
+
return ([1, 2].includes(Object.keys(fileContent).length) &&
|
|
308
|
+
fileContent.hasOwnProperty.call(fileContent, 'store') &&
|
|
309
|
+
!Array.from(Object.keys(fileContent.store)).find((elem) => typeof elem !== 'string') &&
|
|
310
|
+
!Array.from(Object.values(fileContent.store)).find((elem) => typeof elem !== 'string'));
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function isContextFileEmpty(fileContent) {
|
|
314
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
315
|
+
// If context file contains only one empty property `store` then the whole
|
|
316
|
+
// context file is considered empty.
|
|
317
|
+
return (fileContent &&
|
|
318
|
+
Object.keys(fileContent).length === 1 &&
|
|
319
|
+
Object.keys(fileContent.store).length === 0);
|
|
320
|
+
});
|
|
321
|
+
}
|