@expo/steps 0.0.8 → 0.0.10
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/dist_commonjs/BuildConfig.cjs +15 -11
- package/dist_commonjs/BuildConfig.d.ts +1 -2
- package/dist_commonjs/BuildConfig.js.map +1 -1
- package/dist_commonjs/BuildConfigParser.cjs +115 -79
- package/dist_commonjs/BuildConfigParser.d.ts +14 -5
- package/dist_commonjs/BuildConfigParser.js.map +1 -1
- package/dist_commonjs/BuildFunction.cjs +30 -13
- package/dist_commonjs/BuildFunction.d.ts +20 -15
- package/dist_commonjs/BuildFunction.js.map +1 -1
- package/dist_commonjs/BuildStep.cjs +83 -55
- package/dist_commonjs/BuildStep.d.ts +25 -11
- package/dist_commonjs/BuildStep.js.map +1 -1
- package/dist_commonjs/BuildStepContext.cjs +5 -2
- package/dist_commonjs/BuildStepContext.d.ts +4 -0
- package/dist_commonjs/BuildStepContext.js.map +1 -1
- package/dist_commonjs/BuildStepInput.cjs +19 -6
- package/dist_commonjs/BuildStepInput.d.ts +11 -4
- package/dist_commonjs/BuildStepInput.js.map +1 -1
- package/dist_commonjs/BuildStepOutput.cjs +19 -6
- package/dist_commonjs/BuildStepOutput.d.ts +10 -4
- package/dist_commonjs/BuildStepOutput.js.map +1 -1
- package/dist_commonjs/BuildTemporaryFiles.cjs +1 -59
- package/dist_commonjs/BuildTemporaryFiles.d.ts +0 -4
- package/dist_commonjs/BuildTemporaryFiles.js.map +1 -1
- package/dist_commonjs/BuildWorkflow.cjs +3 -16
- package/dist_commonjs/BuildWorkflow.d.ts +0 -3
- package/dist_commonjs/BuildWorkflow.js.map +1 -1
- package/dist_commonjs/BuildWorkflowValidator.cjs +18 -28
- package/dist_commonjs/BuildWorkflowValidator.js.map +1 -1
- package/dist_commonjs/cli/cli.cjs +0 -4
- package/dist_commonjs/cli/cli.js.map +1 -1
- package/dist_commonjs/errors.cjs +30 -0
- package/dist_commonjs/errors.d.ts +24 -0
- package/dist_commonjs/errors.js.map +1 -0
- package/dist_commonjs/index.cjs +33 -3
- package/dist_commonjs/index.d.ts +5 -1
- package/dist_commonjs/index.js.map +1 -1
- package/dist_commonjs/utils/expodash/duplicates.cjs +18 -0
- package/dist_commonjs/utils/expodash/duplicates.d.ts +1 -0
- package/dist_commonjs/utils/expodash/duplicates.js.map +1 -0
- package/dist_commonjs/utils/template.cjs +2 -2
- package/dist_commonjs/utils/template.js.map +1 -1
- package/dist_esm/BuildConfig.d.ts +1 -2
- package/dist_esm/BuildConfig.js +14 -10
- package/dist_esm/BuildConfig.js.map +1 -1
- package/dist_esm/BuildConfigParser.d.ts +14 -5
- package/dist_esm/BuildConfigParser.js +115 -79
- package/dist_esm/BuildConfigParser.js.map +1 -1
- package/dist_esm/BuildFunction.d.ts +20 -15
- package/dist_esm/BuildFunction.js +27 -13
- package/dist_esm/BuildFunction.js.map +1 -1
- package/dist_esm/BuildStep.d.ts +25 -11
- package/dist_esm/BuildStep.js +82 -54
- package/dist_esm/BuildStep.js.map +1 -1
- package/dist_esm/BuildStepContext.d.ts +4 -0
- package/dist_esm/BuildStepContext.js +4 -1
- package/dist_esm/BuildStepContext.js.map +1 -1
- package/dist_esm/BuildStepInput.d.ts +11 -4
- package/dist_esm/BuildStepInput.js +17 -5
- package/dist_esm/BuildStepInput.js.map +1 -1
- package/dist_esm/BuildStepOutput.d.ts +10 -4
- package/dist_esm/BuildStepOutput.js +17 -5
- package/dist_esm/BuildStepOutput.js.map +1 -1
- package/dist_esm/BuildTemporaryFiles.d.ts +0 -4
- package/dist_esm/BuildTemporaryFiles.js +0 -55
- package/dist_esm/BuildTemporaryFiles.js.map +1 -1
- package/dist_esm/BuildWorkflow.d.ts +0 -3
- package/dist_esm/BuildWorkflow.js +3 -16
- package/dist_esm/BuildWorkflow.js.map +1 -1
- package/dist_esm/BuildWorkflowValidator.js +17 -27
- package/dist_esm/BuildWorkflowValidator.js.map +1 -1
- package/dist_esm/cli/cli.js +0 -4
- package/dist_esm/cli/cli.js.map +1 -1
- package/dist_esm/errors.d.ts +24 -0
- package/dist_esm/errors.js +23 -0
- package/dist_esm/errors.js.map +1 -0
- package/dist_esm/index.d.ts +5 -1
- package/dist_esm/index.js +5 -1
- package/dist_esm/index.js.map +1 -1
- package/dist_esm/utils/expodash/duplicates.d.ts +1 -0
- package/dist_esm/utils/expodash/duplicates.js +14 -0
- package/dist_esm/utils/expodash/duplicates.js.map +1 -0
- package/dist_esm/utils/template.js +1 -1
- package/dist_esm/utils/template.js.map +1 -1
- package/package.json +2 -1
- package/bin/upload-artifact +0 -12
- package/dist_commonjs/BuildArtifacts.cjs +0 -9
- package/dist_commonjs/BuildArtifacts.d.ts +0 -5
- package/dist_commonjs/BuildArtifacts.js.map +0 -1
- package/dist_commonjs/bin/uploadArtifact.cjs +0 -30
- package/dist_commonjs/bin/uploadArtifact.d.ts +0 -1
- package/dist_commonjs/bin/uploadArtifact.js.map +0 -1
- package/dist_commonjs/errors/BuildConfigError.cjs +0 -8
- package/dist_commonjs/errors/BuildConfigError.d.ts +0 -3
- package/dist_commonjs/errors/BuildConfigError.js.map +0 -1
- package/dist_commonjs/errors/BuildInternalError.cjs +0 -7
- package/dist_commonjs/errors/BuildInternalError.d.ts +0 -2
- package/dist_commonjs/errors/BuildInternalError.js.map +0 -1
- package/dist_commonjs/errors/BuildStepRuntimeError.cjs +0 -8
- package/dist_commonjs/errors/BuildStepRuntimeError.d.ts +0 -3
- package/dist_commonjs/errors/BuildStepRuntimeError.js.map +0 -1
- package/dist_commonjs/errors/BuildWorkflowError.cjs +0 -13
- package/dist_commonjs/errors/BuildWorkflowError.d.ts +0 -10
- package/dist_commonjs/errors/BuildWorkflowError.js.map +0 -1
- package/dist_commonjs/errors/UserError.cjs +0 -14
- package/dist_commonjs/errors/UserError.d.ts +0 -9
- package/dist_commonjs/errors/UserError.js.map +0 -1
- package/dist_esm/BuildArtifacts.d.ts +0 -5
- package/dist_esm/BuildArtifacts.js +0 -6
- package/dist_esm/BuildArtifacts.js.map +0 -1
- package/dist_esm/bin/uploadArtifact.d.ts +0 -1
- package/dist_esm/bin/uploadArtifact.js +0 -25
- package/dist_esm/bin/uploadArtifact.js.map +0 -1
- package/dist_esm/errors/BuildConfigError.d.ts +0 -3
- package/dist_esm/errors/BuildConfigError.js +0 -4
- package/dist_esm/errors/BuildConfigError.js.map +0 -1
- package/dist_esm/errors/BuildInternalError.d.ts +0 -2
- package/dist_esm/errors/BuildInternalError.js +0 -3
- package/dist_esm/errors/BuildInternalError.js.map +0 -1
- package/dist_esm/errors/BuildStepRuntimeError.d.ts +0 -3
- package/dist_esm/errors/BuildStepRuntimeError.js +0 -4
- package/dist_esm/errors/BuildStepRuntimeError.js.map +0 -1
- package/dist_esm/errors/BuildWorkflowError.d.ts +0 -10
- package/dist_esm/errors/BuildWorkflowError.js +0 -9
- package/dist_esm/errors/BuildWorkflowError.js.map +0 -1
- package/dist_esm/errors/UserError.d.ts +0 -9
- package/dist_esm/errors/UserError.js +0 -10
- package/dist_esm/errors/UserError.js.map +0 -1
package/dist_esm/BuildStep.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
-
import { BuildStepInput } from './BuildStepInput.js';
|
|
3
|
-
import { BuildStepOutput } from './BuildStepOutput.js';
|
|
2
|
+
import { BuildStepInput, BuildStepInputById } from './BuildStepInput.js';
|
|
3
|
+
import { BuildStepOutput, BuildStepOutputById } from './BuildStepOutput.js';
|
|
4
4
|
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
5
5
|
export declare enum BuildStepStatus {
|
|
6
6
|
NEW = "new",
|
|
@@ -14,35 +14,49 @@ export declare enum BuildStepLogMarker {
|
|
|
14
14
|
START_STEP = "start-step",
|
|
15
15
|
END_STEP = "end-step"
|
|
16
16
|
}
|
|
17
|
+
export type BuildStepFunction = (ctx: BuildStepContext, { inputs, outputs, env, }: {
|
|
18
|
+
inputs: BuildStepInputById;
|
|
19
|
+
outputs: BuildStepOutputById;
|
|
20
|
+
env: BuildStepEnv;
|
|
21
|
+
}) => unknown;
|
|
17
22
|
export declare class BuildStep {
|
|
18
|
-
private readonly ctx;
|
|
19
23
|
readonly id: string;
|
|
20
24
|
readonly name?: string;
|
|
21
|
-
readonly displayName
|
|
25
|
+
readonly displayName: string;
|
|
22
26
|
readonly inputs?: BuildStepInput[];
|
|
23
27
|
readonly outputs?: BuildStepOutput[];
|
|
24
|
-
readonly command
|
|
25
|
-
readonly
|
|
28
|
+
readonly command?: string;
|
|
29
|
+
readonly fn?: BuildStepFunction;
|
|
26
30
|
readonly shell: string;
|
|
31
|
+
readonly ctx: BuildStepContext;
|
|
27
32
|
status: BuildStepStatus;
|
|
28
33
|
private readonly internalId;
|
|
29
|
-
private readonly
|
|
34
|
+
private readonly inputById;
|
|
30
35
|
private readonly outputById;
|
|
31
36
|
private executed;
|
|
32
|
-
|
|
37
|
+
static getNewId(userDefinedId?: string): string;
|
|
38
|
+
static getDisplayName({ id, name, command, }: {
|
|
33
39
|
id: string;
|
|
34
40
|
name?: string;
|
|
41
|
+
command?: string;
|
|
42
|
+
}): string;
|
|
43
|
+
constructor(ctx: BuildStepContext, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, }: {
|
|
44
|
+
id: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
displayName: string;
|
|
35
47
|
inputs?: BuildStepInput[];
|
|
36
48
|
outputs?: BuildStepOutput[];
|
|
37
|
-
command
|
|
38
|
-
|
|
49
|
+
command?: string;
|
|
50
|
+
fn?: BuildStepFunction;
|
|
51
|
+
workingDirectory?: string;
|
|
39
52
|
shell?: string;
|
|
40
53
|
});
|
|
41
54
|
executeAsync(env?: BuildStepEnv): Promise<void>;
|
|
42
55
|
hasOutputParameter(name: string): boolean;
|
|
43
56
|
getOutputValueByName(name: string): string | undefined;
|
|
57
|
+
private executeCommandAsync;
|
|
58
|
+
private exectuteFnAsync;
|
|
44
59
|
private interpolateInputsInCommand;
|
|
45
60
|
private collectAndValidateOutputsAsync;
|
|
46
61
|
private getScriptEnv;
|
|
47
|
-
private getStepDisplayName;
|
|
48
62
|
}
|
package/dist_esm/BuildStep.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
1
2
|
import fs from 'fs/promises';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
+
import { makeBuildStepInputByIdMap } from './BuildStepInput.js';
|
|
6
|
+
import { makeBuildStepOutputByIdMap, } from './BuildStepOutput.js';
|
|
4
7
|
import { BIN_PATH } from './utils/shell/bin.js';
|
|
5
8
|
import { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';
|
|
6
9
|
import { cleanUpStepTemporaryDirectoriesAsync, createTemporaryOutputsDirectoryAsync, saveScriptToTemporaryFileAsync, } from './BuildTemporaryFiles.js';
|
|
7
10
|
import { spawnAsync } from './utils/shell/spawn.js';
|
|
8
11
|
import { interpolateWithInputs } from './utils/template.js';
|
|
9
|
-
import { BuildStepRuntimeError } from './errors
|
|
12
|
+
import { BuildStepRuntimeError } from './errors.js';
|
|
10
13
|
export var BuildStepStatus;
|
|
11
14
|
(function (BuildStepStatus) {
|
|
12
15
|
BuildStepStatus["NEW"] = "new";
|
|
@@ -21,66 +24,78 @@ export var BuildStepLogMarker;
|
|
|
21
24
|
BuildStepLogMarker["START_STEP"] = "start-step";
|
|
22
25
|
BuildStepLogMarker["END_STEP"] = "end-step";
|
|
23
26
|
})(BuildStepLogMarker || (BuildStepLogMarker = {}));
|
|
27
|
+
// TODO: move to a place common with tests
|
|
28
|
+
const UUID_REGEX = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
|
24
29
|
export class BuildStep {
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
static getNewId(userDefinedId) {
|
|
31
|
+
return userDefinedId !== null && userDefinedId !== void 0 ? userDefinedId : uuidv4();
|
|
32
|
+
}
|
|
33
|
+
static getDisplayName({ id, name, command, }) {
|
|
34
|
+
if (name) {
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
if (!id.match(UUID_REGEX)) {
|
|
38
|
+
return id;
|
|
39
|
+
}
|
|
40
|
+
if (command) {
|
|
41
|
+
const splits = command.trim().split('\n');
|
|
42
|
+
for (const split of splits) {
|
|
43
|
+
const trimmed = split.trim();
|
|
44
|
+
if (trimmed && !trimmed.startsWith('#')) {
|
|
45
|
+
return trimmed;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return id;
|
|
50
|
+
}
|
|
51
|
+
constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, }) {
|
|
27
52
|
this.executed = false;
|
|
53
|
+
assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
|
|
54
|
+
assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
|
|
28
55
|
this.id = id;
|
|
29
56
|
this.name = name;
|
|
30
|
-
this.displayName =
|
|
57
|
+
this.displayName = displayName;
|
|
31
58
|
this.inputs = inputs;
|
|
32
59
|
this.outputs = outputs;
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
: outputs.reduce((acc, output) => {
|
|
37
|
-
acc[output.id] = output;
|
|
38
|
-
return acc;
|
|
39
|
-
}, {});
|
|
60
|
+
this.inputById = makeBuildStepInputByIdMap(inputs);
|
|
61
|
+
this.outputById = makeBuildStepOutputByIdMap(outputs);
|
|
62
|
+
this.fn = fn;
|
|
40
63
|
this.command = command;
|
|
41
|
-
this.workingDirectory = workingDirectory;
|
|
42
64
|
this.shell = shell !== null && shell !== void 0 ? shell : getDefaultShell();
|
|
43
65
|
this.status = BuildStepStatus.NEW;
|
|
44
66
|
this.internalId = uuidv4();
|
|
45
|
-
|
|
67
|
+
const logger = ctx.logger.child({
|
|
46
68
|
buildStepInternalId: this.internalId,
|
|
47
69
|
buildStepId: this.id,
|
|
48
70
|
buildStepDisplayName: this.displayName,
|
|
49
71
|
});
|
|
72
|
+
const workingDirectory = maybeWorkingDirectory !== undefined
|
|
73
|
+
? path.resolve(ctx.workingDirectory, maybeWorkingDirectory)
|
|
74
|
+
: ctx.workingDirectory;
|
|
75
|
+
this.ctx = ctx.child({ logger, workingDirectory });
|
|
50
76
|
ctx.registerStep(this);
|
|
51
77
|
}
|
|
52
78
|
async executeAsync(env = process.env) {
|
|
53
79
|
try {
|
|
54
|
-
this.logger.info({ marker: BuildStepLogMarker.START_STEP }, `Executing build step "${this.
|
|
80
|
+
this.ctx.logger.info({ marker: BuildStepLogMarker.START_STEP }, `Executing build step "${this.displayName}"`);
|
|
55
81
|
this.status = BuildStepStatus.IN_PROGRESS;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.logger.debug(`Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`);
|
|
64
|
-
await spawnAsync(shellCommand, args !== null && args !== void 0 ? args : [], {
|
|
65
|
-
cwd: this.workingDirectory,
|
|
66
|
-
logger: this.logger,
|
|
67
|
-
env: this.getScriptEnv(env, outputsDir),
|
|
68
|
-
});
|
|
69
|
-
this.logger.debug(`Script completed successfully`);
|
|
70
|
-
await this.collectAndValidateOutputsAsync(outputsDir);
|
|
71
|
-
this.logger.debug('Finished collecting output paramters');
|
|
72
|
-
this.logger.info({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, `Finished build step "${this.id}" successfully`);
|
|
82
|
+
if (this.command !== undefined) {
|
|
83
|
+
await this.executeCommandAsync(env);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await this.exectuteFnAsync(env);
|
|
87
|
+
}
|
|
88
|
+
this.ctx.logger.info({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, `Finished build step "${this.displayName}" successfully`);
|
|
73
89
|
this.status = BuildStepStatus.SUCCESS;
|
|
74
90
|
}
|
|
75
91
|
catch (err) {
|
|
76
|
-
this.logger.error({ err });
|
|
77
|
-
this.logger.error({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL }, `Build step "${this.
|
|
92
|
+
this.ctx.logger.error({ err });
|
|
93
|
+
this.ctx.logger.error({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL }, `Build step "${this.displayName}" failed`);
|
|
78
94
|
this.status = BuildStepStatus.FAIL;
|
|
79
95
|
throw err;
|
|
80
96
|
}
|
|
81
97
|
finally {
|
|
82
98
|
this.executed = true;
|
|
83
|
-
await cleanUpStepTemporaryDirectoriesAsync(this.ctx, this.id);
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
hasOutputParameter(name) {
|
|
@@ -88,13 +103,41 @@ export class BuildStep {
|
|
|
88
103
|
}
|
|
89
104
|
getOutputValueByName(name) {
|
|
90
105
|
if (!this.executed) {
|
|
91
|
-
throw new BuildStepRuntimeError(`Failed getting output "${name}" from step "${this.
|
|
106
|
+
throw new BuildStepRuntimeError(`Failed getting output "${name}" from step "${this.displayName}". The step has not been executed yet.`);
|
|
92
107
|
}
|
|
93
108
|
if (!this.hasOutputParameter(name)) {
|
|
94
|
-
throw new BuildStepRuntimeError(`Step "${this.
|
|
109
|
+
throw new BuildStepRuntimeError(`Step "${this.displayName}" does not have output "${name}".`);
|
|
95
110
|
}
|
|
96
111
|
return this.outputById[name].value;
|
|
97
112
|
}
|
|
113
|
+
async executeCommandAsync(env) {
|
|
114
|
+
assert(this.command, 'Command must be defined.');
|
|
115
|
+
try {
|
|
116
|
+
const command = this.interpolateInputsInCommand(this.command, this.inputs);
|
|
117
|
+
this.ctx.logger.debug(`Interpolated inputs in the command template`);
|
|
118
|
+
const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx, this.id);
|
|
119
|
+
this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);
|
|
120
|
+
const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx, this.id, command);
|
|
121
|
+
this.ctx.logger.debug(`Saved script to ${scriptPath}`);
|
|
122
|
+
const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);
|
|
123
|
+
this.ctx.logger.debug(`Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`);
|
|
124
|
+
await spawnAsync(shellCommand, args !== null && args !== void 0 ? args : [], {
|
|
125
|
+
cwd: this.ctx.workingDirectory,
|
|
126
|
+
logger: this.ctx.logger,
|
|
127
|
+
env: this.getScriptEnv(env, outputsDir),
|
|
128
|
+
});
|
|
129
|
+
this.ctx.logger.debug(`Script completed successfully`);
|
|
130
|
+
await this.collectAndValidateOutputsAsync(outputsDir);
|
|
131
|
+
this.ctx.logger.debug('Finished collecting output paramters');
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await cleanUpStepTemporaryDirectoriesAsync(this.ctx, this.id);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async exectuteFnAsync(env) {
|
|
138
|
+
assert(this.fn, 'Function (fn) must be defined');
|
|
139
|
+
await this.fn(this.ctx, { inputs: this.inputById, outputs: this.outputById, env });
|
|
140
|
+
}
|
|
98
141
|
interpolateInputsInCommand(command, inputs) {
|
|
99
142
|
if (!inputs) {
|
|
100
143
|
return command;
|
|
@@ -123,16 +166,16 @@ export class BuildStep {
|
|
|
123
166
|
}
|
|
124
167
|
if (nonDefinedOutputIds.length > 0) {
|
|
125
168
|
const idsString = nonDefinedOutputIds.map((i) => `"${i}"`).join(', ');
|
|
126
|
-
this.logger.warn(`Some outputs are not defined in step config: ${idsString}`);
|
|
169
|
+
this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);
|
|
127
170
|
}
|
|
128
171
|
const nonSetRequiredOutputIds = [];
|
|
129
172
|
for (const output of (_a = this.outputs) !== null && _a !== void 0 ? _a : []) {
|
|
130
173
|
try {
|
|
131
174
|
const value = output.value;
|
|
132
|
-
this.logger.debug(`Output parameter "${output.id}" is set to "${value}"`);
|
|
175
|
+
this.ctx.logger.debug(`Output parameter "${output.id}" is set to "${value}"`);
|
|
133
176
|
}
|
|
134
177
|
catch (err) {
|
|
135
|
-
this.logger.debug({ err }, `Getting value for output parameter "${output.id}" failed.`);
|
|
178
|
+
this.ctx.logger.debug({ err }, `Getting value for output parameter "${output.id}" failed.`);
|
|
136
179
|
nonSetRequiredOutputIds.push(output.id);
|
|
137
180
|
}
|
|
138
181
|
}
|
|
@@ -153,20 +196,5 @@ export class BuildStep {
|
|
|
153
196
|
PATH: newPath,
|
|
154
197
|
};
|
|
155
198
|
}
|
|
156
|
-
getStepDisplayName(name, command) {
|
|
157
|
-
if (name) {
|
|
158
|
-
return name;
|
|
159
|
-
}
|
|
160
|
-
if (command !== '') {
|
|
161
|
-
const splits = command.trim().split('\n');
|
|
162
|
-
for (const split of splits) {
|
|
163
|
-
const trimmed = split.trim();
|
|
164
|
-
if (trimmed && !trimmed.startsWith('#')) {
|
|
165
|
-
return trimmed;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return undefined;
|
|
170
|
-
}
|
|
171
199
|
}
|
|
172
200
|
//# sourceMappingURL=BuildStep.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStep.js","sourceRoot":"","sources":["../src/BuildStep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAKpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EACL,oCAA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AC,CAAC;YAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;gBAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC7B,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;oBACvC,OAAO,OAAO,CAAC;iBAChB;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import fs from 'fs/promises';\nimport path from 'path';\n\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepInput } from './BuildStepInput.js';\nimport { BuildStepOutput } from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors/BuildStepRuntimeError.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n CANCELED = 'canceled',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport class BuildStep {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName?: string;\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command: string;\n public readonly workingDirectory: string;\n public readonly shell: string;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly logger: bunyan;\n private readonly outputById: Record<string, BuildStepOutput>;\n private executed = false;\n\n constructor(\n private readonly ctx: BuildStepContext,\n {\n id,\n name,\n inputs,\n outputs,\n command,\n workingDirectory,\n shell,\n }: {\n id: string;\n name?: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command: string;\n workingDirectory: string;\n shell?: string;\n }\n ) {\n this.id = id;\n this.name = name;\n this.displayName = this.getStepDisplayName(name, command);\n this.inputs = inputs;\n this.outputs = outputs;\n this.outputById =\n outputs === undefined\n ? {}\n : outputs.reduce((acc, output) => {\n acc[output.id] = output;\n return acc;\n }, {} as Record<string, BuildStepOutput>);\n this.command = command;\n this.workingDirectory = workingDirectory;\n this.shell = shell ?? getDefaultShell();\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n this.logger = ctx.logger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(env: BuildStepEnv = process.env): Promise<void> {\n try {\n this.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.id}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n const command = this.interpolateInputsInCommand(this.command, this.inputs);\n this.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx, this.id);\n this.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx, this.id, command);\n this.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.workingDirectory,\n logger: this.logger,\n env: this.getScriptEnv(env, outputsDir),\n });\n this.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n this.logger.debug('Finished collecting output paramters');\n\n this.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.id}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.logger.error({ err });\n this.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.id}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx, this.id);\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.id}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.id}\" does not have output \"${name}\"`);\n }\n return this.outputById[name].value;\n }\n\n private interpolateInputsInCommand(command: string, inputs?: BuildStepInput[]): string {\n if (!inputs) {\n return command;\n }\n const vars = inputs.reduce((acc, input) => {\n acc[input.id] = input.value ?? '';\n return acc;\n }, {} as Record<string, string>);\n return interpolateWithInputs(command, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(\n `Some required output parameters have not been set: ${idsString}`,\n { metadata: { ids: nonSetRequiredOutputIds } }\n );\n }\n }\n\n private getScriptEnv(env: BuildStepEnv, outputsDir: string): Record<string, string> {\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_BUILD_ID: this.ctx.buildId,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n\n private getStepDisplayName(name: string | undefined, command: string): string | undefined {\n if (name) {\n return name;\n }\n if (command !== '') {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildStep.js","sourceRoot":"","sources":["../src/BuildStep.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,EAAsC,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,EAGL,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EACL,oCAAoC,EACpC,oCAAoC,EACpC,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC;AAClC,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CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACtE,OAAO;YACL,GAAG,GAAG;YACN,qBAAqB,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO;YACvC,wBAAwB,EAAE,UAAU;YACpC,8BAA8B,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB;YACzD,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n CANCELED = 'canceled',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport class BuildStep {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n private readonly outputById: BuildStepOutputById;\n private executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n }\n ) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.inputs = inputs;\n this.outputs = outputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = makeBuildStepOutputByIdMap(outputs);\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.logger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n const workingDirectory =\n maybeWorkingDirectory !== undefined\n ? path.resolve(ctx.workingDirectory, maybeWorkingDirectory)\n : ctx.workingDirectory;\n this.ctx = ctx.child({ logger, workingDirectory });\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(env: BuildStepEnv = process.env): Promise<void> {\n try {\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.displayName}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n if (this.command !== undefined) {\n await this.executeCommandAsync(env);\n } else {\n await this.exectuteFnAsync(env);\n }\n\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.displayName}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.ctx.logger.error({ err });\n this.ctx.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.displayName}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n private async executeCommandAsync(env: BuildStepEnv): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n try {\n const command = this.interpolateInputsInCommand(this.command, this.inputs);\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx, this.id, command);\n this.ctx.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.ctx.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv(env, outputsDir),\n });\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx, this.id);\n }\n }\n\n private async exectuteFnAsync(env: BuildStepEnv): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n await this.fn(this.ctx, { inputs: this.inputById, outputs: this.outputById, env });\n }\n\n private interpolateInputsInCommand(command: string, inputs?: BuildStepInput[]): string {\n if (!inputs) {\n return command;\n }\n const vars = inputs.reduce((acc, input) => {\n acc[input.id] = input.value ?? '';\n return acc;\n }, {} as Record<string, string>);\n return interpolateWithInputs(command, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.ctx.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.ctx.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(\n `Some required output parameters have not been set: ${idsString}`,\n { metadata: { ids: nonSetRequiredOutputIds } }\n );\n }\n }\n\n private getScriptEnv(env: BuildStepEnv, outputsDir: string): Record<string, string> {\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_BUILD_ID: this.ctx.buildId,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
|
|
@@ -10,4 +10,8 @@ export declare class BuildStepContext {
|
|
|
10
10
|
constructor(buildId: string, logger: bunyan, skipCleanup: boolean, workingDirectory?: string);
|
|
11
11
|
registerStep(step: BuildStep): void;
|
|
12
12
|
getStepOutputValue(path: string): string | undefined;
|
|
13
|
+
child({ logger, workingDirectory, }?: {
|
|
14
|
+
logger?: bunyan;
|
|
15
|
+
workingDirectory?: string;
|
|
16
|
+
}): BuildStepContext;
|
|
13
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os from 'os';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { parseOutputPath } from './utils/template.js';
|
|
4
|
-
import { BuildStepRuntimeError } from './errors
|
|
4
|
+
import { BuildStepRuntimeError } from './errors.js';
|
|
5
5
|
export class BuildStepContext {
|
|
6
6
|
constructor(buildId, logger, skipCleanup, workingDirectory) {
|
|
7
7
|
this.buildId = buildId;
|
|
@@ -21,5 +21,8 @@ export class BuildStepContext {
|
|
|
21
21
|
}
|
|
22
22
|
return this.stepById[stepId].getOutputValueByName(outputId);
|
|
23
23
|
}
|
|
24
|
+
child({ logger, workingDirectory, } = {}) {
|
|
25
|
+
return new BuildStepContext(this.buildId, logger !== null && logger !== void 0 ? logger : this.logger, this.skipCleanup, workingDirectory !== null && workingDirectory !== void 0 ? workingDirectory : this.workingDirectory);
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
//# sourceMappingURL=BuildStepContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,OAAO,gBAAgB;IAM3B,YACkB,OAAe,EACf,MAAc,EACd,WAAoB,EACpC,gBAAyB;QAHT,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAS;QAL9B,aAAQ,GAA8B,EAAE,CAAC;QAQ/C,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QACzE,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAC9F,CAAC;IAEM,YAAY,CAAC,IAAe;QACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAChC,CAAC;IAEM,kBAAkB,CAAC,IAAY;QACpC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC9B,MAAM,IAAI,qBAAqB,CAAC,SAAS,MAAM,mBAAmB,CAAC,CAAC;SACrE;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,EACX,MAAM,EACN,gBAAgB,MAId,EAAE;QACJ,OAAO,IAAI,gBAAgB,CACzB,IAAI,CAAC,OAAO,EACZ,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI,CAAC,MAAM,EACrB,IAAI,CAAC,WAAW,EAChB,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,IAAI,CAAC,gBAAgB,CAC1C,CAAC;IACJ,CAAC;CACF","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport { bunyan } from '@expo/logger';\n\nimport { BuildStep } from './BuildStep.js';\nimport { parseOutputPath } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\n\nexport class BuildStepContext {\n public readonly baseWorkingDirectory: string;\n public readonly workingDirectory: string;\n\n private stepById: Record<string, BuildStep> = {};\n\n constructor(\n public readonly buildId: string,\n public readonly logger: bunyan,\n public readonly skipCleanup: boolean,\n workingDirectory?: string\n ) {\n this.baseWorkingDirectory = path.join(os.tmpdir(), 'eas-build', buildId);\n this.workingDirectory = workingDirectory ?? path.join(this.baseWorkingDirectory, 'project');\n }\n\n public registerStep(step: BuildStep): void {\n this.stepById[step.id] = step;\n }\n\n public getStepOutputValue(path: string): string | undefined {\n const { stepId, outputId } = parseOutputPath(path);\n if (!(stepId in this.stepById)) {\n throw new BuildStepRuntimeError(`Step \"${stepId}\" does not exist.`);\n }\n return this.stepById[stepId].getOutputValueByName(outputId);\n }\n\n public child({\n logger,\n workingDirectory,\n }: {\n logger?: bunyan;\n workingDirectory?: string;\n } = {}): BuildStepContext {\n return new BuildStepContext(\n this.buildId,\n logger ?? this.logger,\n this.skipCleanup,\n workingDirectory ?? this.workingDirectory\n );\n }\n}\n"]}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
-
export type
|
|
2
|
+
export type BuildStepInputById = Record<string, BuildStepInput>;
|
|
3
|
+
export type BuildStepInputProvider = (ctx: BuildStepContext, stepId: string) => BuildStepInput;
|
|
3
4
|
export declare class BuildStepInput {
|
|
4
5
|
private readonly ctx;
|
|
5
6
|
readonly id: string;
|
|
6
|
-
readonly
|
|
7
|
+
readonly stepDisplayName: string;
|
|
7
8
|
readonly defaultValue?: string;
|
|
8
9
|
readonly required: boolean;
|
|
9
10
|
private _value?;
|
|
10
|
-
|
|
11
|
+
static createProvider(params: {
|
|
11
12
|
id: string;
|
|
12
|
-
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
}): BuildStepInputProvider;
|
|
16
|
+
constructor(ctx: BuildStepContext, { id, stepDisplayName, defaultValue, required, }: {
|
|
17
|
+
id: string;
|
|
18
|
+
stepDisplayName: string;
|
|
13
19
|
defaultValue?: string;
|
|
14
20
|
required?: boolean;
|
|
15
21
|
});
|
|
16
22
|
get value(): string | undefined;
|
|
17
23
|
set(value: string | undefined): BuildStepInput;
|
|
18
24
|
}
|
|
25
|
+
export declare function makeBuildStepInputByIdMap(inputs?: BuildStepInput[]): BuildStepInputById;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { BuildStepRuntimeError } from './errors
|
|
1
|
+
import { BuildStepRuntimeError } from './errors.js';
|
|
2
2
|
import { interpolateWithOutputs } from './utils/template.js';
|
|
3
3
|
export class BuildStepInput {
|
|
4
|
-
|
|
4
|
+
static createProvider(params) {
|
|
5
|
+
return (ctx, stepDisplayName) => new BuildStepInput(ctx, { ...params, stepDisplayName });
|
|
6
|
+
}
|
|
7
|
+
constructor(ctx, { id, stepDisplayName, defaultValue, required = true, }) {
|
|
5
8
|
this.ctx = ctx;
|
|
6
9
|
this.id = id;
|
|
7
|
-
this.
|
|
10
|
+
this.stepDisplayName = stepDisplayName;
|
|
8
11
|
this.defaultValue = defaultValue;
|
|
9
12
|
this.required = required;
|
|
10
13
|
}
|
|
@@ -12,7 +15,7 @@ export class BuildStepInput {
|
|
|
12
15
|
var _a;
|
|
13
16
|
const rawValue = (_a = this._value) !== null && _a !== void 0 ? _a : this.defaultValue;
|
|
14
17
|
if (this.required && rawValue === undefined) {
|
|
15
|
-
throw new BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.
|
|
18
|
+
throw new BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepDisplayName}" is required but it was not set.`);
|
|
16
19
|
}
|
|
17
20
|
if (rawValue === undefined) {
|
|
18
21
|
return rawValue;
|
|
@@ -23,10 +26,19 @@ export class BuildStepInput {
|
|
|
23
26
|
}
|
|
24
27
|
set(value) {
|
|
25
28
|
if (this.required && value === undefined) {
|
|
26
|
-
throw new BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.
|
|
29
|
+
throw new BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepDisplayName}" is required.`);
|
|
27
30
|
}
|
|
28
31
|
this._value = value;
|
|
29
32
|
return this;
|
|
30
33
|
}
|
|
31
34
|
}
|
|
35
|
+
export function makeBuildStepInputByIdMap(inputs) {
|
|
36
|
+
if (inputs === undefined) {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
return inputs.reduce((acc, input) => {
|
|
40
|
+
acc[input.id] = input;
|
|
41
|
+
return acc;
|
|
42
|
+
}, {});
|
|
43
|
+
}
|
|
32
44
|
//# sourceMappingURL=BuildStepInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStepInput.js","sourceRoot":"","sources":["../src/BuildStepInput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"BuildStepInput.js","sourceRoot":"","sources":["../src/BuildStepInput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAK7D,MAAM,OAAO,cAAc;IAQlB,MAAM,CAAC,cAAc,CAAC,MAI5B;QACC,OAAO,CAAC,GAAG,EAAE,eAAe,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;IAC3F,CAAC;IAED,YACmB,GAAqB,EACtC,EACE,EAAE,EACF,eAAe,EACf,YAAY,EACZ,QAAQ,GAAG,IAAI,GAMhB;QAXgB,QAAG,GAAH,GAAG,CAAkB;QAatC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,KAAK;;QACP,MAAM,QAAQ,GAAG,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC,YAAY,CAAC;QAClD,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC3C,MAAM,IAAI,qBAAqB,CAC7B,oBAAoB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,mCAAmC,CAClG,CAAC;SACH;QAED,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,OAAO,QAAQ,CAAC;SACjB;aAAM;YACL,OAAO,sBAAsB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,WAAC,OAAA,MAAA,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,mCAAI,EAAE,CAAA,EAAA,CAAC,CAAC;SAC5F;IACH,CAAC;IAED,GAAG,CAAC,KAAyB;QAC3B,IAAI,IAAI,CAAC,QAAQ,IAAI,KAAK,KAAK,SAAS,EAAE;YACxC,MAAM,IAAI,qBAAqB,CAC7B,oBAAoB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,gBAAgB,CAC/E,CAAC;SACH;QACD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,UAAU,yBAAyB,CAAC,MAAyB;IACjE,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO,EAAE,CAAC;KACX;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;QACtB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAwB,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { interpolateWithOutputs } from './utils/template.js';\n\nexport type BuildStepInputById = Record<string, BuildStepInput>;\nexport type BuildStepInputProvider = (ctx: BuildStepContext, stepId: string) => BuildStepInput;\n\nexport class BuildStepInput {\n public readonly id: string;\n public readonly stepDisplayName: string;\n public readonly defaultValue?: string;\n public readonly required: boolean;\n\n private _value?: string;\n\n public static createProvider(params: {\n id: string;\n defaultValue?: string;\n required?: boolean;\n }): BuildStepInputProvider {\n return (ctx, stepDisplayName) => new BuildStepInput(ctx, { ...params, stepDisplayName });\n }\n\n constructor(\n private readonly ctx: BuildStepContext,\n {\n id,\n stepDisplayName,\n defaultValue,\n required = true,\n }: {\n id: string;\n stepDisplayName: string;\n defaultValue?: string;\n required?: boolean;\n }\n ) {\n this.id = id;\n this.stepDisplayName = stepDisplayName;\n this.defaultValue = defaultValue;\n this.required = required;\n }\n\n get value(): string | undefined {\n const rawValue = this._value ?? this.defaultValue;\n if (this.required && rawValue === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required but it was not set.`\n );\n }\n\n if (rawValue === undefined) {\n return rawValue;\n } else {\n return interpolateWithOutputs(rawValue, (path) => this.ctx.getStepOutputValue(path) ?? '');\n }\n }\n\n set(value: string | undefined): BuildStepInput {\n if (this.required && value === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required.`\n );\n }\n this._value = value;\n return this;\n }\n}\n\nexport function makeBuildStepInputByIdMap(inputs?: BuildStepInput[]): BuildStepInputById {\n if (inputs === undefined) {\n return {};\n }\n return inputs.reduce((acc, input) => {\n acc[input.id] = input;\n return acc;\n }, {} as BuildStepInputById);\n}\n"]}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
-
export type
|
|
2
|
+
export type BuildStepOutputById = Record<string, BuildStepOutput>;
|
|
3
|
+
export type BuildStepOutputProvider = (ctx: BuildStepContext, stepDisplayName: string) => BuildStepOutput;
|
|
3
4
|
export declare class BuildStepOutput {
|
|
4
5
|
private readonly ctx;
|
|
5
6
|
readonly id: string;
|
|
6
|
-
readonly
|
|
7
|
+
readonly stepDisplayName: string;
|
|
7
8
|
readonly required: boolean;
|
|
8
9
|
private _value?;
|
|
9
|
-
|
|
10
|
+
static createProvider(params: {
|
|
10
11
|
id: string;
|
|
11
|
-
|
|
12
|
+
required?: boolean;
|
|
13
|
+
}): BuildStepOutputProvider;
|
|
14
|
+
constructor(ctx: BuildStepContext, { id, stepDisplayName, required, }: {
|
|
15
|
+
id: string;
|
|
16
|
+
stepDisplayName: string;
|
|
12
17
|
required?: boolean;
|
|
13
18
|
});
|
|
14
19
|
get value(): string | undefined;
|
|
15
20
|
set(value: string | undefined): BuildStepOutput;
|
|
16
21
|
}
|
|
22
|
+
export declare function makeBuildStepOutputByIdMap(outputs?: BuildStepOutput[]): BuildStepOutputById;
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
import { BuildStepRuntimeError } from './errors
|
|
1
|
+
import { BuildStepRuntimeError } from './errors.js';
|
|
2
2
|
export class BuildStepOutput {
|
|
3
|
+
static createProvider(params) {
|
|
4
|
+
return (ctx, stepDisplayName) => new BuildStepOutput(ctx, { ...params, stepDisplayName });
|
|
5
|
+
}
|
|
3
6
|
constructor(
|
|
4
7
|
// @ts-expect-error ctx is not used in this class but let's keep it here for consistency
|
|
5
|
-
ctx, { id,
|
|
8
|
+
ctx, { id, stepDisplayName, required = true, }) {
|
|
6
9
|
this.ctx = ctx;
|
|
7
10
|
this.id = id;
|
|
8
|
-
this.
|
|
11
|
+
this.stepDisplayName = stepDisplayName;
|
|
9
12
|
this.required = required;
|
|
10
13
|
}
|
|
11
14
|
get value() {
|
|
12
15
|
if (this.required && this._value === undefined) {
|
|
13
|
-
throw new BuildStepRuntimeError(`Output parameter "${this.id}" for step "${this.
|
|
16
|
+
throw new BuildStepRuntimeError(`Output parameter "${this.id}" for step "${this.stepDisplayName}" is required but it was not set.`);
|
|
14
17
|
}
|
|
15
18
|
return this._value;
|
|
16
19
|
}
|
|
17
20
|
set(value) {
|
|
18
21
|
if (this.required && value === undefined) {
|
|
19
|
-
throw new BuildStepRuntimeError(`Output parameter "${this.id}" for step "${this.
|
|
22
|
+
throw new BuildStepRuntimeError(`Output parameter "${this.id}" for step "${this.stepDisplayName}" is required.`);
|
|
20
23
|
}
|
|
21
24
|
this._value = value;
|
|
22
25
|
return this;
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
export function makeBuildStepOutputByIdMap(outputs) {
|
|
29
|
+
if (outputs === undefined) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
return outputs.reduce((acc, output) => {
|
|
33
|
+
acc[output.id] = output;
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
}
|
|
25
37
|
//# sourceMappingURL=BuildStepOutput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStepOutput.js","sourceRoot":"","sources":["../src/BuildStepOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"BuildStepOutput.js","sourceRoot":"","sources":["../src/BuildStepOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAQpD,MAAM,OAAO,eAAe;IAOnB,MAAM,CAAC,cAAc,CAAC,MAG5B;QACC,OAAO,CAAC,GAAG,EAAE,eAAe,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED;IACE,wFAAwF;IACvE,GAAqB,EACtC,EACE,EAAE,EACF,eAAe,EACf,QAAQ,GAAG,IAAI,GAC6C;QAL7C,QAAG,GAAH,GAAG,CAAkB;QAOtC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,KAAK;QACP,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;YAC9C,MAAM,IAAI,qBAAqB,CAC7B,qBAAqB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,mCAAmC,CACnG,CAAC;SACH;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,GAAG,CAAC,KAAyB;QAC3B,IAAI,IAAI,CAAC,QAAQ,IAAI,KAAK,KAAK,SAAS,EAAE;YACxC,MAAM,IAAI,qBAAqB,CAC7B,qBAAqB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,gBAAgB,CAChF,CAAC;SACH;QACD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,UAAU,0BAA0B,CAAC,OAA2B;IACpE,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,EAAE,CAAC;KACX;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACpC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;QACxB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAyB,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors.js';\n\nexport type BuildStepOutputById = Record<string, BuildStepOutput>;\nexport type BuildStepOutputProvider = (\n ctx: BuildStepContext,\n stepDisplayName: string\n) => BuildStepOutput;\n\nexport class BuildStepOutput {\n public readonly id: string;\n public readonly stepDisplayName: string;\n public readonly required: boolean;\n\n private _value?: string;\n\n public static createProvider(params: {\n id: string;\n required?: boolean;\n }): BuildStepOutputProvider {\n return (ctx, stepDisplayName) => new BuildStepOutput(ctx, { ...params, stepDisplayName });\n }\n\n constructor(\n // @ts-expect-error ctx is not used in this class but let's keep it here for consistency\n private readonly ctx: BuildStepContext,\n {\n id,\n stepDisplayName,\n required = true,\n }: { id: string; stepDisplayName: string; required?: boolean }\n ) {\n this.id = id;\n this.stepDisplayName = stepDisplayName;\n this.required = required;\n }\n\n get value(): string | undefined {\n if (this.required && this._value === undefined) {\n throw new BuildStepRuntimeError(\n `Output parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required but it was not set.`\n );\n }\n return this._value;\n }\n\n set(value: string | undefined): BuildStepOutput {\n if (this.required && value === undefined) {\n throw new BuildStepRuntimeError(\n `Output parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required.`\n );\n }\n this._value = value;\n return this;\n }\n}\n\nexport function makeBuildStepOutputByIdMap(outputs?: BuildStepOutput[]): BuildStepOutputById {\n if (outputs === undefined) {\n return {};\n }\n return outputs.reduce((acc, output) => {\n acc[output.id] = output;\n return acc;\n }, {} as BuildStepOutputById);\n}\n"]}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
-
import { BuildArtifactType } from './BuildArtifacts.js';
|
|
3
2
|
export declare function saveScriptToTemporaryFileAsync(ctx: BuildStepContext, stepId: string, scriptContents: string): Promise<string>;
|
|
4
|
-
export declare function saveArtifactToTemporaryDirectoryAsync(ctx: BuildStepContext, type: BuildArtifactType, artifactPath: string): Promise<string>;
|
|
5
3
|
export declare function createTemporaryOutputsDirectoryAsync(ctx: BuildStepContext, stepId: string): Promise<string>;
|
|
6
|
-
export declare function findArtifactsByTypeAsync(ctx: BuildStepContext, type: BuildArtifactType): Promise<string[]>;
|
|
7
4
|
export declare function cleanUpStepTemporaryDirectoriesAsync(ctx: BuildStepContext, stepId: string): Promise<void>;
|
|
8
|
-
export declare function cleanUpWorkflowTemporaryDirectoriesAsync(ctx: BuildStepContext): Promise<void>;
|