-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathexecutor.ts
More file actions
57 lines (55 loc) · 1.63 KB
/
executor.ts
File metadata and controls
57 lines (55 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { type ExecutorContext, logger } from '@nx/devkit';
import { executeProcess } from '../../internal/execute-process.js';
import {
createCliCommandObject,
createCliCommandString,
} from '../internal/cli.js';
import { normalizeContext } from '../internal/context.js';
import type { AutorunCommandExecutorOptions } from './schema.js';
import { parseAutorunExecutorOptions } from './utils.js';
export type ExecutorOutput = {
success: boolean;
command?: string;
error?: Error;
};
export default async function runAutorunExecutor(
terminalAndExecutorOptions: AutorunCommandExecutorOptions,
context: ExecutorContext,
): Promise<ExecutorOutput> {
const normalizedContext = normalizeContext(context);
const cliArgumentObject = parseAutorunExecutorOptions(
terminalAndExecutorOptions,
normalizedContext,
);
const { dryRun, verbose, command, bin } = terminalAndExecutorOptions;
const commandString = createCliCommandString({
command,
args: cliArgumentObject,
bin,
});
if (verbose) {
logger.info(`Run CLI executor ${command ?? ''}`);
logger.info(`Command: ${commandString}`);
}
if (dryRun) {
logger.warn(`DryRun execution of: ${commandString}`);
} else {
try {
await executeProcess({
...createCliCommandObject({ command, args: cliArgumentObject, bin }),
...(context.cwd ? { cwd: context.cwd } : {}),
});
} catch (error) {
logger.error(error);
return {
success: false,
command: commandString,
error: error instanceof Error ? error : new Error(`${error}`),
};
}
}
return {
success: true,
command: commandString,
};
}