@sap/cli-core 2023.12.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/CHANGELOG.md +40 -0
- package/LICENSE +44 -0
- package/README.md +13 -0
- package/assets/error.html +20 -0
- package/assets/success.html +20 -0
- package/cache/cache.d.ts +6 -0
- package/cache/cache.js +82 -0
- package/cache/index.d.ts +2 -0
- package/cache/index.js +12 -0
- package/cache/utils.d.ts +1 -0
- package/cache/utils.js +16 -0
- package/commands/cache.command/clean.command.d.ts +3 -0
- package/commands/cache.command/clean.command.js +15 -0
- package/commands/cache.command/index.d.ts +3 -0
- package/commands/cache.command/index.js +15 -0
- package/commands/cache.command/init.command.d.ts +3 -0
- package/commands/cache.command/init.command.js +36 -0
- package/commands/cache.command/show.command.d.ts +3 -0
- package/commands/cache.command/show.command.js +30 -0
- package/commands/handler/authentication/index.d.ts +2 -0
- package/commands/handler/authentication/index.js +21 -0
- package/commands/handler/authentication/oauth/index.d.ts +2 -0
- package/commands/handler/authentication/oauth/index.js +18 -0
- package/commands/handler/authentication/oauth/secretsProvider/cache.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/cache.js +19 -0
- package/commands/handler/authentication/oauth/secretsProvider/file.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/file.js +25 -0
- package/commands/handler/authentication/oauth/secretsProvider/index.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/index.js +10 -0
- package/commands/handler/authentication/oauth/secretsProvider/options.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/options.js +30 -0
- package/commands/handler/authentication/oauth/tokenProvider/getToken.d.ts +2 -0
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +88 -0
- package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +2 -0
- package/commands/handler/authentication/oauth/tokenProvider/index.js +11 -0
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.d.ts +2 -0
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +15 -0
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.d.ts +3 -0
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +35 -0
- package/commands/handler/authentication/oauth/tokenProvider/utils.d.ts +1 -0
- package/commands/handler/authentication/oauth/tokenProvider/utils.js +27 -0
- package/commands/handler/authentication/oauth/utils.d.ts +15 -0
- package/commands/handler/authentication/oauth/utils.js +58 -0
- package/commands/handler/authentication/passcode/function.d.ts +2 -0
- package/commands/handler/authentication/passcode/function.js +22 -0
- package/commands/handler/authentication/passcode/index.d.ts +2 -0
- package/commands/handler/authentication/passcode/index.js +19 -0
- package/commands/handler/authentication/passcode/input.d.ts +2 -0
- package/commands/handler/authentication/passcode/input.js +42 -0
- package/commands/handler/authentication/passcode/setPasscode.d.ts +2 -0
- package/commands/handler/authentication/passcode/setPasscode.js +16 -0
- package/commands/handler/authentication/passcode/types.d.ts +1 -0
- package/commands/handler/authentication/passcode/types.js +2 -0
- package/commands/handler/authentication/technicalJWT/cf.d.ts +4 -0
- package/commands/handler/authentication/technicalJWT/cf.js +133 -0
- package/commands/handler/authentication/technicalJWT/exec.d.ts +9 -0
- package/commands/handler/authentication/technicalJWT/exec.js +196 -0
- package/commands/handler/authentication/technicalJWT/index.d.ts +2 -0
- package/commands/handler/authentication/technicalJWT/index.js +15 -0
- package/commands/handler/authentication/technicalJWT/types.d.ts +2 -0
- package/commands/handler/authentication/technicalJWT/types.js +8 -0
- package/commands/handler/authentication/technicalJWT/utils.d.ts +1 -0
- package/commands/handler/authentication/technicalJWT/utils.js +70 -0
- package/commands/handler/authentication/utils.d.ts +3 -0
- package/commands/handler/authentication/utils.js +8 -0
- package/commands/handler/checkOptionsExistence.d.ts +2 -0
- package/commands/handler/checkOptionsExistence.js +17 -0
- package/commands/handler/error.d.ts +2 -0
- package/commands/handler/error.js +21 -0
- package/commands/handler/fail.d.ts +2 -0
- package/commands/handler/fail.js +10 -0
- package/commands/handler/fetch/fetch.d.ts +2 -0
- package/commands/handler/fetch/fetch.js +83 -0
- package/commands/handler/fetch/index.d.ts +2 -0
- package/commands/handler/fetch/index.js +25 -0
- package/commands/handler/fetch/utils.d.ts +14 -0
- package/commands/handler/fetch/utils.js +152 -0
- package/commands/handler/force.d.ts +2 -0
- package/commands/handler/force.js +35 -0
- package/commands/handler/index.d.ts +18 -0
- package/commands/handler/index.js +39 -0
- package/commands/handler/input/file.d.ts +2 -0
- package/commands/handler/input/file.js +34 -0
- package/commands/handler/input/index.d.ts +2 -0
- package/commands/handler/input/index.js +8 -0
- package/commands/handler/input/input.d.ts +2 -0
- package/commands/handler/input/input.js +44 -0
- package/commands/handler/mandatoryOptions.d.ts +2 -0
- package/commands/handler/mandatoryOptions.js +25 -0
- package/commands/handler/next.d.ts +2 -0
- package/commands/handler/next.js +19 -0
- package/commands/handler/options/env.d.ts +2 -0
- package/commands/handler/options/env.js +18 -0
- package/commands/handler/options/file.d.ts +2 -0
- package/commands/handler/options/file.js +21 -0
- package/commands/handler/options/index.d.ts +7 -0
- package/commands/handler/options/index.js +32 -0
- package/commands/handler/options/option.d.ts +2 -0
- package/commands/handler/options/option.js +20 -0
- package/commands/handler/options/pipe.d.ts +2 -0
- package/commands/handler/options/pipe.js +34 -0
- package/commands/handler/options/utils.d.ts +6 -0
- package/commands/handler/options/utils.js +63 -0
- package/commands/handler/or.d.ts +2 -0
- package/commands/handler/or.js +37 -0
- package/commands/handler/parseArguments.d.ts +4 -0
- package/commands/handler/parseArguments.js +22 -0
- package/commands/handler/resilient.d.ts +2 -0
- package/commands/handler/resilient.js +18 -0
- package/commands/handler/root/index.d.ts +2 -0
- package/commands/handler/root/index.js +18 -0
- package/commands/handler/stackTrace.d.ts +2 -0
- package/commands/handler/stackTrace.js +22 -0
- package/commands/handler/succeed.d.ts +2 -0
- package/commands/handler/succeed.js +9 -0
- package/commands/handler/utils.d.ts +7 -0
- package/commands/handler/utils.js +56 -0
- package/commands/host.command.d.ts +2 -0
- package/commands/host.command.js +68 -0
- package/commands/login.command.d.ts +3 -0
- package/commands/login.command.js +16 -0
- package/commands/logout.command.d.ts +3 -0
- package/commands/logout.command.js +21 -0
- package/commands/openAPI.command/index.d.ts +2 -0
- package/commands/openAPI.command/index.js +102 -0
- package/commands/openAPI.command/utils.d.ts +19 -0
- package/commands/openAPI.command/utils.js +334 -0
- package/commands/passcode.command.d.ts +2 -0
- package/commands/passcode.command.js +26 -0
- package/commands/secrets.command/index.d.ts +3 -0
- package/commands/secrets.command/index.js +13 -0
- package/commands/secrets.command/show.command.d.ts +3 -0
- package/commands/secrets.command/show.command.js +25 -0
- package/config/core.d.ts +10 -0
- package/config/core.js +23 -0
- package/config/index.d.ts +5 -0
- package/config/index.js +90 -0
- package/configureLoggers.d.ts +1 -0
- package/configureLoggers.js +11 -0
- package/constants.d.ts +43 -0
- package/constants.js +175 -0
- package/discovery/index.d.ts +10 -0
- package/discovery/index.js +142 -0
- package/discovery/utils.d.ts +7 -0
- package/discovery/utils.js +27 -0
- package/dwc/dwc.d.ts +10 -0
- package/dwc/dwc.js +180 -0
- package/dwc/run.d.ts +1 -0
- package/dwc/run.js +37 -0
- package/dwc/utils.d.ts +4 -0
- package/dwc/utils.js +37 -0
- package/index.d.ts +16 -0
- package/index.js +59 -0
- package/logger/index.d.ts +28 -0
- package/logger/index.js +63 -0
- package/module.d.ts +4 -0
- package/module.js +45 -0
- package/package.json +32 -0
- package/result/ResultHandlerFactory.d.ts +6 -0
- package/result/ResultHandlerFactory.js +12 -0
- package/result/ResultHandlerImpl.d.ts +6 -0
- package/result/ResultHandlerImpl.js +12 -0
- package/result/types.d.ts +4 -0
- package/result/types.js +2 -0
- package/schemas/discovery.json +347 -0
- package/settings/index.d.ts +4 -0
- package/settings/index.js +34 -0
- package/types.d.ts +182 -0
- package/types.js +67 -0
- package/utils/commands.d.ts +8 -0
- package/utils/commands.js +115 -0
- package/utils/http/index.d.ts +7 -0
- package/utils/http/index.js +69 -0
- package/utils/http/utils.d.ts +7 -0
- package/utils/http/utils.js +47 -0
- package/utils/options.d.ts +3 -0
- package/utils/options.js +25 -0
- package/utils/utils.d.ts +24 -0
- package/utils/utils.js +163 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.create = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const config_1 = require("../../config");
|
|
9
|
+
const constants_1 = require("../../constants");
|
|
10
|
+
const options_1 = require("./options");
|
|
11
|
+
const PARAM_REGEX = /{.*}/;
|
|
12
|
+
const replacer = (toBeReplaced) => {
|
|
13
|
+
const param = toBeReplaced.slice(1, -1);
|
|
14
|
+
return `{${lodash_1.default.kebabCase(param)}}`;
|
|
15
|
+
};
|
|
16
|
+
const create = (message) => (0, options_1.create)([
|
|
17
|
+
{
|
|
18
|
+
...constants_1.OPTION_FORCE,
|
|
19
|
+
required: true,
|
|
20
|
+
prompts: {
|
|
21
|
+
type: "confirm",
|
|
22
|
+
initial: true,
|
|
23
|
+
message: () => {
|
|
24
|
+
const config = (0, config_1.get)();
|
|
25
|
+
let intMessage = message.replace(PARAM_REGEX, replacer);
|
|
26
|
+
Object.entries(config.options).forEach((option) => {
|
|
27
|
+
intMessage = intMessage.replace(`{${option[0]}}`, option[1]);
|
|
28
|
+
});
|
|
29
|
+
return intMessage;
|
|
30
|
+
},
|
|
31
|
+
inputValidator: (value) => value,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
], undefined, false, true);
|
|
35
|
+
exports.create = create;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { create as createRootHandler } from "./root";
|
|
2
|
+
export { create as createMandatoryOptionsHandler } from "./mandatoryOptions";
|
|
3
|
+
export { create as createNextHandler } from "./next";
|
|
4
|
+
export { create as createOrHandler } from "./or";
|
|
5
|
+
export { create as createParseArgumentsHandler } from "./parseArguments";
|
|
6
|
+
export { create as createAuthenticationHandler } from "./authentication";
|
|
7
|
+
export { create as createPasscodeHandler } from "./authentication/passcode";
|
|
8
|
+
export { create as createOauthHandler } from "./authentication/oauth";
|
|
9
|
+
export { create as createForceHandler } from "./force";
|
|
10
|
+
export { create as createFetchHandler } from "./fetch";
|
|
11
|
+
export { create as createOptionsHandler } from "./options";
|
|
12
|
+
export { create as createInputHandler } from "./input";
|
|
13
|
+
export { create as createCheckOptionsExistence } from "./checkOptionsExistence";
|
|
14
|
+
export { create as createFailHandler } from "./fail";
|
|
15
|
+
export { create as createSucceedHandler } from "./succeed";
|
|
16
|
+
export { create as createErrorHandler } from "./error";
|
|
17
|
+
export { create as createResilientHandler } from "./resilient";
|
|
18
|
+
export { create as createStackTraceHandler } from "./stackTrace";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStackTraceHandler = exports.createResilientHandler = exports.createErrorHandler = exports.createSucceedHandler = exports.createFailHandler = exports.createCheckOptionsExistence = exports.createInputHandler = exports.createOptionsHandler = exports.createFetchHandler = exports.createForceHandler = exports.createOauthHandler = exports.createPasscodeHandler = exports.createAuthenticationHandler = exports.createParseArgumentsHandler = exports.createOrHandler = exports.createNextHandler = exports.createMandatoryOptionsHandler = exports.createRootHandler = void 0;
|
|
4
|
+
var root_1 = require("./root");
|
|
5
|
+
Object.defineProperty(exports, "createRootHandler", { enumerable: true, get: function () { return root_1.create; } });
|
|
6
|
+
var mandatoryOptions_1 = require("./mandatoryOptions");
|
|
7
|
+
Object.defineProperty(exports, "createMandatoryOptionsHandler", { enumerable: true, get: function () { return mandatoryOptions_1.create; } });
|
|
8
|
+
var next_1 = require("./next");
|
|
9
|
+
Object.defineProperty(exports, "createNextHandler", { enumerable: true, get: function () { return next_1.create; } });
|
|
10
|
+
var or_1 = require("./or");
|
|
11
|
+
Object.defineProperty(exports, "createOrHandler", { enumerable: true, get: function () { return or_1.create; } });
|
|
12
|
+
var parseArguments_1 = require("./parseArguments");
|
|
13
|
+
Object.defineProperty(exports, "createParseArgumentsHandler", { enumerable: true, get: function () { return parseArguments_1.create; } });
|
|
14
|
+
var authentication_1 = require("./authentication");
|
|
15
|
+
Object.defineProperty(exports, "createAuthenticationHandler", { enumerable: true, get: function () { return authentication_1.create; } });
|
|
16
|
+
var passcode_1 = require("./authentication/passcode");
|
|
17
|
+
Object.defineProperty(exports, "createPasscodeHandler", { enumerable: true, get: function () { return passcode_1.create; } });
|
|
18
|
+
var oauth_1 = require("./authentication/oauth");
|
|
19
|
+
Object.defineProperty(exports, "createOauthHandler", { enumerable: true, get: function () { return oauth_1.create; } });
|
|
20
|
+
var force_1 = require("./force");
|
|
21
|
+
Object.defineProperty(exports, "createForceHandler", { enumerable: true, get: function () { return force_1.create; } });
|
|
22
|
+
var fetch_1 = require("./fetch");
|
|
23
|
+
Object.defineProperty(exports, "createFetchHandler", { enumerable: true, get: function () { return fetch_1.create; } });
|
|
24
|
+
var options_1 = require("./options");
|
|
25
|
+
Object.defineProperty(exports, "createOptionsHandler", { enumerable: true, get: function () { return options_1.create; } });
|
|
26
|
+
var input_1 = require("./input");
|
|
27
|
+
Object.defineProperty(exports, "createInputHandler", { enumerable: true, get: function () { return input_1.create; } });
|
|
28
|
+
var checkOptionsExistence_1 = require("./checkOptionsExistence");
|
|
29
|
+
Object.defineProperty(exports, "createCheckOptionsExistence", { enumerable: true, get: function () { return checkOptionsExistence_1.create; } });
|
|
30
|
+
var fail_1 = require("./fail");
|
|
31
|
+
Object.defineProperty(exports, "createFailHandler", { enumerable: true, get: function () { return fail_1.create; } });
|
|
32
|
+
var succeed_1 = require("./succeed");
|
|
33
|
+
Object.defineProperty(exports, "createSucceedHandler", { enumerable: true, get: function () { return succeed_1.create; } });
|
|
34
|
+
var error_1 = require("./error");
|
|
35
|
+
Object.defineProperty(exports, "createErrorHandler", { enumerable: true, get: function () { return error_1.create; } });
|
|
36
|
+
var resilient_1 = require("./resilient");
|
|
37
|
+
Object.defineProperty(exports, "createResilientHandler", { enumerable: true, get: function () { return resilient_1.create; } });
|
|
38
|
+
var stackTrace_1 = require("./stackTrace");
|
|
39
|
+
Object.defineProperty(exports, "createStackTraceHandler", { enumerable: true, get: function () { return stackTrace_1.create; } });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.create = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const config_1 = require("../../../config");
|
|
9
|
+
const logger_1 = require("../../../logger");
|
|
10
|
+
const constants_1 = require("../../../constants");
|
|
11
|
+
const checkOptionsExistence_1 = require("../checkOptionsExistence");
|
|
12
|
+
const next_1 = require("../next");
|
|
13
|
+
const options_1 = require("../options");
|
|
14
|
+
const readBodyFromFile = () => async () => {
|
|
15
|
+
const config = (0, config_1.get)();
|
|
16
|
+
const filePath = config.options[constants_1.OPTION_FILE_PATH.longName];
|
|
17
|
+
const { debug, trace } = (0, logger_1.get)("commands.handler.input.file");
|
|
18
|
+
debug("reading request body from %s", filePath);
|
|
19
|
+
try {
|
|
20
|
+
(0, config_1.set)({
|
|
21
|
+
data: JSON.parse(await fs_extra_1.default.readFile(filePath, "utf-8")),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (config.verbose) {
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
console.log(`Failed to read content from file ${filePath}. Does the file really exist and does it contain valid JSON?`);
|
|
28
|
+
}
|
|
29
|
+
trace(`Failed to read content from file ${filePath}`, err);
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const create = () => (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_INPUT), (0, options_1.create)(constants_1.OPTION_FILE_PATH, { readEnv: true, readFile: true, readOptions: true, readPipe: true }, true, true), readBodyFromFile);
|
|
34
|
+
exports.create = create;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const or_1 = require("../or");
|
|
5
|
+
const input_1 = require("./input");
|
|
6
|
+
const file_1 = require("./file");
|
|
7
|
+
const create = () => (0, or_1.create)((0, file_1.create)(), (0, input_1.create)());
|
|
8
|
+
exports.create = create;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.create = void 0;
|
|
7
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
8
|
+
const config_1 = require("../../../config");
|
|
9
|
+
const constants_1 = require("../../../constants");
|
|
10
|
+
const logger_1 = require("../../../logger");
|
|
11
|
+
const commands_1 = require("../../../utils/commands");
|
|
12
|
+
const create = () => (command) => {
|
|
13
|
+
command.addOption((0, commands_1.buildOption)(constants_1.OPTION_INPUT));
|
|
14
|
+
return async () => {
|
|
15
|
+
const config = (0, config_1.get)();
|
|
16
|
+
const { debug } = (0, logger_1.get)("handler.input.input");
|
|
17
|
+
if (config.options[constants_1.OPTION_FILE_PATH.longName]) {
|
|
18
|
+
throw new Error(`input provided through option --${constants_1.OPTION_FILE_PATH.longName}`);
|
|
19
|
+
}
|
|
20
|
+
let input = config.options[constants_1.OPTION_INPUT.longName];
|
|
21
|
+
if (!input) {
|
|
22
|
+
input = (await prompts_1.default.prompt({
|
|
23
|
+
type: "text",
|
|
24
|
+
message: `Please provide input as a string to use for the command:`,
|
|
25
|
+
name: "value",
|
|
26
|
+
})).value;
|
|
27
|
+
}
|
|
28
|
+
if (!input) {
|
|
29
|
+
throw new Error("no input");
|
|
30
|
+
}
|
|
31
|
+
debug("reading request body from data");
|
|
32
|
+
try {
|
|
33
|
+
(0, config_1.set)({ data: JSON.parse(input) });
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (config.verbose) {
|
|
37
|
+
// eslint-disable-next-line
|
|
38
|
+
console.log("Failed to parse input data. Is it a valid escaped JSON string?");
|
|
39
|
+
}
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.create = create;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const config_1 = require("../../config");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const utils_1 = require("../../utils/utils");
|
|
7
|
+
const next_1 = require("./next");
|
|
8
|
+
const options_1 = require("./options");
|
|
9
|
+
const MANDATORY_OPTIONS = [
|
|
10
|
+
constants_1.OPTION_VERBOSE,
|
|
11
|
+
constants_1.OPTION_OPTIONS_FILE,
|
|
12
|
+
{ ...constants_1.OPTION_HOST, required: true },
|
|
13
|
+
];
|
|
14
|
+
const post = () => async () => {
|
|
15
|
+
const config = (0, config_1.get)();
|
|
16
|
+
const tenant = (0, utils_1.parseTenant)(config.options[constants_1.OPTION_HOST.longName]);
|
|
17
|
+
const info = (0, utils_1.getInfoFromTenant)(tenant, config.verbose);
|
|
18
|
+
for (const [key, value] of Object.entries(info)) {
|
|
19
|
+
if (!config[key]) {
|
|
20
|
+
(0, config_1.set)({ [key]: value });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const create = () => (0, next_1.create)((0, options_1.create)(MANDATORY_OPTIONS), post);
|
|
25
|
+
exports.create = create;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const stackTrace_1 = require("./stackTrace");
|
|
5
|
+
const nextHandler = (...handlers) => (command) => {
|
|
6
|
+
const commandHandlers = [];
|
|
7
|
+
for (const handler of handlers) {
|
|
8
|
+
commandHandlers.push(handler(command));
|
|
9
|
+
}
|
|
10
|
+
return async (...args) => {
|
|
11
|
+
for (const handler of commandHandlers) {
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
await handler(...args);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const create = (...handlers) => (0, stackTrace_1.create)(nextHandler(...handlers));
|
|
18
|
+
exports.create = create;
|
|
19
|
+
/* jscpd:ignore-end */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const logger_1 = require("../../../logger");
|
|
5
|
+
const utils_1 = require("../../../utils/utils");
|
|
6
|
+
const utils_2 = require("./utils");
|
|
7
|
+
/* jscpd:ignore-start */
|
|
8
|
+
const create = (option) => () => async () => {
|
|
9
|
+
const { debug } = (0, logger_1.get)("commands.handler.options.env");
|
|
10
|
+
/* jscpd:ignore-end */
|
|
11
|
+
debug(`reading option ${option.longName} from env`);
|
|
12
|
+
if (!process.env[(0, utils_1.toConstantCase)(option.longName)]) {
|
|
13
|
+
throw new Error(`env variable process.env.${(0, utils_1.toConstantCase)(option.longName)} is not set`);
|
|
14
|
+
}
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
16
|
+
(0, utils_2.setOption)(option, process.env[(0, utils_1.toConstantCase)(option.longName)]);
|
|
17
|
+
};
|
|
18
|
+
exports.create = create;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const constants_1 = require("../../../constants");
|
|
5
|
+
const logger_1 = require("../../../logger");
|
|
6
|
+
const options_1 = require("../../../utils/options");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
/* jscpd:ignore-start */
|
|
9
|
+
const create = (option) => () => async () => {
|
|
10
|
+
const { debug, trace } = (0, logger_1.get)("commands.handler.options.file");
|
|
11
|
+
/* jscpd:ignore-end */
|
|
12
|
+
debug(`reading option ${option.longName} from file`);
|
|
13
|
+
const filePath = (0, options_1.getOptionValueFromConfig)(constants_1.OPTION_OPTIONS_FILE);
|
|
14
|
+
try {
|
|
15
|
+
(0, utils_1.setOption)(option, await (0, utils_1.getValueFromOptionsFile)(filePath, option));
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
trace(`failed to read option ${option.longName} from options file ${filePath}`, err);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.create = create;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Handler, Option } from "../../../types";
|
|
2
|
+
export declare const create: (options: Array<Option> | Option, { readPipe, readEnv, readFile, readOptions }?: {
|
|
3
|
+
readPipe: boolean;
|
|
4
|
+
readEnv: boolean;
|
|
5
|
+
readFile: boolean;
|
|
6
|
+
readOptions: boolean;
|
|
7
|
+
}, promptAlways?: boolean, throwIfHandlersFailed?: boolean) => Handler;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-await-in-loop */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.create = void 0;
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const or_1 = require("../or");
|
|
7
|
+
const next_1 = require("../next");
|
|
8
|
+
const checkOptionsExistence_1 = require("../checkOptionsExistence");
|
|
9
|
+
const pipe_1 = require("./pipe");
|
|
10
|
+
const file_1 = require("./file");
|
|
11
|
+
const option_1 = require("./option");
|
|
12
|
+
const succeed_1 = require("../succeed");
|
|
13
|
+
const fail_1 = require("../fail");
|
|
14
|
+
const env_1 = require("./env");
|
|
15
|
+
const createHandler = (use, option, handler) => (0, next_1.create)((0, checkOptionsExistence_1.create)(option), use ? handler : (0, succeed_1.create)());
|
|
16
|
+
const create = (options, { readPipe, readEnv, readFile, readOptions } = {
|
|
17
|
+
readPipe: true,
|
|
18
|
+
readEnv: true,
|
|
19
|
+
readFile: true,
|
|
20
|
+
readOptions: true,
|
|
21
|
+
}, promptAlways = false, throwIfHandlersFailed = false) => (command) => {
|
|
22
|
+
const intOptions = Array.isArray(options) ? options : [options];
|
|
23
|
+
(0, utils_1.checkOptions)(intOptions, command);
|
|
24
|
+
return async () => {
|
|
25
|
+
for (const option of intOptions) {
|
|
26
|
+
await (0, or_1.create)((0, checkOptionsExistence_1.create)(option, false), (0, or_1.create)(createHandler(readPipe, option, (0, pipe_1.create)(option)), createHandler(readEnv, option, (0, env_1.create)(option)), createHandler(readFile, option, (0, file_1.create)(option)), createHandler(readOptions, option, (0, option_1.create)(option, promptAlways))), throwIfHandlersFailed
|
|
27
|
+
? (0, fail_1.create)()
|
|
28
|
+
: (0, succeed_1.create)())(command)();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.create = create;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const logger_1 = require("../../../logger");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const create = (option, promptAlways = false) => () => async () => {
|
|
7
|
+
const { debug } = (0, logger_1.get)("commands.handler.options.option");
|
|
8
|
+
debug(`reading option ${option.longName} from options`);
|
|
9
|
+
if (option.required || promptAlways) {
|
|
10
|
+
if (!option.prompts) {
|
|
11
|
+
throw new Error(`inconsistent option ${option.longName}, no prompts configuration available`);
|
|
12
|
+
}
|
|
13
|
+
const value = await (0, utils_1.promptForValue)(option);
|
|
14
|
+
(0, utils_1.setOption)(option, value);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
throw new Error(`option ${option.longName} is not required and promptAlways is false`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.create = create;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const logger_1 = require("../../../logger");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const getLogger = () => (0, logger_1.get)("commands.handler.options.pipe");
|
|
8
|
+
let data;
|
|
9
|
+
const getDataFromPipe = () => {
|
|
10
|
+
if (data === undefined) {
|
|
11
|
+
try {
|
|
12
|
+
data = JSON.parse((0, fs_extra_1.readFileSync)(0, "utf-8"));
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
const { error } = getLogger();
|
|
16
|
+
error("failed to read from pipe", err);
|
|
17
|
+
data = null;
|
|
18
|
+
return getDataFromPipe();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (data === null) {
|
|
22
|
+
throw new Error("no data received from pipe");
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
/* jscpd:ignore-start */
|
|
27
|
+
const create = (option) => () => async () => {
|
|
28
|
+
const { debug } = getLogger();
|
|
29
|
+
/* jscpd:ignore-end */
|
|
30
|
+
debug(`reading option ${option.longName} from pipe`);
|
|
31
|
+
const options = getDataFromPipe();
|
|
32
|
+
(0, utils_1.setOption)(option, options[option.longName]);
|
|
33
|
+
};
|
|
34
|
+
exports.create = create;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { Option } from "../../../types";
|
|
3
|
+
export declare const checkOptions: (options: Array<Option> | Option, command: Command) => void;
|
|
4
|
+
export declare const promptForValue: (option: Option) => Promise<string>;
|
|
5
|
+
export declare const setOption: (option: Option, value: string) => void;
|
|
6
|
+
export declare const getValueFromOptionsFile: (filePath: string, { longName }: Option) => Promise<string>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getValueFromOptionsFile = exports.setOption = exports.promptForValue = exports.checkOptions = void 0;
|
|
8
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
9
|
+
const fs_extra_1 = require("fs-extra");
|
|
10
|
+
const logger_1 = require("../../../logger");
|
|
11
|
+
const commands_1 = require("../../../utils/commands");
|
|
12
|
+
const config_1 = require("../../../config");
|
|
13
|
+
const checkOptions = (options, command) => {
|
|
14
|
+
const intOptions = Array.isArray(options) ? options : [options];
|
|
15
|
+
for (const option of intOptions) {
|
|
16
|
+
if (!(0, commands_1.isOptionAlreadyRegistered)(option, command)) {
|
|
17
|
+
command.addOption((0, commands_1.buildOption)({ ...option, required: false }));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.checkOptions = checkOptions;
|
|
22
|
+
const promptForValue = async (option) => {
|
|
23
|
+
const { value } = await prompts_1.default.prompt({
|
|
24
|
+
type: option.prompts.type,
|
|
25
|
+
choices: option.choices?.map((choice) => ({
|
|
26
|
+
title: choice,
|
|
27
|
+
value: choice,
|
|
28
|
+
})),
|
|
29
|
+
initial: option.prompts.initial,
|
|
30
|
+
message: typeof option.prompts.message === "string"
|
|
31
|
+
? option.prompts.message
|
|
32
|
+
: option.prompts.message(),
|
|
33
|
+
name: "value",
|
|
34
|
+
});
|
|
35
|
+
if (option.prompts?.inputValidator) {
|
|
36
|
+
if (!option.prompts.inputValidator(value)) {
|
|
37
|
+
throw new Error(`input validator returned false for value ${value}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
exports.promptForValue = promptForValue;
|
|
43
|
+
const buildOptionName = (option) => `--${option.longName}`;
|
|
44
|
+
const setOption = (option, value) => {
|
|
45
|
+
const { output } = (0, logger_1.get)("handler.options");
|
|
46
|
+
if (!value && (option.args || []).length > 0) {
|
|
47
|
+
const name = buildOptionName(option);
|
|
48
|
+
output(`error: required option '${name}' not specified`);
|
|
49
|
+
throw new Error(`no value provided for option ${option.longName}`);
|
|
50
|
+
}
|
|
51
|
+
(0, config_1.set)({
|
|
52
|
+
options: { [option.longName]: value },
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.setOption = setOption;
|
|
56
|
+
const getValueFromOptionsFile = async (filePath, { longName }) => {
|
|
57
|
+
const options = JSON.parse(await (0, fs_extra_1.readFile)(filePath, { encoding: "utf8" }));
|
|
58
|
+
if (options[longName]) {
|
|
59
|
+
return options[longName];
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`no value for option ${longName} found in file ${filePath}`);
|
|
62
|
+
};
|
|
63
|
+
exports.getValueFromOptionsFile = getValueFromOptionsFile;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const logger_1 = require("../../logger");
|
|
5
|
+
const getLogger = () => (0, logger_1.get)("commands.handlers.or");
|
|
6
|
+
const create = (...handlers) => {
|
|
7
|
+
const { stack } = new Error();
|
|
8
|
+
return (command) => {
|
|
9
|
+
const commandHandlers = [];
|
|
10
|
+
for (const handler of handlers) {
|
|
11
|
+
commandHandlers.push(handler(command));
|
|
12
|
+
}
|
|
13
|
+
return async (...args) => {
|
|
14
|
+
const { debug, trace } = getLogger();
|
|
15
|
+
let handlerFailed = false;
|
|
16
|
+
for (const handler of commandHandlers) {
|
|
17
|
+
handlerFailed = false;
|
|
18
|
+
try {
|
|
19
|
+
// eslint-disable-next-line
|
|
20
|
+
await handler(...args);
|
|
21
|
+
trace(`handler succeeded, exiting loop`);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
debug(`handler failed`, err.stack || err);
|
|
26
|
+
handlerFailed = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (handlerFailed) {
|
|
30
|
+
trace("handler was created from:", stack);
|
|
31
|
+
throw new Error("all handlers failed");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.create = create;
|
|
37
|
+
/* jscpd:ignore-end */
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const config_1 = require("../../config");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const constants_1 = require("../../constants");
|
|
8
|
+
const logger_1 = require("../../logger");
|
|
9
|
+
const create = (handlerArgs) => () => async (...args) => {
|
|
10
|
+
const { debug } = (0, logger_1.get)("commands.handler.parseArguments");
|
|
11
|
+
const command = args[args.length - 1].name();
|
|
12
|
+
const options = Object.entries(args[args.length - 2])
|
|
13
|
+
.map((o) => [o[0], (0, utils_1.parseOption)(o[1])])
|
|
14
|
+
.reduce((prev, curr) => ({ ...prev, [(0, lodash_1.kebabCase)(curr[0])]: curr[1] }), {});
|
|
15
|
+
const commandArgs = handlerArgs
|
|
16
|
+
? handlerArgs.reduce((p, c, i) => ({ ...p, [c.argument]: args[i] }), {})
|
|
17
|
+
: {};
|
|
18
|
+
const verbose = (0, utils_1.getBooleanOption)(options[constants_1.OPTION_VERBOSE.longName]);
|
|
19
|
+
debug("setting command: %s, options: %s, arguments: %s, verbose: %s", command, JSON.stringify(options), JSON.stringify(commandArgs), verbose);
|
|
20
|
+
(0, config_1.set)({ command, options, arguments: commandArgs, verbose });
|
|
21
|
+
};
|
|
22
|
+
exports.create = create;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const logger_1 = require("../../logger");
|
|
5
|
+
const create = (handler) => (command) => {
|
|
6
|
+
const commandHandler = handler(command);
|
|
7
|
+
return async (...args) => {
|
|
8
|
+
try {
|
|
9
|
+
await commandHandler(...args);
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
const { error } = (0, logger_1.get)("commands.handler.resilient");
|
|
13
|
+
error("handler failed, ignoring it silently", err);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.create = create;
|
|
18
|
+
/* jscpd:ignore-end */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const logger_1 = require("../../../logger");
|
|
5
|
+
const create = (handler, errorMessage = "Command failed") => (command) => {
|
|
6
|
+
const { output } = (0, logger_1.get)("handler.root");
|
|
7
|
+
const hdlr = handler(command);
|
|
8
|
+
return async (...args) => {
|
|
9
|
+
try {
|
|
10
|
+
await hdlr(...args);
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
output(errorMessage);
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.create = create;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const logger_1 = require("../../logger");
|
|
5
|
+
const create = (handler) => {
|
|
6
|
+
const { stack } = new Error();
|
|
7
|
+
return (command) => {
|
|
8
|
+
const commandHandler = handler(command);
|
|
9
|
+
return async (...args) => {
|
|
10
|
+
try {
|
|
11
|
+
await commandHandler(...args);
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
const { trace } = (0, logger_1.get)("commands.handler.stackTrace");
|
|
15
|
+
trace("handler was created from:", stack);
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.create = create;
|
|
22
|
+
/* jscpd:ignore-end */
|