@sap/cli-core 2025.16.0 → 2025.19.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 +20 -0
- package/README.md +1 -1
- package/cache/cache.js +16 -28
- package/cache/index.d.ts +2 -2
- package/cache/index.js +2 -12
- package/cache/secrets/SecretsStorageImpl.d.ts +2 -3
- package/cache/secrets/SecretsStorageImpl.js +18 -25
- package/cache/secrets/SecretsStorageSingleton.d.ts +1 -1
- package/cache/secrets/SecretsStorageSingleton.js +1 -5
- package/cache/secrets/types.d.ts +1 -1
- package/cache/secrets/types.js +1 -2
- package/cache/secrets/utils.d.ts +1 -1
- package/cache/secrets/utils.js +20 -27
- package/cache/utils.js +8 -15
- package/commands/config.command/cache.command/clean.command.d.ts +1 -1
- package/commands/config.command/cache.command/clean.command.js +10 -12
- package/commands/config.command/cache.command/index.d.ts +1 -1
- package/commands/config.command/cache.command/index.js +5 -10
- package/commands/config.command/cache.command/init.command/index.d.ts +1 -1
- package/commands/config.command/cache.command/init.command/index.js +29 -36
- package/commands/config.command/cache.command/init.command/utils.d.ts +1 -1
- package/commands/config.command/cache.command/init.command/utils.js +6 -13
- package/commands/config.command/cache.command/show.command.d.ts +1 -1
- package/commands/config.command/cache.command/show.command.js +7 -9
- package/commands/config.command/host.command.d.ts +1 -1
- package/commands/config.command/host.command.js +19 -23
- package/commands/config.command/index.d.ts +1 -1
- package/commands/config.command/index.js +5 -45
- package/commands/config.command/passcode.command.d.ts +1 -1
- package/commands/config.command/passcode.command.js +12 -16
- package/commands/config.command/secrets.command/check.command.d.ts +1 -2
- package/commands/config.command/secrets.command/check.command.js +10 -14
- package/commands/config.command/secrets.command/index.d.ts +1 -1
- package/commands/config.command/secrets.command/index.js +6 -11
- package/commands/config.command/secrets.command/refresh.command.d.ts +1 -1
- package/commands/config.command/secrets.command/refresh.command.js +5 -7
- package/commands/config.command/secrets.command/reset.command.d.ts +1 -1
- package/commands/config.command/secrets.command/reset.command.js +6 -8
- package/commands/config.command/secrets.command/show.command.d.ts +1 -1
- package/commands/config.command/secrets.command/show.command.js +8 -10
- package/commands/handler/authentication/index.d.ts +1 -1
- package/commands/handler/authentication/index.js +18 -21
- package/commands/handler/authentication/oauth/index.d.ts +2 -2
- package/commands/handler/authentication/oauth/index.js +13 -16
- package/commands/handler/authentication/oauth/secretsProvider/cache.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/cache.js +5 -9
- package/commands/handler/authentication/oauth/secretsProvider/file.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/file.js +20 -25
- package/commands/handler/authentication/oauth/secretsProvider/index.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/index.js +6 -10
- package/commands/handler/authentication/oauth/secretsProvider/options.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/options.js +25 -29
- package/commands/handler/authentication/oauth/tokenProvider/getToken.d.ts +2 -2
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +18 -23
- package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +2 -2
- package/commands/handler/authentication/oauth/tokenProvider/index.js +7 -11
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +5 -9
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +19 -24
- package/commands/handler/authentication/oauth/tokenProvider/utils.js +30 -36
- package/commands/handler/authentication/oauth/utils.d.ts +1 -1
- package/commands/handler/authentication/oauth/utils.js +15 -24
- package/commands/handler/authentication/passcode/function.d.ts +1 -1
- package/commands/handler/authentication/passcode/function.js +11 -13
- package/commands/handler/authentication/passcode/index.d.ts +1 -1
- package/commands/handler/authentication/passcode/index.js +14 -17
- package/commands/handler/authentication/passcode/input.d.ts +1 -1
- package/commands/handler/authentication/passcode/input.js +13 -20
- package/commands/handler/authentication/passcode/setPasscode.d.ts +1 -1
- package/commands/handler/authentication/passcode/setPasscode.js +9 -13
- package/commands/handler/authentication/passcode/types.js +1 -2
- package/commands/handler/authentication/technicalJWT/cf.js +9 -11
- package/commands/handler/authentication/technicalJWT/exec.d.ts +5 -6
- package/commands/handler/authentication/technicalJWT/exec.js +15 -19
- package/commands/handler/authentication/technicalJWT/index.d.ts +1 -1
- package/commands/handler/authentication/technicalJWT/index.js +8 -12
- package/commands/handler/authentication/technicalJWT/types.d.ts +1 -1
- package/commands/handler/authentication/technicalJWT/types.js +1 -4
- package/commands/handler/authentication/technicalJWT/utils.js +20 -27
- package/commands/handler/authentication/utils.js +3 -7
- package/commands/handler/checkOptionsExistence.d.ts +1 -1
- package/commands/handler/checkOptionsExistence.js +5 -9
- package/commands/handler/error.d.ts +1 -1
- package/commands/handler/error.js +4 -8
- package/commands/handler/fail.d.ts +1 -1
- package/commands/handler/fail.js +3 -7
- package/commands/handler/fetch/fetch.d.ts +1 -1
- package/commands/handler/fetch/fetch.js +26 -27
- package/commands/handler/fetch/index.d.ts +1 -1
- package/commands/handler/fetch/index.js +10 -14
- package/commands/handler/fetch/utils.d.ts +2 -2
- package/commands/handler/fetch/utils.js +55 -74
- package/commands/handler/force.d.ts +1 -1
- package/commands/handler/force.js +8 -15
- package/commands/handler/index.d.ts +18 -18
- package/commands/handler/index.js +18 -39
- package/commands/handler/input/file.d.ts +1 -1
- package/commands/handler/input/file.js +22 -29
- package/commands/handler/input/index.d.ts +1 -1
- package/commands/handler/input/index.js +4 -8
- package/commands/handler/input/input.d.ts +1 -1
- package/commands/handler/input/input.js +16 -23
- package/commands/handler/mandatoryOptions.d.ts +1 -1
- package/commands/handler/mandatoryOptions.js +13 -17
- package/commands/handler/next.d.ts +1 -1
- package/commands/handler/next.js +4 -8
- package/commands/handler/options/env.d.ts +1 -1
- package/commands/handler/options/env.js +8 -12
- package/commands/handler/options/file.d.ts +1 -1
- package/commands/handler/options/file.js +8 -12
- package/commands/handler/options/index.d.ts +1 -1
- package/commands/handler/options/index.js +15 -19
- package/commands/handler/options/option.d.ts +1 -1
- package/commands/handler/options/option.js +12 -13
- package/commands/handler/options/utils.d.ts +4 -2
- package/commands/handler/options/utils.js +18 -26
- package/commands/handler/or.d.ts +1 -1
- package/commands/handler/or.js +3 -7
- package/commands/handler/parseArguments.d.ts +1 -1
- package/commands/handler/parseArguments.js +11 -15
- package/commands/handler/resilient.d.ts +1 -1
- package/commands/handler/resilient.js +3 -7
- package/commands/handler/root/index.d.ts +1 -1
- package/commands/handler/root/index.js +3 -7
- package/commands/handler/stackTrace.d.ts +1 -1
- package/commands/handler/stackTrace.js +3 -7
- package/commands/handler/succeed.d.ts +1 -1
- package/commands/handler/succeed.js +3 -7
- package/commands/handler/utils.d.ts +1 -1
- package/commands/handler/utils.js +17 -27
- package/commands/login.command.d.ts +1 -1
- package/commands/login.command.js +51 -49
- package/commands/logout.command.d.ts +1 -1
- package/commands/logout.command.js +15 -17
- package/commands/openAPI.command/index.d.ts +1 -1
- package/commands/openAPI.command/index.js +20 -24
- package/commands/openAPI.command/utils.d.ts +1 -1
- package/commands/openAPI.command/utils.js +47 -97
- package/commands/utils.d.ts +1 -1
- package/commands/utils.js +6 -11
- package/config/core.d.ts +1 -1
- package/config/core.js +12 -25
- package/config/index.d.ts +1 -1
- package/config/index.js +45 -49
- package/configureLoggers.js +2 -6
- package/constants.d.ts +4 -1
- package/constants.js +62 -59
- package/discovery/index.d.ts +1 -1
- package/discovery/index.js +32 -45
- package/discovery/utils.js +5 -12
- package/dwc/dwc.js +63 -76
- package/dwc/run.js +15 -19
- package/dwc/utils.d.ts +1 -1
- package/dwc/utils.js +42 -38
- package/index.d.ts +4 -4
- package/index.js +22 -68
- package/logger/index.d.ts +2 -2
- package/logger/index.js +17 -22
- package/logger/types.js +1 -2
- package/logger/utils.d.ts +1 -1
- package/logger/utils.js +4 -8
- package/module.d.ts +3 -3
- package/module.js +10 -48
- package/package.json +9 -7
- package/result/ResultHandlerFactory.d.ts +1 -1
- package/result/ResultHandlerFactory.js +1 -5
- package/result/ResultHandlerImpl.d.ts +1 -1
- package/result/ResultHandlerImpl.js +1 -5
- package/result/types.js +1 -2
- package/settings/index.d.ts +1 -1
- package/settings/index.js +11 -17
- package/types.d.ts +1 -1
- package/types.js +6 -9
- package/utils/commands.d.ts +3 -3
- package/utils/commands.js +23 -36
- package/utils/http/httpsAgent.d.ts +6 -0
- package/utils/http/httpsAgent.js +44 -0
- package/utils/http/index.d.ts +1 -1
- package/utils/http/index.js +31 -35
- package/utils/http/utils.d.ts +1 -1
- package/utils/http/utils.js +4 -9
- package/utils/openUtils.js +8 -14
- package/utils/options.d.ts +1 -1
- package/utils/options.js +5 -10
- package/utils/utils.d.ts +2 -2
- package/utils/utils.js +42 -94
package/discovery/utils.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validate = void 0;
|
|
7
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
-
const logger_1 = require("../logger");
|
|
9
|
-
const validate = async (schema, data) => {
|
|
10
|
-
const logger = (0, logger_1.get)("jsonschema");
|
|
1
|
+
import { Ajv } from "ajv";
|
|
2
|
+
import { get as getLogger } from "../logger/index.js";
|
|
3
|
+
export const validate = async (schema, data) => {
|
|
4
|
+
const logger = getLogger("jsonschema");
|
|
11
5
|
try {
|
|
12
|
-
const ajv = new
|
|
6
|
+
const ajv = new Ajv({ logger });
|
|
13
7
|
// use await, see ajv.js.org/api.html#ajv-validate-schemaorref-object-string-data-any-boolean
|
|
14
8
|
await ajv.validate(schema, data);
|
|
15
9
|
return {
|
|
@@ -24,4 +18,3 @@ const validate = async (schema, data) => {
|
|
|
24
18
|
};
|
|
25
19
|
}
|
|
26
20
|
};
|
|
27
|
-
exports.validate = validate;
|
package/dwc/dwc.js
CHANGED
|
@@ -1,58 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
const SecretsStorageImpl_1 = require("../cache/secrets/SecretsStorageImpl");
|
|
25
|
-
const SecretsStorageSingleton_1 = require("../cache/secrets/SecretsStorageSingleton");
|
|
26
|
-
const utils_3 = require("../commands/handler/utils");
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { get } from "../logger/index.js";
|
|
3
|
+
import { CLI_DESCRIPTION, CLI_NAME, CLI_SAP_HELP, OPTION_FILE_PATH, OPTION_FORCE, OPTION_HELP, OPTION_HOST, OPTION_INPUT, OPTION_OPTIONS_FILE, OPTION_OUTPUT, OPTION_VERBOSE, OPTION_VERSION, ROOT_COMMAND, } from "../constants.js";
|
|
4
|
+
import { init as initCache } from "../cache/index.js";
|
|
5
|
+
import { get as getConfig, set as setConfig, setCustomConfig, initialize as initializeConfig, } from "../config/index.js";
|
|
6
|
+
import { buildOption, createCommand, registerLongName, } from "../utils/commands.js";
|
|
7
|
+
import { clear as clearDiscovery } from "../discovery/index.js";
|
|
8
|
+
import { get as getSettings } from "../settings/index.js";
|
|
9
|
+
import { addCommandsFromFolder, getOptionValueFromArgv } from "./utils.js";
|
|
10
|
+
import { getValueFromOptionsFile } from "../commands/handler/options/utils.js";
|
|
11
|
+
import { getGenericOptionsHelp, getVersion } from "../config/core.js";
|
|
12
|
+
import { ResultHandlerImpl } from "../result/ResultHandlerImpl.js";
|
|
13
|
+
import { ResultHandlerFactory } from "../result/ResultHandlerFactory.js";
|
|
14
|
+
import { SecretsStorageImpl } from "../cache/secrets/SecretsStorageImpl.js";
|
|
15
|
+
import { SecretsStorageSingleton } from "../cache/secrets/SecretsStorageSingleton.js";
|
|
16
|
+
import { replaceLeadingTrailingSingleQuotes } from "../commands/handler/utils.js";
|
|
27
17
|
let program;
|
|
28
18
|
let initialized = false;
|
|
29
|
-
const getLogger = () =>
|
|
19
|
+
const getLogger = () => get("dwc.dwc");
|
|
30
20
|
const MANDATORY_OPTIONS = [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
OPTION_VERSION,
|
|
22
|
+
OPTION_HELP,
|
|
23
|
+
OPTION_HOST,
|
|
24
|
+
OPTION_FILE_PATH,
|
|
25
|
+
OPTION_FORCE,
|
|
26
|
+
OPTION_OUTPUT,
|
|
27
|
+
OPTION_VERBOSE,
|
|
28
|
+
OPTION_INPUT,
|
|
29
|
+
OPTION_OPTIONS_FILE,
|
|
40
30
|
];
|
|
41
31
|
const setTenant = async () => {
|
|
42
|
-
const config = (
|
|
32
|
+
const config = getConfig();
|
|
43
33
|
if (config.host) {
|
|
44
34
|
return;
|
|
45
35
|
}
|
|
46
|
-
const readHostFromArgv = async () =>
|
|
36
|
+
const readHostFromArgv = async () => getOptionValueFromArgv(ROOT_COMMAND, OPTION_HOST);
|
|
47
37
|
const readHostFromOptionsFile = async () => {
|
|
48
|
-
const filePath =
|
|
49
|
-
return
|
|
38
|
+
const filePath = getOptionValueFromArgv(ROOT_COMMAND, OPTION_OPTIONS_FILE);
|
|
39
|
+
return getValueFromOptionsFile(filePath, OPTION_HOST);
|
|
50
40
|
};
|
|
51
41
|
const readHostFromOptions = async () => {
|
|
52
|
-
if (!config.options?.[
|
|
42
|
+
if (!config.options?.[OPTION_HOST.longName]) {
|
|
53
43
|
throw new Error("host not found in options");
|
|
54
44
|
}
|
|
55
|
-
return config.options[
|
|
45
|
+
return config.options[OPTION_HOST.longName];
|
|
56
46
|
};
|
|
57
47
|
const strategies = [
|
|
58
48
|
{
|
|
@@ -73,10 +63,10 @@ const setTenant = async () => {
|
|
|
73
63
|
trace(`trying to ${name}`);
|
|
74
64
|
try {
|
|
75
65
|
// eslint-disable-next-line no-await-in-loop
|
|
76
|
-
const host =
|
|
77
|
-
(
|
|
66
|
+
const host = replaceLeadingTrailingSingleQuotes(await func());
|
|
67
|
+
setConfig({
|
|
78
68
|
tenant: host,
|
|
79
|
-
options: { ...config.options, [
|
|
69
|
+
options: { ...config.options, [OPTION_HOST.longName]: host },
|
|
80
70
|
});
|
|
81
71
|
break;
|
|
82
72
|
}
|
|
@@ -86,68 +76,66 @@ const setTenant = async () => {
|
|
|
86
76
|
}
|
|
87
77
|
};
|
|
88
78
|
const setHost = async () => {
|
|
89
|
-
const settings = await (
|
|
79
|
+
const settings = await getSettings();
|
|
90
80
|
if (settings.host) {
|
|
91
|
-
(
|
|
81
|
+
setConfig({ options: { [OPTION_HOST.longName]: settings.host } });
|
|
92
82
|
}
|
|
93
83
|
};
|
|
94
84
|
const initCacheTolerant = async () => {
|
|
95
85
|
try {
|
|
96
|
-
await (
|
|
86
|
+
await initCache();
|
|
97
87
|
}
|
|
98
88
|
catch {
|
|
99
89
|
// ignore
|
|
100
90
|
}
|
|
101
91
|
};
|
|
102
92
|
const registerMandatoryOptions = () => {
|
|
103
|
-
MANDATORY_OPTIONS.forEach((option) =>
|
|
93
|
+
MANDATORY_OPTIONS.forEach((option) => registerLongName(ROOT_COMMAND, option));
|
|
104
94
|
};
|
|
105
95
|
async function setupSecretsStorage() {
|
|
106
|
-
const instance = new
|
|
96
|
+
const instance = new SecretsStorageImpl();
|
|
107
97
|
await instance.initializeStorage();
|
|
108
|
-
|
|
98
|
+
SecretsStorageSingleton.SINGLETON = instance;
|
|
109
99
|
}
|
|
110
|
-
const init = async () => {
|
|
100
|
+
export const init = async () => {
|
|
111
101
|
const { debug } = getLogger();
|
|
112
102
|
if (initialized) {
|
|
113
103
|
return;
|
|
114
104
|
}
|
|
115
105
|
initialized = true;
|
|
116
|
-
const resultHandler = new
|
|
117
|
-
|
|
106
|
+
const resultHandler = new ResultHandlerImpl();
|
|
107
|
+
ResultHandlerFactory.set(resultHandler);
|
|
118
108
|
registerMandatoryOptions();
|
|
119
109
|
await setHost();
|
|
120
110
|
await setTenant();
|
|
121
111
|
await initCacheTolerant();
|
|
122
112
|
await setupSecretsStorage();
|
|
123
|
-
const cliName = (
|
|
124
|
-
program =
|
|
113
|
+
const cliName = getConfig()[CLI_NAME];
|
|
114
|
+
program = createCommand();
|
|
125
115
|
program.name(cliName);
|
|
126
|
-
program.version(
|
|
127
|
-
program.description((
|
|
116
|
+
program.version(getVersion(), "-v, --version", "output the current version");
|
|
117
|
+
program.description(getConfig()[CLI_DESCRIPTION]);
|
|
128
118
|
program.showHelpAfterError(`Make sure to always define the host using the --host option or by running ${cliName}` +
|
|
129
119
|
` config host set "<Server_URL>". Did you initialize the CLI by running ${cliName} config` +
|
|
130
120
|
` cache init --host "<Server_URL>"?` +
|
|
131
|
-
` Add option --help, -h or go to ${(
|
|
132
|
-
program.addOption(await
|
|
133
|
-
program.addOption(await
|
|
121
|
+
` Add option --help, -h or go to ${getConfig()[CLI_SAP_HELP]} for additional information.`);
|
|
122
|
+
program.addOption(await buildOption(ROOT_COMMAND, OPTION_HOST));
|
|
123
|
+
program.addOption(await buildOption(ROOT_COMMAND, OPTION_OPTIONS_FILE));
|
|
134
124
|
program.configureHelp({ sortSubcommands: true });
|
|
135
125
|
program.addHelpText("afterAll", `Only command-specific options are listed here. To learn more about available generic options,` +
|
|
136
|
-
` visit ${
|
|
137
|
-
const commandsPath =
|
|
138
|
-
await
|
|
126
|
+
` visit ${getGenericOptionsHelp()}`);
|
|
127
|
+
const commandsPath = path.join(import.meta.dirname, "..", "commands");
|
|
128
|
+
await addCommandsFromFolder(commandsPath, program);
|
|
139
129
|
debug("cli initialized");
|
|
140
130
|
};
|
|
141
|
-
|
|
142
|
-
const executeCommand = async (command) => {
|
|
131
|
+
export const executeCommand = async (command) => {
|
|
143
132
|
await program.parseAsync(command?.split(" ") ?? undefined);
|
|
144
133
|
};
|
|
145
|
-
exports.executeCommand = executeCommand;
|
|
146
134
|
const buildCommandsObject = (name, command, object = {}) => {
|
|
147
135
|
const commandName = name || "dwc";
|
|
148
136
|
// eslint-disable-next-line no-param-reassign
|
|
149
137
|
object[commandName] = async (options) => {
|
|
150
|
-
await
|
|
138
|
+
await executeCommand(new Array(2)
|
|
151
139
|
.fill("dummy")
|
|
152
140
|
.concat(name.split(" ").concat(options
|
|
153
141
|
? Object.entries(options).reduce((prev, curr) => {
|
|
@@ -156,7 +144,7 @@ const buildCommandsObject = (name, command, object = {}) => {
|
|
|
156
144
|
}, [])
|
|
157
145
|
: []))
|
|
158
146
|
.join(" "));
|
|
159
|
-
return
|
|
147
|
+
return ResultHandlerFactory.get().getResult();
|
|
160
148
|
};
|
|
161
149
|
/* istanbul ignore next */
|
|
162
150
|
command.commands.forEach((c) => {
|
|
@@ -166,14 +154,13 @@ const buildCommandsObject = (name, command, object = {}) => {
|
|
|
166
154
|
};
|
|
167
155
|
const reinitialize = (host) => {
|
|
168
156
|
initialized = false;
|
|
169
|
-
(
|
|
170
|
-
(
|
|
171
|
-
|
|
172
|
-
(
|
|
157
|
+
initializeConfig();
|
|
158
|
+
setConfig({ tenant: host });
|
|
159
|
+
setCustomConfig();
|
|
160
|
+
clearDiscovery();
|
|
173
161
|
};
|
|
174
|
-
const getCommands = async (host) => {
|
|
162
|
+
export const getCommands = async (host) => {
|
|
175
163
|
reinitialize(host);
|
|
176
|
-
await
|
|
164
|
+
await init();
|
|
177
165
|
return buildCommandsObject("", program);
|
|
178
166
|
};
|
|
179
|
-
exports.getCommands = getCommands;
|
package/dwc/run.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const run = async () => {
|
|
10
|
-
const { error, debug, output } = (0, logger_1.get)("dwc.run");
|
|
1
|
+
import { SecretsStorageSingleton } from "../cache/secrets/SecretsStorageSingleton.js";
|
|
2
|
+
import { getDeprecationMessage, isDeprecated } from "../config/core.js";
|
|
3
|
+
import { get } from "../logger/index.js";
|
|
4
|
+
import { executeCommand, init } from "./dwc.js";
|
|
5
|
+
import { checkVersion, compareEtags, verifyNodeVersion } from "./utils.js";
|
|
6
|
+
export const run = async () => {
|
|
7
|
+
const { error, debug, output } = get("dwc.run");
|
|
11
8
|
let exitCode = 0;
|
|
12
9
|
try {
|
|
13
|
-
await
|
|
14
|
-
await
|
|
15
|
-
await
|
|
10
|
+
await init();
|
|
11
|
+
await checkVersion();
|
|
12
|
+
await executeCommand();
|
|
16
13
|
}
|
|
17
14
|
catch (err) {
|
|
18
15
|
if (err.code === "commander.helpDisplayed" ||
|
|
@@ -26,17 +23,16 @@ const run = async () => {
|
|
|
26
23
|
exitCode = err.exitCode ?? exitCode;
|
|
27
24
|
}
|
|
28
25
|
finally {
|
|
29
|
-
await
|
|
30
|
-
if (
|
|
31
|
-
const message =
|
|
26
|
+
await compareEtags();
|
|
27
|
+
if (isDeprecated()) {
|
|
28
|
+
const message = getDeprecationMessage() ??
|
|
32
29
|
"WARNING: This package has been deprecated. Please consult the README or CHANGELOG for more information.";
|
|
33
30
|
output(message);
|
|
34
31
|
}
|
|
35
|
-
await
|
|
36
|
-
|
|
32
|
+
await SecretsStorageSingleton.SINGLETON.synchronizeSecretsToStorage();
|
|
33
|
+
verifyNodeVersion();
|
|
37
34
|
if (exitCode > 0) {
|
|
38
35
|
process.exit(exitCode);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
|
-
exports.run = run;
|
package/dwc/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import { Option } from "../types";
|
|
2
|
+
import { Option } from "../types.js";
|
|
3
3
|
export declare const addCommandsFromFolder: (pathToFolder: string, program: Command) => Promise<void>;
|
|
4
4
|
export declare function verifyNodeVersion(): void;
|
|
5
5
|
export declare const checkVersion: () => Promise<void>;
|
package/dwc/utils.js
CHANGED
|
@@ -1,37 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
1
|
+
import { satisfies } from "compare-versions";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { getPackageName } from "../config/core.js";
|
|
5
|
+
import { checkVersion as check, compareEtags as compare, } from "../discovery/index.js";
|
|
6
|
+
import { get } from "../logger/index.js";
|
|
7
|
+
import { buildCommand, getShortFlagForLongName } from "../utils/commands.js";
|
|
8
|
+
import { getBin, getEngines } from "../utils/utils.js";
|
|
9
|
+
const getLogger = () => get("dwc.utils");
|
|
10
|
+
/**
|
|
11
|
+
* Helper to resolve index.js or index.ts in a command directory
|
|
12
|
+
*/
|
|
13
|
+
async function resolveCommandIndex(commandsFolderPath, file) {
|
|
14
|
+
const dirPath = path.join(commandsFolderPath, file);
|
|
15
|
+
if ((await fs.stat(dirPath)).isDirectory() === false)
|
|
16
|
+
return dirPath;
|
|
17
|
+
const jsIndex = path.join(dirPath, "index.js");
|
|
18
|
+
const tsIndex = path.join(dirPath, "index.ts");
|
|
19
|
+
if (await fs.pathExists(jsIndex)) {
|
|
20
|
+
return jsIndex;
|
|
21
|
+
}
|
|
22
|
+
if (await fs.pathExists(tsIndex)) {
|
|
23
|
+
return tsIndex;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`No index.js or index.ts found in directory: ${dirPath}`);
|
|
26
|
+
}
|
|
27
|
+
export const addCommandsFromFolder = async (pathToFolder, program) => {
|
|
18
28
|
const { error, debug } = getLogger();
|
|
19
|
-
for (const file of (await
|
|
29
|
+
for (const file of (await fs.readdir(pathToFolder, {
|
|
20
30
|
encoding: "utf-8",
|
|
21
31
|
withFileTypes: false,
|
|
22
32
|
})).filter((f) => f.includes(".command") && !f.endsWith(".d.ts"))) {
|
|
23
33
|
try {
|
|
24
|
-
|
|
25
|
-
const content =
|
|
34
|
+
const importPath = await resolveCommandIndex(pathToFolder, file);
|
|
35
|
+
const content = await import(importPath);
|
|
26
36
|
if (content.addCommands) {
|
|
27
37
|
debug("adding commands from file %s.addCommands", file);
|
|
28
|
-
// eslint-disable-next-line no-await-in-loop
|
|
29
38
|
await content.addCommands(program);
|
|
30
39
|
}
|
|
31
40
|
else {
|
|
32
41
|
debug("adding command from file %s.default", file);
|
|
33
|
-
|
|
34
|
-
await (0, commands_1.buildCommand)(program, content.default);
|
|
42
|
+
await buildCommand(program, content.default);
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
catch (err) {
|
|
@@ -39,42 +47,38 @@ const addCommandsFromFolder = async (pathToFolder, program) => {
|
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
};
|
|
42
|
-
|
|
43
|
-
function verifyNodeVersion() {
|
|
50
|
+
export function verifyNodeVersion() {
|
|
44
51
|
const { output } = getLogger();
|
|
45
|
-
const { node } =
|
|
52
|
+
const { node } = getEngines();
|
|
46
53
|
const version = process.version.replace("v", "").trim();
|
|
47
|
-
if (!
|
|
54
|
+
if (!satisfies(version, node)) {
|
|
48
55
|
output(`WARNING: the current node version ${version} does not satisfy the required node version ${node}.` +
|
|
49
56
|
` The CLI might not behave as expected. Please make sure to install a matching node version.`);
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
|
-
const checkVersion = async () => {
|
|
59
|
+
export const checkVersion = async () => {
|
|
53
60
|
const { output, error } = getLogger();
|
|
54
61
|
try {
|
|
55
|
-
const result = await (
|
|
62
|
+
const result = await check();
|
|
56
63
|
if (result.status === "OUTDATED") {
|
|
57
|
-
output(`Your local CLI installation is outdated. Run 'npm install ${
|
|
64
|
+
output(`Your local CLI installation is outdated. Run 'npm install ${getPackageName()}@latest [-g]' to update`);
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
catch (err) {
|
|
61
68
|
error(err.stack);
|
|
62
69
|
}
|
|
63
70
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!(await (0, discovery_1.compareEtags)())) {
|
|
71
|
+
export const compareEtags = async () => {
|
|
72
|
+
if (!(await compare())) {
|
|
67
73
|
const { output } = getLogger();
|
|
68
|
-
output(`Your local CLI cache is outdated. Run '${
|
|
74
|
+
output(`Your local CLI cache is outdated. Run '${getBin()} config cache init' to update`);
|
|
69
75
|
}
|
|
70
76
|
};
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const shortFlag = (0, commands_1.getShortFlagForLongName)(command, option);
|
|
77
|
+
export const getOptionValueFromArgv = (command, option) => {
|
|
78
|
+
const shortFlag = getShortFlagForLongName(command, option);
|
|
74
79
|
const index = process.argv.findIndex((a) => a === `-${shortFlag}` || a === `--${option.longName}`);
|
|
75
80
|
if (index > -1) {
|
|
76
81
|
return process.argv[index + 1];
|
|
77
82
|
}
|
|
78
83
|
throw new Error(`option ${option.longName} not found in argv`);
|
|
79
84
|
};
|
|
80
|
-
exports.getOptionValueFromArgv = getOptionValueFromArgv;
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AuthenticationMethod } from "./constants";
|
|
2
|
-
export { run } from "./dwc/run";
|
|
3
|
-
export { configure, getCommands } from "./module";
|
|
1
|
+
import { AuthenticationMethod } from "./constants.js";
|
|
2
|
+
export { run } from "./dwc/run.js";
|
|
3
|
+
export { configure, getCommands } from "./module.js";
|
|
4
4
|
export { AuthenticationMethod };
|
|
5
|
-
export { getVersion, getBin, getDescription, getName, getPackageName, } from "./utils/utils";
|
|
5
|
+
export { getVersion, getBin, getDescription, getName, getPackageName, } from "./utils/utils.js";
|
|
6
6
|
export declare const configureCoreModule: ({ name, packageName, discoveryPaths, description, sapHelpLink, authenticationMethods, version, genericOptionsHelp, deprecated, deprecationMessage, }: {
|
|
7
7
|
name: string;
|
|
8
8
|
packageName: string;
|
package/index.js
CHANGED
|
@@ -1,74 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.configureCoreModule = exports.getPackageName = exports.getName = exports.getDescription = exports.getBin = exports.getVersion = exports.AuthenticationMethod = exports.getCommands = exports.configure = exports.run = void 0;
|
|
38
|
-
const dotenv = __importStar(require("dotenv"));
|
|
39
|
-
const configureLoggers_1 = require("./configureLoggers");
|
|
1
|
+
import * as dotenv from "dotenv";
|
|
2
|
+
import { configureLoggers } from "./configureLoggers.js";
|
|
3
|
+
import { set } from "./config/index.js";
|
|
40
4
|
/* jscpd:ignore-start */
|
|
5
|
+
import { AuthenticationMethod, CLI_DEPRECATED, CLI_DEPRECATION_MESSAGE, CLI_DESCRIPTION, CLI_DISCOVERY_PATHS, CLI_GENERIC_OPTIONS_HELP, CLI_NAME, CLI_PACKAGE_NAME, CLI_SAP_HELP, CLI_SUPPORTED_AUTHENTICATION_METHODS, CLI_VERSION, } from "./constants.js";
|
|
6
|
+
/* jscpd:ignore-end */
|
|
7
|
+
export { run } from "./dwc/run.js";
|
|
8
|
+
export { configure, getCommands } from "./module.js";
|
|
9
|
+
export { AuthenticationMethod };
|
|
10
|
+
export { getVersion, getBin, getDescription, getName, getPackageName, } from "./utils/utils.js";
|
|
41
11
|
dotenv.config({
|
|
42
12
|
quiet: true, // default is false, but we want to avoid logging to the stdout
|
|
43
13
|
});
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
Object.defineProperty(exports, "getDescription", { enumerable: true, get: function () { return utils_1.getDescription; } });
|
|
58
|
-
Object.defineProperty(exports, "getName", { enumerable: true, get: function () { return utils_1.getName; } });
|
|
59
|
-
Object.defineProperty(exports, "getPackageName", { enumerable: true, get: function () { return utils_1.getPackageName; } });
|
|
60
|
-
const configureCoreModule = ({ name, packageName, discoveryPaths, description, sapHelpLink, authenticationMethods = [constants_1.AuthenticationMethod.oauth], version, genericOptionsHelp, deprecated = false, deprecationMessage, }) => {
|
|
61
|
-
(0, config_1.set)({
|
|
62
|
-
[constants_1.CLI_NAME]: name,
|
|
63
|
-
[constants_1.CLI_PACKAGE_NAME]: packageName,
|
|
64
|
-
[constants_1.CLI_DESCRIPTION]: description,
|
|
65
|
-
[constants_1.CLI_DISCOVERY_PATHS]: discoveryPaths,
|
|
66
|
-
[constants_1.CLI_SAP_HELP]: sapHelpLink,
|
|
67
|
-
[constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS]: authenticationMethods,
|
|
68
|
-
[constants_1.CLI_VERSION]: version,
|
|
69
|
-
[constants_1.CLI_DEPRECATED]: deprecated,
|
|
70
|
-
[constants_1.CLI_DEPRECATION_MESSAGE]: deprecationMessage,
|
|
71
|
-
[constants_1.CLI_GENERIC_OPTIONS_HELP]: genericOptionsHelp,
|
|
14
|
+
configureLoggers();
|
|
15
|
+
export const configureCoreModule = ({ name, packageName, discoveryPaths, description, sapHelpLink, authenticationMethods = [AuthenticationMethod.oauth], version, genericOptionsHelp, deprecated = false, deprecationMessage, }) => {
|
|
16
|
+
set({
|
|
17
|
+
[CLI_NAME]: name,
|
|
18
|
+
[CLI_PACKAGE_NAME]: packageName,
|
|
19
|
+
[CLI_DESCRIPTION]: description,
|
|
20
|
+
[CLI_DISCOVERY_PATHS]: discoveryPaths,
|
|
21
|
+
[CLI_SAP_HELP]: sapHelpLink,
|
|
22
|
+
[CLI_SUPPORTED_AUTHENTICATION_METHODS]: authenticationMethods,
|
|
23
|
+
[CLI_VERSION]: version,
|
|
24
|
+
[CLI_DEPRECATED]: deprecated,
|
|
25
|
+
[CLI_DEPRECATION_MESSAGE]: deprecationMessage,
|
|
26
|
+
[CLI_GENERIC_OPTIONS_HELP]: genericOptionsHelp,
|
|
72
27
|
});
|
|
73
28
|
};
|
|
74
|
-
exports.configureCoreModule = configureCoreModule;
|
package/logger/index.d.ts
CHANGED
package/logger/index.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.get = exports.configure = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
1
|
+
import { LogLevel } from "../types.js";
|
|
5
2
|
const LogLevel2Console = {
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
3
|
+
[LogLevel.INACTIVE]: "inactive",
|
|
4
|
+
[LogLevel.ERROR]: "error",
|
|
5
|
+
[LogLevel.WARN]: "warn",
|
|
6
|
+
[LogLevel.INFO]: "info",
|
|
7
|
+
[LogLevel.DEBUG]: "debug",
|
|
8
|
+
[LogLevel.TRACE]: "info",
|
|
12
9
|
};
|
|
13
|
-
let logLevel =
|
|
10
|
+
let logLevel = LogLevel.INACTIVE;
|
|
14
11
|
let loggers;
|
|
15
12
|
let customLogger;
|
|
16
|
-
const configure = ({ logLevel: newLogLevel, loggers: newLoggers, customLogger: newCustomLogger, }) => {
|
|
13
|
+
export const configure = ({ logLevel: newLogLevel, loggers: newLoggers, customLogger: newCustomLogger, }) => {
|
|
17
14
|
if (newLogLevel) {
|
|
18
15
|
logLevel = newLogLevel;
|
|
19
16
|
}
|
|
@@ -30,7 +27,6 @@ const configure = ({ logLevel: newLogLevel, loggers: newLoggers, customLogger: n
|
|
|
30
27
|
customLogger = newCustomLogger;
|
|
31
28
|
}
|
|
32
29
|
};
|
|
33
|
-
exports.configure = configure;
|
|
34
30
|
const logMessage = (namespace, level) => (...args) => {
|
|
35
31
|
if (level <= logLevel && (loggers ? loggers.test(namespace) : true)) {
|
|
36
32
|
// @ts-expect-error ts(7053)
|
|
@@ -41,23 +37,22 @@ const logMessage = (namespace, level) => (...args) => {
|
|
|
41
37
|
: // @ts-expect-error ts(7053)
|
|
42
38
|
// eslint-disable-next-line
|
|
43
39
|
console[LogLevel2Console[level]](...[
|
|
44
|
-
`[${namespace}:${level ===
|
|
40
|
+
`[${namespace}:${level === LogLevel.TRACE ? "trace" : LogLevel2Console[level]}:${new Date().toISOString()}] ${args[0]}`,
|
|
45
41
|
...args.slice(1),
|
|
46
42
|
]);
|
|
47
43
|
}
|
|
48
44
|
};
|
|
49
|
-
const get = (namespace) => {
|
|
45
|
+
export const get = (namespace) => {
|
|
50
46
|
return {
|
|
51
47
|
output: customLogger?.output
|
|
52
48
|
? customLogger.output
|
|
53
49
|
: // eslint-disable-next-line
|
|
54
50
|
(...args) => console.log(...args),
|
|
55
|
-
error: logMessage(namespace,
|
|
56
|
-
warn: logMessage(namespace,
|
|
57
|
-
info: logMessage(namespace,
|
|
58
|
-
log: logMessage(namespace,
|
|
59
|
-
debug: logMessage(namespace,
|
|
60
|
-
trace: logMessage(namespace,
|
|
51
|
+
error: logMessage(namespace, LogLevel.ERROR),
|
|
52
|
+
warn: logMessage(namespace, LogLevel.WARN),
|
|
53
|
+
info: logMessage(namespace, LogLevel.INFO),
|
|
54
|
+
log: logMessage(namespace, LogLevel.INFO),
|
|
55
|
+
debug: logMessage(namespace, LogLevel.DEBUG),
|
|
56
|
+
trace: logMessage(namespace, LogLevel.TRACE),
|
|
61
57
|
};
|
|
62
58
|
};
|
|
63
|
-
exports.get = get;
|
package/logger/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/logger/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Logger } from "./types";
|
|
1
|
+
import { Logger } from "./types.js";
|
|
2
2
|
export declare const logVerbose: (logger: Logger, ...args: Array<any>) => void;
|