MCPcopy Index your code
hub / github.com/code-pushup/cli / runCliExecutor

Function runCliExecutor

packages/nx-plugin/src/executors/cli/executor.ts:14–81  ·  view source on GitHub ↗
(
  terminalAndExecutorOptions: CliCommandExecutorOptions,
  context: ExecutorContext,
)

Source from the content-addressed store, hash-verified

12
13/* eslint-disable-next-line max-lines-per-function */
14export default async function runCliExecutor(
15 terminalAndExecutorOptions: CliCommandExecutorOptions,
16 context: ExecutorContext,
17): Promise<ExecutorOutput> {
18 const { objectToCliArgs, formatCommandStatus, logger, stringifyError } =
19 await import('@code-pushup/utils');
20 const normalizedContext = normalizeContext(context);
21 const {
22 command: cliCommand,
23 verbose = false,
24 dryRun,
25 env: executorEnv,
26 bin,
27 projectPrefix, // Do not forward to CLI, it is handled plugin logic only
28 ...restArgs
29 } = parseCliExecutorOptions(terminalAndExecutorOptions, normalizedContext);
30 // this sets `CP_VERBOSE=true` on process.env
31 logger.setVerbose(verbose);
32
33 const command = bin ? `node` : 'npx';
34 const args = [
35 bin ?? '@code-pushup/cli',
36 ...(cliCommand ? [cliCommand] : []),
37 ...objectToCliArgs(restArgs),
38 ];
39 const loggedEnvVars = {
40 ...executorEnv,
41 ...(verbose && { CP_VERBOSE: 'true' }),
42 };
43 const commandString = formatCommandStatus([command, ...args].join(' '), {
44 cwd: context.cwd,
45 env: loggedEnvVars,
46 });
47
48 if (dryRun) {
49 logger.warn(`DryRun execution of: ${commandString}`);
50 } else {
51 try {
52 logger.debug(`Run CLI with env vars: ${JSON.stringify(loggedEnvVars)}`);
53 await executeProcess({
54 command,
55 args,
56 ...(context.cwd ? { cwd: context.cwd } : {}),
57 ...(executorEnv && Object.keys(executorEnv).length > 0
58 ? {
59 env: {
60 // if env is undefined, executeProcess extends process.env by default
61 ...process.env,
62 // we don't pass `CP_VERBOSE=true` as it is handled inside logger.setVerbose
63 ...executorEnv,
64 },
65 }
66 : {}),
67 });
68 } catch (error) {
69 logger.error(stringifyError(error));
70 return {
71 success: false,

Callers 2

Calls 10

normalizeContextFunction · 0.85
parseCliExecutorOptionsFunction · 0.85
objectToCliArgsFunction · 0.85
formatCommandStatusFunction · 0.85
setVerboseMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80
executeProcessFunction · 0.50
stringifyErrorFunction · 0.50
debugMethod · 0.45

Tested by

no test coverage detected