@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
package/dwc/dwc.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
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.getCommands = exports.executeCommand = exports.init = void 0;
|
|
7
|
+
if (process.env.SUPPRESS_NO_CONFIG_WARNING === undefined) {
|
|
8
|
+
process.env.SUPPRESS_NO_CONFIG_WARNING = "true";
|
|
9
|
+
}
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
const cache_1 = require("../cache");
|
|
15
|
+
const config_1 = require("../config");
|
|
16
|
+
const commands_1 = require("../utils/commands");
|
|
17
|
+
const discovery_1 = require("../discovery");
|
|
18
|
+
const settings_1 = require("../settings");
|
|
19
|
+
const utils_1 = require("./utils");
|
|
20
|
+
const utils_2 = require("../commands/handler/options/utils");
|
|
21
|
+
const core_1 = require("../config/core");
|
|
22
|
+
const ResultHandlerImpl_1 = require("../result/ResultHandlerImpl");
|
|
23
|
+
const ResultHandlerFactory_1 = require("../result/ResultHandlerFactory");
|
|
24
|
+
let program;
|
|
25
|
+
let initialized = false;
|
|
26
|
+
const getLogger = () => (0, logger_1.get)("dwc.dwc");
|
|
27
|
+
const MANDATORY_OPTIONS = [
|
|
28
|
+
constants_1.OPTION_VERSION,
|
|
29
|
+
constants_1.OPTION_HELP,
|
|
30
|
+
constants_1.OPTION_HOST,
|
|
31
|
+
constants_1.OPTION_FILE_PATH,
|
|
32
|
+
constants_1.OPTION_FORCE,
|
|
33
|
+
constants_1.OPTION_OUTPUT,
|
|
34
|
+
constants_1.OPTION_VERBOSE,
|
|
35
|
+
constants_1.OPTION_INPUT,
|
|
36
|
+
constants_1.OPTION_OPTIONS_FILE,
|
|
37
|
+
];
|
|
38
|
+
const setTenant = async () => {
|
|
39
|
+
const config = (0, config_1.get)();
|
|
40
|
+
if (config.host) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const readHostFromArgv = async () => (0, utils_1.getOptionValueFromArgv)(constants_1.OPTION_HOST);
|
|
44
|
+
const readHostFromOptionsFile = async () => {
|
|
45
|
+
const filePath = (0, utils_1.getOptionValueFromArgv)(constants_1.OPTION_OPTIONS_FILE);
|
|
46
|
+
return (0, utils_2.getValueFromOptionsFile)(filePath, constants_1.OPTION_HOST);
|
|
47
|
+
};
|
|
48
|
+
const readHostFromOptions = async () => {
|
|
49
|
+
if (!config.options?.[constants_1.OPTION_HOST.longName]) {
|
|
50
|
+
throw new Error("host not found in options");
|
|
51
|
+
}
|
|
52
|
+
return config.options[constants_1.OPTION_HOST.longName];
|
|
53
|
+
};
|
|
54
|
+
const strategies = [
|
|
55
|
+
{
|
|
56
|
+
func: readHostFromArgv,
|
|
57
|
+
name: "read host from argv",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
func: readHostFromOptionsFile,
|
|
61
|
+
name: "read host from options-file",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
func: readHostFromOptions,
|
|
65
|
+
name: "read host from options",
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
const { trace } = getLogger();
|
|
69
|
+
for (const { name, func } of strategies) {
|
|
70
|
+
trace(`trying to ${name}`);
|
|
71
|
+
try {
|
|
72
|
+
// eslint-disable-next-line no-await-in-loop
|
|
73
|
+
const host = await func();
|
|
74
|
+
(0, config_1.set)({ tenant: host });
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
trace(`failed to ${name}`, err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const setHost = async () => {
|
|
82
|
+
const settings = await (0, settings_1.get)();
|
|
83
|
+
if (settings.host) {
|
|
84
|
+
(0, config_1.set)({ options: { [constants_1.OPTION_HOST.longName]: settings.host } });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const initCacheTolerant = async () => {
|
|
88
|
+
try {
|
|
89
|
+
await (0, cache_1.init)();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// ignore
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const registerMandatoryOptions = () => {
|
|
96
|
+
MANDATORY_OPTIONS.forEach((option) => (0, commands_1.registerLongName)(option.longName));
|
|
97
|
+
};
|
|
98
|
+
const init = async () => {
|
|
99
|
+
const { error, debug } = getLogger();
|
|
100
|
+
if (initialized) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
initialized = true;
|
|
104
|
+
const resultHandler = new ResultHandlerImpl_1.ResultHandlerImpl();
|
|
105
|
+
ResultHandlerFactory_1.ResultHandlerFactory.set(resultHandler);
|
|
106
|
+
registerMandatoryOptions();
|
|
107
|
+
await setHost();
|
|
108
|
+
await setTenant();
|
|
109
|
+
await initCacheTolerant();
|
|
110
|
+
program = (0, commands_1.createCommand)();
|
|
111
|
+
program.version((0, core_1.getVersion)(), "-v, --version", "output the current version");
|
|
112
|
+
program.description((0, config_1.get)()[constants_1.CLI_DESCRIPTION]);
|
|
113
|
+
program.showHelpAfterError(`Did you initialize the CLI by running ${(0, config_1.get)()[constants_1.CLI_NAME]} cache init -H "<Server_URL>"?` +
|
|
114
|
+
` Add --help, -h or go to ${(0, config_1.get)()[constants_1.CLI_SAP_HELP]} for additional information.`);
|
|
115
|
+
program.addOption((0, commands_1.buildOption)(constants_1.OPTION_HOST));
|
|
116
|
+
program.addOption((0, commands_1.buildOption)(constants_1.OPTION_OPTIONS_FILE));
|
|
117
|
+
program.configureHelp({ sortSubcommands: true });
|
|
118
|
+
const commandsPath = path_1.default.join(__dirname, "..", "commands");
|
|
119
|
+
for (const file of (await fs_extra_1.default.readdir(commandsPath, {
|
|
120
|
+
encoding: "utf-8",
|
|
121
|
+
withFileTypes: false,
|
|
122
|
+
})).filter((f) => f.includes(".command") && !f.endsWith(".d.ts"))) {
|
|
123
|
+
try {
|
|
124
|
+
// eslint-disable-next-line
|
|
125
|
+
const content = require(path_1.default.join(commandsPath, file));
|
|
126
|
+
if (content.addCommands) {
|
|
127
|
+
debug("adding commands from file %s.addCommands", file);
|
|
128
|
+
// eslint-disable-next-line
|
|
129
|
+
await content.addCommands(program);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
debug("adding command from file %s.default", file);
|
|
133
|
+
(0, commands_1.buildCommand)(program, content.default);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
error("error while adding command from file %s:", file, err.stack);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
debug("cli initialized");
|
|
141
|
+
};
|
|
142
|
+
exports.init = init;
|
|
143
|
+
const executeCommand = async (command) => {
|
|
144
|
+
await program.parseAsync(command?.split(" ") || undefined);
|
|
145
|
+
};
|
|
146
|
+
exports.executeCommand = executeCommand;
|
|
147
|
+
const buildCommandsObject = (name, command, object = {}) => {
|
|
148
|
+
const commandName = name || "dwc";
|
|
149
|
+
// eslint-disable-next-line no-param-reassign
|
|
150
|
+
object[commandName] = async (options) => {
|
|
151
|
+
await (0, exports.executeCommand)(new Array(2)
|
|
152
|
+
.fill("dummy")
|
|
153
|
+
.concat(name.split(" ").concat(options
|
|
154
|
+
? Object.entries(options).reduce((prev, curr) => {
|
|
155
|
+
const [key, value] = curr;
|
|
156
|
+
return prev.concat([key, value]);
|
|
157
|
+
}, [])
|
|
158
|
+
: []))
|
|
159
|
+
.join(" "));
|
|
160
|
+
return ResultHandlerFactory_1.ResultHandlerFactory.get().getResult();
|
|
161
|
+
};
|
|
162
|
+
/* istanbul ignore next */
|
|
163
|
+
command.commands.forEach((c) => {
|
|
164
|
+
buildCommandsObject(name ? `${name} ${c.name()}` : c.name(), c, object);
|
|
165
|
+
});
|
|
166
|
+
return object;
|
|
167
|
+
};
|
|
168
|
+
const reinitialize = (host) => {
|
|
169
|
+
initialized = false;
|
|
170
|
+
(0, config_1.initialize)();
|
|
171
|
+
(0, config_1.set)({ tenant: host });
|
|
172
|
+
(0, config_1.setCustomConfig)();
|
|
173
|
+
(0, discovery_1.clear)();
|
|
174
|
+
};
|
|
175
|
+
const getCommands = async (host) => {
|
|
176
|
+
reinitialize(host);
|
|
177
|
+
await (0, exports.init)();
|
|
178
|
+
return buildCommandsObject("", program);
|
|
179
|
+
};
|
|
180
|
+
exports.getCommands = getCommands;
|
package/dwc/run.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const run: () => Promise<void>;
|
package/dwc/run.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = void 0;
|
|
4
|
+
const core_1 = require("../config/core");
|
|
5
|
+
const logger_1 = require("../logger");
|
|
6
|
+
const dwc_1 = require("./dwc");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const run = async () => {
|
|
9
|
+
const { error, debug, output } = (0, logger_1.get)("dwc.run");
|
|
10
|
+
let exitCode = 0;
|
|
11
|
+
try {
|
|
12
|
+
await (0, dwc_1.init)();
|
|
13
|
+
await (0, utils_1.checkVersion)();
|
|
14
|
+
await (0, dwc_1.executeCommand)();
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (err.code === "commander.helpDisplayed") {
|
|
18
|
+
debug("Error while running CLI", err.stack);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
error("Error while running CLI", err.stack);
|
|
22
|
+
exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
await (0, utils_1.compareEtags)();
|
|
27
|
+
if ((0, core_1.isDeprecated)()) {
|
|
28
|
+
const message = (0, core_1.getDeprecationMessage)() ||
|
|
29
|
+
"WARNING: This package has been deprecated. Please consult the README or CHANGELOG for more information.";
|
|
30
|
+
output(message);
|
|
31
|
+
}
|
|
32
|
+
if (exitCode > 0) {
|
|
33
|
+
process.exit(exitCode);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.run = run;
|
package/dwc/utils.d.ts
ADDED
package/dwc/utils.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOptionValueFromArgv = exports.compareEtags = exports.checkVersion = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const discovery_1 = require("../discovery");
|
|
6
|
+
const commands_1 = require("../utils/commands");
|
|
7
|
+
const core_1 = require("../config/core");
|
|
8
|
+
const getLogger = () => (0, logger_1.get)("dwc.utils");
|
|
9
|
+
const checkVersion = async () => {
|
|
10
|
+
const { output, error } = getLogger();
|
|
11
|
+
try {
|
|
12
|
+
const result = await (0, discovery_1.checkVersion)();
|
|
13
|
+
if (result.status === "OUTDATED") {
|
|
14
|
+
output(`Your local CLI installation is outdated. Run 'npm install ${(0, core_1.getPackageName)()} [-g]' to update`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
error(err.stack);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.checkVersion = checkVersion;
|
|
22
|
+
const compareEtags = async () => {
|
|
23
|
+
if (!(await (0, discovery_1.compareEtags)())) {
|
|
24
|
+
const { output } = getLogger();
|
|
25
|
+
output(`Your local CLI cache is outdated. Run 'dwc cache init' to update`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.compareEtags = compareEtags;
|
|
29
|
+
const getOptionValueFromArgv = ({ longName }) => {
|
|
30
|
+
const shortFlag = (0, commands_1.getShortFlagForLongName)(longName);
|
|
31
|
+
const index = process.argv.findIndex((a) => a === `-${shortFlag}` || a === `--${longName}`);
|
|
32
|
+
if (index > -1) {
|
|
33
|
+
return process.argv[index + 1];
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`option ${longName} not found in argv`);
|
|
36
|
+
};
|
|
37
|
+
exports.getOptionValueFromArgv = getOptionValueFromArgv;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthenticationMethod } from "./constants";
|
|
2
|
+
export { run } from "./dwc/run";
|
|
3
|
+
export { configure, getCommands } from "./module";
|
|
4
|
+
export { AuthenticationMethod };
|
|
5
|
+
export { getVersion, getBin, getDescription, getName, getPackageName, } from "./utils/utils";
|
|
6
|
+
export declare const configureCoreModule: ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods, version, deprecated, deprecationMessage, }: {
|
|
7
|
+
name: string;
|
|
8
|
+
packageName: string;
|
|
9
|
+
discoveryPath: string;
|
|
10
|
+
description: string;
|
|
11
|
+
sapHelpLink: string;
|
|
12
|
+
authenticationMethods?: AuthenticationMethod[] | undefined;
|
|
13
|
+
version: string;
|
|
14
|
+
deprecated?: boolean | undefined;
|
|
15
|
+
deprecationMessage?: string | undefined;
|
|
16
|
+
}) => void;
|
package/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable import/first */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.configureCoreModule = exports.getPackageName = exports.getName = exports.getDescription = exports.getBin = exports.getVersion = exports.AuthenticationMethod = exports.getCommands = exports.configure = exports.run = void 0;
|
|
28
|
+
const dotenv = __importStar(require("dotenv"));
|
|
29
|
+
const configureLoggers_1 = require("./configureLoggers");
|
|
30
|
+
dotenv.config();
|
|
31
|
+
(0, configureLoggers_1.configureLoggers)();
|
|
32
|
+
const config_1 = require("./config");
|
|
33
|
+
const constants_1 = require("./constants");
|
|
34
|
+
Object.defineProperty(exports, "AuthenticationMethod", { enumerable: true, get: function () { return constants_1.AuthenticationMethod; } });
|
|
35
|
+
var run_1 = require("./dwc/run");
|
|
36
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_1.run; } });
|
|
37
|
+
var module_1 = require("./module");
|
|
38
|
+
Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return module_1.configure; } });
|
|
39
|
+
Object.defineProperty(exports, "getCommands", { enumerable: true, get: function () { return module_1.getCommands; } });
|
|
40
|
+
var utils_1 = require("./utils/utils");
|
|
41
|
+
Object.defineProperty(exports, "getVersion", { enumerable: true, get: function () { return utils_1.getVersion; } });
|
|
42
|
+
Object.defineProperty(exports, "getBin", { enumerable: true, get: function () { return utils_1.getBin; } });
|
|
43
|
+
Object.defineProperty(exports, "getDescription", { enumerable: true, get: function () { return utils_1.getDescription; } });
|
|
44
|
+
Object.defineProperty(exports, "getName", { enumerable: true, get: function () { return utils_1.getName; } });
|
|
45
|
+
Object.defineProperty(exports, "getPackageName", { enumerable: true, get: function () { return utils_1.getPackageName; } });
|
|
46
|
+
const configureCoreModule = ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods = [constants_1.AuthenticationMethod.oauth], version, deprecated = false, deprecationMessage, }) => {
|
|
47
|
+
(0, config_1.set)({
|
|
48
|
+
[constants_1.CLI_NAME]: name,
|
|
49
|
+
[constants_1.CLI_PACKAGE_NAME]: packageName,
|
|
50
|
+
[constants_1.CLI_DESCRIPTION]: description,
|
|
51
|
+
[constants_1.CLI_DISCOVERY_PATH]: discoveryPath,
|
|
52
|
+
[constants_1.CLI_SAP_HELP]: sapHelpLink,
|
|
53
|
+
[constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS]: authenticationMethods,
|
|
54
|
+
[constants_1.CLI_VERSION]: version,
|
|
55
|
+
[constants_1.CLI_DEPRECATED]: deprecated,
|
|
56
|
+
[constants_1.CLI_DEPRECATION_MESSAGE]: deprecationMessage,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
exports.configureCoreModule = configureCoreModule;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LogLevel } from "../types";
|
|
2
|
+
type Method = (...args: Array<any>) => void;
|
|
3
|
+
export type Logger = {
|
|
4
|
+
output: Method;
|
|
5
|
+
error: Method;
|
|
6
|
+
warn: Method;
|
|
7
|
+
info: Method;
|
|
8
|
+
log: Method;
|
|
9
|
+
debug: Method;
|
|
10
|
+
trace: Method;
|
|
11
|
+
};
|
|
12
|
+
type CustomLogger = {
|
|
13
|
+
output?: Method;
|
|
14
|
+
error?: Method;
|
|
15
|
+
warn?: Method;
|
|
16
|
+
info?: Method;
|
|
17
|
+
log?: Method;
|
|
18
|
+
debug?: Method;
|
|
19
|
+
trace?: Method;
|
|
20
|
+
};
|
|
21
|
+
export type Configuration = {
|
|
22
|
+
logLevel?: LogLevel;
|
|
23
|
+
loggers?: RegExp | "RESET";
|
|
24
|
+
customLogger?: CustomLogger | "RESET";
|
|
25
|
+
};
|
|
26
|
+
export declare const configure: ({ logLevel: newLogLevel, loggers: newLoggers, customLogger: newCustomLogger, }: Configuration) => void;
|
|
27
|
+
export declare const get: (namespace: string) => Logger;
|
|
28
|
+
export {};
|
package/logger/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get = exports.configure = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const LogLevel2Console = {
|
|
6
|
+
[types_1.LogLevel.INACTIVE]: "inactive",
|
|
7
|
+
[types_1.LogLevel.ERROR]: "error",
|
|
8
|
+
[types_1.LogLevel.WARN]: "warn",
|
|
9
|
+
[types_1.LogLevel.INFO]: "info",
|
|
10
|
+
[types_1.LogLevel.DEBUG]: "debug",
|
|
11
|
+
[types_1.LogLevel.TRACE]: "info",
|
|
12
|
+
};
|
|
13
|
+
let logLevel = types_1.LogLevel.INACTIVE;
|
|
14
|
+
let loggers;
|
|
15
|
+
let customLogger;
|
|
16
|
+
const configure = ({ logLevel: newLogLevel, loggers: newLoggers, customLogger: newCustomLogger, }) => {
|
|
17
|
+
if (newLogLevel) {
|
|
18
|
+
logLevel = newLogLevel;
|
|
19
|
+
}
|
|
20
|
+
if (newLoggers === "RESET") {
|
|
21
|
+
loggers = undefined;
|
|
22
|
+
}
|
|
23
|
+
else if (newLoggers) {
|
|
24
|
+
loggers = newLoggers;
|
|
25
|
+
}
|
|
26
|
+
if (newCustomLogger === "RESET") {
|
|
27
|
+
customLogger = undefined;
|
|
28
|
+
}
|
|
29
|
+
else if (newCustomLogger) {
|
|
30
|
+
customLogger = newCustomLogger;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.configure = configure;
|
|
34
|
+
const logMessage = (namespace, level) => (...args) => {
|
|
35
|
+
if (level <= logLevel && (loggers ? loggers.test(namespace) : true)) {
|
|
36
|
+
// @ts-expect-error ts(7053)
|
|
37
|
+
// eslint-disable-next-line
|
|
38
|
+
customLogger?.[LogLevel2Console[level]]
|
|
39
|
+
? // @ts-expect-error ts(7053)
|
|
40
|
+
customLogger[LogLevel2Console[level]](...args)
|
|
41
|
+
: // @ts-expect-error ts(7053)
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
console[LogLevel2Console[level]](...[
|
|
44
|
+
`[${namespace}:${level === types_1.LogLevel.TRACE ? "trace" : LogLevel2Console[level]}:${new Date().toISOString()}] ${args[0]}`,
|
|
45
|
+
...args.slice(1),
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const get = (namespace) => {
|
|
50
|
+
return {
|
|
51
|
+
output: customLogger?.output
|
|
52
|
+
? customLogger.output
|
|
53
|
+
: // eslint-disable-next-line
|
|
54
|
+
(...args) => console.log(...args),
|
|
55
|
+
error: logMessage(namespace, types_1.LogLevel.ERROR),
|
|
56
|
+
warn: logMessage(namespace, types_1.LogLevel.WARN),
|
|
57
|
+
info: logMessage(namespace, types_1.LogLevel.INFO),
|
|
58
|
+
log: logMessage(namespace, types_1.LogLevel.INFO),
|
|
59
|
+
debug: logMessage(namespace, types_1.LogLevel.DEBUG),
|
|
60
|
+
trace: logMessage(namespace, types_1.LogLevel.TRACE),
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
exports.get = get;
|
package/module.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PasscodeFunction } from "./commands/handler/authentication/passcode/types";
|
|
2
|
+
import { Configuration as LoggerConfiguration } from "./logger";
|
|
3
|
+
export { getCommands } from "./dwc/dwc";
|
|
4
|
+
export declare const configure: (logger?: LoggerConfiguration, passcodeFunction?: PasscodeFunction) => void;
|
package/module.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable import/first */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.configure = exports.getCommands = void 0;
|
|
28
|
+
const dotenv = __importStar(require("dotenv"));
|
|
29
|
+
const configureLoggers_1 = require("./configureLoggers");
|
|
30
|
+
dotenv.config();
|
|
31
|
+
(0, configureLoggers_1.configureLoggers)();
|
|
32
|
+
const config_1 = require("./config");
|
|
33
|
+
const constants_1 = require("./constants");
|
|
34
|
+
const logger_1 = require("./logger");
|
|
35
|
+
var dwc_1 = require("./dwc/dwc");
|
|
36
|
+
Object.defineProperty(exports, "getCommands", { enumerable: true, get: function () { return dwc_1.getCommands; } });
|
|
37
|
+
const configure = (logger, passcodeFunction) => {
|
|
38
|
+
if (logger) {
|
|
39
|
+
(0, logger_1.configure)(logger);
|
|
40
|
+
}
|
|
41
|
+
if (passcodeFunction) {
|
|
42
|
+
(0, config_1.set)({ [constants_1.CONFIG_PASSCODE_FUNCTION]: passcodeFunction });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.configure = configure;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sap/cli-core",
|
|
3
|
+
"version": "2023.12.0",
|
|
4
|
+
"description": "Command-Line Interface (CLI) Core Module",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"author": "SAP SE",
|
|
7
|
+
"homepage": "https://www.sap.com",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": "^16",
|
|
11
|
+
"npm": "^8"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"cli",
|
|
15
|
+
"sap data warehouse cloud",
|
|
16
|
+
"cli-core"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"ajv": "8.12.0",
|
|
20
|
+
"axios": "1.4.0",
|
|
21
|
+
"commander": "10.0.1",
|
|
22
|
+
"config": "3.3.9",
|
|
23
|
+
"dotenv": "16.0.3",
|
|
24
|
+
"fs-extra": "11.1.1",
|
|
25
|
+
"https": "1.0.0",
|
|
26
|
+
"lodash": "4.17.21",
|
|
27
|
+
"open": "8.4.2",
|
|
28
|
+
"path": "0.12.7",
|
|
29
|
+
"prompts": "2.4.2",
|
|
30
|
+
"qs": "6.11.1"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResultHandlerFactory = void 0;
|
|
4
|
+
class ResultHandlerFactory {
|
|
5
|
+
static get() {
|
|
6
|
+
return ResultHandlerFactory.INSTANCE;
|
|
7
|
+
}
|
|
8
|
+
static set(instance) {
|
|
9
|
+
ResultHandlerFactory.INSTANCE = instance;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ResultHandlerFactory = ResultHandlerFactory;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResultHandlerImpl = void 0;
|
|
4
|
+
class ResultHandlerImpl {
|
|
5
|
+
setResult(data) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
}
|
|
8
|
+
getResult() {
|
|
9
|
+
return this.data;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ResultHandlerImpl = ResultHandlerImpl;
|
package/result/types.js
ADDED