|
1 | 1 | import { Command, EnumType, ValidationError } from '/deps.ts' |
2 | 2 | import { config } from '/lib/config.ts' |
| 3 | +import { getSubstitutions, render } from '/lib/template.ts' |
3 | 4 | import { cmd, GlobalOptions } from '/index.ts' |
4 | 5 | import { CliOptions, RunrealConfig } from '/lib/types.ts' |
5 | 6 | import { exec as execCmd, randomBuildkiteEmoji } from '/lib/utils.ts' |
6 | 7 |
|
7 | 8 | export type ExecOptions = typeof exec extends Command<any, any, infer Options, any, any> ? Options |
8 | 9 | : never |
9 | 10 |
|
10 | | -// Object containing the allowed substitutions |
11 | | -const getSubstitutions = (cfg: RunrealConfig): Record<string, string | undefined> => ({ |
12 | | - 'engine.path': cfg.engine.path, |
13 | | - 'project.path': cfg.project.path, |
14 | | - 'project.name': cfg.project.name, |
15 | | - 'build.id': cfg.build.id, |
16 | | - 'build.path': cfg.build.path, |
17 | | - 'build.branch': cfg.build.branchSafe, |
18 | | - 'build.commit': cfg.build.commitShort, |
19 | | - 'buildkite.buildNumber': cfg.buildkite.buildNumber, |
20 | | -}) |
21 | | - |
22 | | -// This helper function will take a command string with placeholders and a substitutions object |
23 | | -// It will replace all placeholders in the command with their corresponding values |
24 | | -// If the key is not found in substitutions, keep the original placeholder |
25 | | -function interpolateCommand(input: string[], substitutions: Record<string, string | undefined>) { |
26 | | - // This regular expression matches all occurrences of ${placeholder} |
27 | | - const placeholderRegex = /\$\{([^}]+)\}/g |
28 | | - return input.map((arg) => |
29 | | - arg.replace(placeholderRegex, (_, key: string) => { |
30 | | - return key in substitutions ? substitutions[key] || key : _ |
31 | | - }) |
32 | | - ) |
33 | | -} |
34 | | - |
35 | 11 | enum Mode { |
36 | 12 | Local = 'local', |
37 | 13 | Buildkite = 'buildkite', |
@@ -84,8 +60,8 @@ export const exec = new Command<GlobalOptions>() |
84 | 60 |
|
85 | 61 | const steps: { command: string; args: string[] }[] = [] |
86 | 62 | for await (const step of run.steps) { |
87 | | - const command = interpolateCommand([step.command], getSubstitutions(cfg))[0] |
88 | | - const args = interpolateCommand(step.args || [], getSubstitutions(cfg)) |
| 63 | + const command = render(step.command, getSubstitutions(cfg))[0] |
| 64 | + const args = render(step.args, getSubstitutions(cfg)) |
89 | 65 | steps.push({ command, args }) |
90 | 66 | } |
91 | 67 |
|
|
0 commit comments