forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevfileCommandRunner.ts
More file actions
70 lines (55 loc) · 2.32 KB
/
Copy pathdevfileCommandRunner.ts
File metadata and controls
70 lines (55 loc) · 2.32 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
58
59
60
61
62
63
64
65
66
67
68
69
70
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { ComponentWorkspaceFolder } from '../odo/workspace';
import { Command } from '../odo/componentTypeDescription';
import { CommandResolver } from './commandResolver';
import { ExecCommandExecutor } from './execCommand';
export class DevfileCommandRunner {
public static async execute(
componentFolder: ComponentWorkspaceFolder,
commandId: string,
): Promise<void> {
const devfile = componentFolder.component.devfileData.devfile;
const command = CommandResolver.getCommand(devfile, commandId);
await this.executeCommand(componentFolder, command);
}
private static async executeCommand(
componentFolder: ComponentWorkspaceFolder,
command: Command,
): Promise<void> {
if (command.exec) {
await ExecCommandExecutor.execute(componentFolder, command.id, command.exec);
return;
}
if (command.composite) {
const devfile = componentFolder.component.devfileData.devfile;
const commandMap = CommandResolver.getAllCommandsMap(devfile);
const children = command.composite.commands.map((id) => {
const child = commandMap.get(id.toLowerCase());
if (!child) {
throw new Error(`Command '${id}' not found`);
}
return child;
});
const isParallel =
(
command.composite as {
parallel?: boolean;
}
).parallel === true;
if (isParallel) {
await Promise.all(
children.map((child) => this.executeCommand(componentFolder, child)),
);
} else {
for (const child of children) {
await this.executeCommand(componentFolder, child);
}
}
return;
}
throw new Error(`Unsupported command '${command.id}'`);
}
}