@expo/steps 0.0.7 → 0.0.9
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 +112 -0
- package/dist_commonjs/BuildConfig.d.ts +52 -0
- package/dist_commonjs/BuildConfig.js.map +1 -0
- package/dist_commonjs/BuildConfigParser.cjs +177 -0
- package/dist_commonjs/BuildConfigParser.d.ts +24 -0
- package/dist_commonjs/BuildConfigParser.js.map +1 -0
- package/dist_commonjs/BuildFunction.cjs +51 -0
- package/dist_commonjs/BuildFunction.d.ts +37 -0
- package/dist_commonjs/BuildFunction.js.map +1 -0
- package/dist_commonjs/BuildPlatform.cjs +9 -0
- package/dist_commonjs/BuildPlatform.d.ts +4 -0
- package/dist_commonjs/BuildPlatform.js.map +1 -0
- package/dist_commonjs/BuildStep.cjs +199 -0
- package/dist_commonjs/BuildStep.d.ts +56 -0
- package/dist_commonjs/BuildStep.js.map +1 -0
- package/dist_commonjs/BuildStepContext.cjs +35 -0
- package/dist_commonjs/BuildStepContext.d.ts +17 -0
- package/dist_commonjs/BuildStepContext.js.map +1 -0
- package/dist_commonjs/BuildStepEnv.cjs +3 -0
- package/dist_commonjs/BuildStepEnv.d.ts +1 -0
- package/dist_commonjs/BuildStepEnv.js.map +1 -0
- package/dist_commonjs/BuildStepInput.cjs +49 -0
- package/dist_commonjs/BuildStepInput.d.ts +25 -0
- package/dist_commonjs/BuildStepInput.js.map +1 -0
- package/dist_commonjs/BuildStepOutput.cjs +42 -0
- package/dist_commonjs/BuildStepOutput.d.ts +22 -0
- package/dist_commonjs/BuildStepOutput.js.map +1 -0
- package/dist_commonjs/BuildTemporaryFiles.cjs +42 -0
- package/dist_commonjs/BuildTemporaryFiles.d.ts +4 -0
- package/dist_commonjs/BuildTemporaryFiles.js.map +1 -0
- package/dist_commonjs/BuildWorkflow.cjs +19 -0
- package/dist_commonjs/BuildWorkflow.d.ts +14 -0
- package/dist_commonjs/BuildWorkflow.js.map +1 -0
- package/dist_commonjs/BuildWorkflowValidator.cjs +67 -0
- package/dist_commonjs/BuildWorkflowValidator.d.ts +8 -0
- package/dist_commonjs/BuildWorkflowValidator.js.map +1 -0
- package/dist_commonjs/cli/cli.cjs +33 -0
- package/dist_commonjs/cli/cli.d.ts +1 -0
- package/dist_commonjs/cli/cli.js.map +1 -0
- package/dist_commonjs/errors/BuildConfigError.cjs +8 -0
- package/dist_commonjs/errors/BuildConfigError.d.ts +3 -0
- package/dist_commonjs/errors/BuildConfigError.js.map +1 -0
- package/dist_commonjs/errors/BuildInternalError.cjs +7 -0
- package/dist_commonjs/errors/BuildInternalError.d.ts +2 -0
- package/dist_commonjs/errors/BuildInternalError.js.map +1 -0
- package/dist_commonjs/errors/BuildStepRuntimeError.cjs +8 -0
- package/dist_commonjs/errors/BuildStepRuntimeError.d.ts +3 -0
- package/dist_commonjs/errors/BuildStepRuntimeError.js.map +1 -0
- package/dist_commonjs/errors/BuildWorkflowError.cjs +13 -0
- package/dist_commonjs/errors/BuildWorkflowError.d.ts +10 -0
- package/dist_commonjs/errors/BuildWorkflowError.js.map +1 -0
- package/dist_commonjs/errors/UserError.cjs +14 -0
- package/dist_commonjs/errors/UserError.d.ts +9 -0
- package/dist_commonjs/errors/UserError.js.map +1 -0
- package/dist_commonjs/index.cjs +14 -0
- package/dist_commonjs/index.d.ts +5 -0
- package/dist_commonjs/index.js.map +1 -0
- 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/expodash/uniq.cjs +9 -0
- package/dist_commonjs/utils/expodash/uniq.d.ts +1 -0
- package/dist_commonjs/utils/expodash/uniq.js.map +1 -0
- package/dist_commonjs/utils/nullthrows.cjs +11 -0
- package/dist_commonjs/utils/nullthrows.d.ts +1 -0
- package/dist_commonjs/utils/nullthrows.js.map +1 -0
- package/dist_commonjs/utils/shell/bin.cjs +11 -0
- package/dist_commonjs/utils/shell/bin.d.ts +1 -0
- package/dist_commonjs/utils/shell/bin.js.map +1 -0
- package/dist_commonjs/utils/shell/command.cjs +36 -0
- package/dist_commonjs/utils/shell/command.d.ts +6 -0
- package/dist_commonjs/utils/shell/command.js.map +1 -0
- package/dist_commonjs/utils/shell/spawn.cjs +25 -0
- package/dist_commonjs/utils/shell/spawn.d.ts +9 -0
- package/dist_commonjs/utils/shell/spawn.js.map +1 -0
- package/dist_commonjs/utils/template.cjs +47 -0
- package/dist_commonjs/utils/template.d.ts +11 -0
- package/dist_commonjs/utils/template.js.map +1 -0
- package/dist_esm/BuildConfig.d.ts +52 -0
- package/dist_esm/BuildConfig.js +101 -0
- package/dist_esm/BuildConfig.js.map +1 -0
- package/dist_esm/BuildConfigParser.d.ts +24 -0
- package/dist_esm/BuildConfigParser.js +170 -0
- package/dist_esm/BuildConfigParser.js.map +1 -0
- package/dist_esm/BuildFunction.d.ts +37 -0
- package/dist_esm/BuildFunction.js +44 -0
- package/dist_esm/BuildFunction.js.map +1 -0
- package/dist_esm/BuildPlatform.d.ts +4 -0
- package/dist_esm/BuildPlatform.js +6 -0
- package/dist_esm/BuildPlatform.js.map +1 -0
- package/dist_esm/BuildStep.d.ts +56 -0
- package/dist_esm/BuildStep.js +192 -0
- package/dist_esm/BuildStep.js.map +1 -0
- package/dist_esm/BuildStepContext.d.ts +17 -0
- package/dist_esm/BuildStepContext.js +28 -0
- package/dist_esm/BuildStepContext.js.map +1 -0
- package/dist_esm/BuildStepEnv.d.ts +1 -0
- package/dist_esm/BuildStepEnv.js +2 -0
- package/dist_esm/BuildStepEnv.js.map +1 -0
- package/dist_esm/BuildStepInput.d.ts +25 -0
- package/dist_esm/BuildStepInput.js +44 -0
- package/dist_esm/BuildStepInput.js.map +1 -0
- package/dist_esm/BuildStepOutput.d.ts +22 -0
- package/dist_esm/BuildStepOutput.js +37 -0
- package/dist_esm/BuildStepOutput.js.map +1 -0
- package/dist_esm/BuildTemporaryFiles.d.ts +4 -0
- package/dist_esm/BuildTemporaryFiles.js +33 -0
- package/dist_esm/BuildTemporaryFiles.js.map +1 -0
- package/dist_esm/BuildWorkflow.d.ts +14 -0
- package/dist_esm/BuildWorkflow.js +15 -0
- package/dist_esm/BuildWorkflow.js.map +1 -0
- package/dist_esm/BuildWorkflowValidator.d.ts +8 -0
- package/dist_esm/BuildWorkflowValidator.js +63 -0
- package/dist_esm/BuildWorkflowValidator.js.map +1 -0
- package/dist_esm/cli/cli.d.ts +1 -0
- package/dist_esm/cli/cli.js +28 -0
- package/dist_esm/cli/cli.js.map +1 -0
- package/dist_esm/errors/BuildConfigError.d.ts +3 -0
- package/dist_esm/errors/BuildConfigError.js +4 -0
- package/dist_esm/errors/BuildConfigError.js.map +1 -0
- package/dist_esm/errors/BuildInternalError.d.ts +2 -0
- package/dist_esm/errors/BuildInternalError.js +3 -0
- package/dist_esm/errors/BuildInternalError.js.map +1 -0
- package/dist_esm/errors/BuildStepRuntimeError.d.ts +3 -0
- package/dist_esm/errors/BuildStepRuntimeError.js +4 -0
- package/dist_esm/errors/BuildStepRuntimeError.js.map +1 -0
- package/dist_esm/errors/BuildWorkflowError.d.ts +10 -0
- package/dist_esm/errors/BuildWorkflowError.js +9 -0
- package/dist_esm/errors/BuildWorkflowError.js.map +1 -0
- package/dist_esm/errors/UserError.d.ts +9 -0
- package/dist_esm/errors/UserError.js +10 -0
- package/dist_esm/errors/UserError.js.map +1 -0
- package/dist_esm/index.d.ts +5 -0
- package/dist_esm/index.js +6 -0
- package/dist_esm/index.js.map +1 -0
- 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/expodash/uniq.d.ts +1 -0
- package/dist_esm/utils/expodash/uniq.js +5 -0
- package/dist_esm/utils/expodash/uniq.js.map +1 -0
- package/dist_esm/utils/nullthrows.d.ts +1 -0
- package/dist_esm/utils/nullthrows.js +7 -0
- package/dist_esm/utils/nullthrows.js.map +1 -0
- package/dist_esm/utils/shell/bin.d.ts +1 -0
- package/dist_esm/utils/shell/bin.js +5 -0
- package/dist_esm/utils/shell/bin.js.map +1 -0
- package/dist_esm/utils/shell/command.d.ts +6 -0
- package/dist_esm/utils/shell/command.js +28 -0
- package/dist_esm/utils/shell/command.js.map +1 -0
- package/dist_esm/utils/shell/spawn.d.ts +9 -0
- package/dist_esm/utils/shell/spawn.js +18 -0
- package/dist_esm/utils/shell/spawn.js.map +1 -0
- package/dist_esm/utils/template.d.ts +11 -0
- package/dist_esm/utils/template.js +40 -0
- package/dist_esm/utils/template.js.map +1 -0
- package/package.json +3 -1
- package/bin/upload-artifact +0 -12
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BuildStep = exports.BuildStepLogMarker = exports.BuildStepStatus = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const BuildStepInput_js_1 = require("./BuildStepInput.cjs");
|
|
12
|
+
const BuildStepOutput_js_1 = require("./BuildStepOutput.cjs");
|
|
13
|
+
const bin_js_1 = require("./utils/shell/bin.cjs");
|
|
14
|
+
const command_js_1 = require("./utils/shell/command.cjs");
|
|
15
|
+
const BuildTemporaryFiles_js_1 = require("./BuildTemporaryFiles.cjs");
|
|
16
|
+
const spawn_js_1 = require("./utils/shell/spawn.cjs");
|
|
17
|
+
const template_js_1 = require("./utils/template.cjs");
|
|
18
|
+
const BuildStepRuntimeError_js_1 = require("./errors/BuildStepRuntimeError.cjs");
|
|
19
|
+
var BuildStepStatus;
|
|
20
|
+
(function (BuildStepStatus) {
|
|
21
|
+
BuildStepStatus["NEW"] = "new";
|
|
22
|
+
BuildStepStatus["IN_PROGRESS"] = "in-progress";
|
|
23
|
+
BuildStepStatus["CANCELED"] = "canceled";
|
|
24
|
+
BuildStepStatus["FAIL"] = "fail";
|
|
25
|
+
BuildStepStatus["WARNING"] = "warning";
|
|
26
|
+
BuildStepStatus["SUCCESS"] = "success";
|
|
27
|
+
})(BuildStepStatus = exports.BuildStepStatus || (exports.BuildStepStatus = {}));
|
|
28
|
+
var BuildStepLogMarker;
|
|
29
|
+
(function (BuildStepLogMarker) {
|
|
30
|
+
BuildStepLogMarker["START_STEP"] = "start-step";
|
|
31
|
+
BuildStepLogMarker["END_STEP"] = "end-step";
|
|
32
|
+
})(BuildStepLogMarker = exports.BuildStepLogMarker || (exports.BuildStepLogMarker = {}));
|
|
33
|
+
class BuildStep {
|
|
34
|
+
constructor(ctx, { id, name, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, }) {
|
|
35
|
+
this.executed = false;
|
|
36
|
+
(0, assert_1.default)(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
|
|
37
|
+
(0, assert_1.default)(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
|
|
38
|
+
this.id = id;
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.displayName = this.getStepDisplayName(name, command);
|
|
41
|
+
this.inputs = inputs;
|
|
42
|
+
this.outputs = outputs;
|
|
43
|
+
this.inputById = (0, BuildStepInput_js_1.makeBuildStepInputByIdMap)(inputs);
|
|
44
|
+
this.outputById = (0, BuildStepOutput_js_1.makeBuildStepOutputByIdMap)(outputs);
|
|
45
|
+
this.fn = fn;
|
|
46
|
+
this.command = command;
|
|
47
|
+
this.shell = shell !== null && shell !== void 0 ? shell : (0, command_js_1.getDefaultShell)();
|
|
48
|
+
this.status = BuildStepStatus.NEW;
|
|
49
|
+
this.internalId = (0, uuid_1.v4)();
|
|
50
|
+
const logger = ctx.logger.child({
|
|
51
|
+
buildStepInternalId: this.internalId,
|
|
52
|
+
buildStepId: this.id,
|
|
53
|
+
buildStepDisplayName: this.displayName,
|
|
54
|
+
});
|
|
55
|
+
const workingDirectory = maybeWorkingDirectory !== undefined
|
|
56
|
+
? path_1.default.resolve(ctx.workingDirectory, maybeWorkingDirectory)
|
|
57
|
+
: ctx.workingDirectory;
|
|
58
|
+
this.ctx = ctx.child({ logger, workingDirectory });
|
|
59
|
+
ctx.registerStep(this);
|
|
60
|
+
}
|
|
61
|
+
async executeAsync(env = process.env) {
|
|
62
|
+
try {
|
|
63
|
+
this.ctx.logger.info({ marker: BuildStepLogMarker.START_STEP }, `Executing build step "${this.id}"`);
|
|
64
|
+
this.status = BuildStepStatus.IN_PROGRESS;
|
|
65
|
+
if (this.command !== undefined) {
|
|
66
|
+
await this.executeCommandAsync(env);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await this.exectuteFnAsync(env);
|
|
70
|
+
}
|
|
71
|
+
this.ctx.logger.info({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, `Finished build step "${this.id}" successfully`);
|
|
72
|
+
this.status = BuildStepStatus.SUCCESS;
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
this.ctx.logger.error({ err });
|
|
76
|
+
this.ctx.logger.error({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL }, `Build step "${this.id}" failed`);
|
|
77
|
+
this.status = BuildStepStatus.FAIL;
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
this.executed = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
hasOutputParameter(name) {
|
|
85
|
+
return name in this.outputById;
|
|
86
|
+
}
|
|
87
|
+
getOutputValueByName(name) {
|
|
88
|
+
if (!this.executed) {
|
|
89
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Failed getting output "${name}" from step "${this.id}". The step has not been executed yet.`);
|
|
90
|
+
}
|
|
91
|
+
if (!this.hasOutputParameter(name)) {
|
|
92
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Step "${this.id}" does not have output "${name}"`);
|
|
93
|
+
}
|
|
94
|
+
return this.outputById[name].value;
|
|
95
|
+
}
|
|
96
|
+
async executeCommandAsync(env) {
|
|
97
|
+
(0, assert_1.default)(this.command, 'Command must be defined.');
|
|
98
|
+
try {
|
|
99
|
+
const command = this.interpolateInputsInCommand(this.command, this.inputs);
|
|
100
|
+
this.ctx.logger.debug(`Interpolated inputs in the command template`);
|
|
101
|
+
const outputsDir = await (0, BuildTemporaryFiles_js_1.createTemporaryOutputsDirectoryAsync)(this.ctx, this.id);
|
|
102
|
+
this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);
|
|
103
|
+
const scriptPath = await (0, BuildTemporaryFiles_js_1.saveScriptToTemporaryFileAsync)(this.ctx, this.id, command);
|
|
104
|
+
this.ctx.logger.debug(`Saved script to ${scriptPath}`);
|
|
105
|
+
const { command: shellCommand, args } = (0, command_js_1.getShellCommandAndArgs)(this.shell, scriptPath);
|
|
106
|
+
this.ctx.logger.debug(`Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`);
|
|
107
|
+
await (0, spawn_js_1.spawnAsync)(shellCommand, args !== null && args !== void 0 ? args : [], {
|
|
108
|
+
cwd: this.ctx.workingDirectory,
|
|
109
|
+
logger: this.ctx.logger,
|
|
110
|
+
env: this.getScriptEnv(env, outputsDir),
|
|
111
|
+
});
|
|
112
|
+
this.ctx.logger.debug(`Script completed successfully`);
|
|
113
|
+
await this.collectAndValidateOutputsAsync(outputsDir);
|
|
114
|
+
this.ctx.logger.debug('Finished collecting output paramters');
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
await (0, BuildTemporaryFiles_js_1.cleanUpStepTemporaryDirectoriesAsync)(this.ctx, this.id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async exectuteFnAsync(env) {
|
|
121
|
+
(0, assert_1.default)(this.fn, 'Function (fn) must be defined');
|
|
122
|
+
await this.fn(this.ctx, { inputs: this.inputById, outputs: this.outputById, env });
|
|
123
|
+
}
|
|
124
|
+
interpolateInputsInCommand(command, inputs) {
|
|
125
|
+
if (!inputs) {
|
|
126
|
+
return command;
|
|
127
|
+
}
|
|
128
|
+
const vars = inputs.reduce((acc, input) => {
|
|
129
|
+
var _a;
|
|
130
|
+
acc[input.id] = (_a = input.value) !== null && _a !== void 0 ? _a : '';
|
|
131
|
+
return acc;
|
|
132
|
+
}, {});
|
|
133
|
+
return (0, template_js_1.interpolateWithInputs)(command, vars);
|
|
134
|
+
}
|
|
135
|
+
async collectAndValidateOutputsAsync(outputsDir) {
|
|
136
|
+
var _a;
|
|
137
|
+
const files = await promises_1.default.readdir(outputsDir);
|
|
138
|
+
const nonDefinedOutputIds = [];
|
|
139
|
+
for (const outputId of files) {
|
|
140
|
+
if (!(outputId in this.outputById)) {
|
|
141
|
+
nonDefinedOutputIds.push(outputId);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const file = path_1.default.join(outputsDir, outputId);
|
|
145
|
+
const rawContents = await promises_1.default.readFile(file, 'utf-8');
|
|
146
|
+
const value = rawContents.trim();
|
|
147
|
+
this.outputById[outputId].set(value);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (nonDefinedOutputIds.length > 0) {
|
|
151
|
+
const idsString = nonDefinedOutputIds.map((i) => `"${i}"`).join(', ');
|
|
152
|
+
this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);
|
|
153
|
+
}
|
|
154
|
+
const nonSetRequiredOutputIds = [];
|
|
155
|
+
for (const output of (_a = this.outputs) !== null && _a !== void 0 ? _a : []) {
|
|
156
|
+
try {
|
|
157
|
+
const value = output.value;
|
|
158
|
+
this.ctx.logger.debug(`Output parameter "${output.id}" is set to "${value}"`);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
this.ctx.logger.debug({ err }, `Getting value for output parameter "${output.id}" failed.`);
|
|
162
|
+
nonSetRequiredOutputIds.push(output.id);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (nonSetRequiredOutputIds.length > 0) {
|
|
166
|
+
const idsString = nonSetRequiredOutputIds.map((i) => `"${i}"`).join(', ');
|
|
167
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Some required output parameters have not been set: ${idsString}`, { metadata: { ids: nonSetRequiredOutputIds } });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
getScriptEnv(env, outputsDir) {
|
|
171
|
+
var _a;
|
|
172
|
+
const currentPath = (_a = env.PATH) !== null && _a !== void 0 ? _a : process.env.PATH;
|
|
173
|
+
const newPath = currentPath ? `${bin_js_1.BIN_PATH}:${currentPath}` : bin_js_1.BIN_PATH;
|
|
174
|
+
return {
|
|
175
|
+
...env,
|
|
176
|
+
__EXPO_STEPS_BUILD_ID: this.ctx.buildId,
|
|
177
|
+
__EXPO_STEPS_OUTPUTS_DIR: outputsDir,
|
|
178
|
+
__EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,
|
|
179
|
+
PATH: newPath,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
getStepDisplayName(name, command) {
|
|
183
|
+
if (name) {
|
|
184
|
+
return name;
|
|
185
|
+
}
|
|
186
|
+
if (command) {
|
|
187
|
+
const splits = command.trim().split('\n');
|
|
188
|
+
for (const split of splits) {
|
|
189
|
+
const trimmed = split.trim();
|
|
190
|
+
if (trimmed && !trimmed.startsWith('#')) {
|
|
191
|
+
return trimmed;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.BuildStep = BuildStep;
|
|
199
|
+
//# sourceMappingURL=BuildStep.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
+
import { BuildStepInput, BuildStepInputById } from './BuildStepInput.js';
|
|
3
|
+
import { BuildStepOutput, BuildStepOutputById } from './BuildStepOutput.js';
|
|
4
|
+
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
5
|
+
export declare enum BuildStepStatus {
|
|
6
|
+
NEW = "new",
|
|
7
|
+
IN_PROGRESS = "in-progress",
|
|
8
|
+
CANCELED = "canceled",
|
|
9
|
+
FAIL = "fail",
|
|
10
|
+
WARNING = "warning",
|
|
11
|
+
SUCCESS = "success"
|
|
12
|
+
}
|
|
13
|
+
export declare enum BuildStepLogMarker {
|
|
14
|
+
START_STEP = "start-step",
|
|
15
|
+
END_STEP = "end-step"
|
|
16
|
+
}
|
|
17
|
+
export type BuildStepFunction = (ctx: BuildStepContext, { inputs, outputs, env, }: {
|
|
18
|
+
inputs: BuildStepInputById;
|
|
19
|
+
outputs: BuildStepOutputById;
|
|
20
|
+
env: BuildStepEnv;
|
|
21
|
+
}) => unknown;
|
|
22
|
+
export declare class BuildStep {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
readonly displayName?: string;
|
|
26
|
+
readonly inputs?: BuildStepInput[];
|
|
27
|
+
readonly outputs?: BuildStepOutput[];
|
|
28
|
+
readonly command?: string;
|
|
29
|
+
readonly fn?: BuildStepFunction;
|
|
30
|
+
readonly shell: string;
|
|
31
|
+
readonly ctx: BuildStepContext;
|
|
32
|
+
status: BuildStepStatus;
|
|
33
|
+
private readonly internalId;
|
|
34
|
+
private readonly inputById;
|
|
35
|
+
private readonly outputById;
|
|
36
|
+
private executed;
|
|
37
|
+
constructor(ctx: BuildStepContext, { id, name, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, }: {
|
|
38
|
+
id: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
inputs?: BuildStepInput[];
|
|
41
|
+
outputs?: BuildStepOutput[];
|
|
42
|
+
command?: string;
|
|
43
|
+
fn?: BuildStepFunction;
|
|
44
|
+
workingDirectory?: string;
|
|
45
|
+
shell?: string;
|
|
46
|
+
});
|
|
47
|
+
executeAsync(env?: BuildStepEnv): Promise<void>;
|
|
48
|
+
hasOutputParameter(name: string): boolean;
|
|
49
|
+
getOutputValueByName(name: string): string | undefined;
|
|
50
|
+
private executeCommandAsync;
|
|
51
|
+
private exectuteFnAsync;
|
|
52
|
+
private interpolateInputsInCommand;
|
|
53
|
+
private collectAndValidateOutputsAsync;
|
|
54
|
+
private getScriptEnv;
|
|
55
|
+
private getStepDisplayName;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildStep.js","sourceRoot":"","sources":["../src/BuildStep.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2DAA6B;AAC7B,gDAAwB;AAExB,+BAAoC;AAGpC,2DAAoG;AACpG,6DAI8B;AAC9B,iDAAgD;AAChD,yDAAmF;AACnF,qEAIkC;AAClC,qDAAoD;AACpD,qDAA4D;AAC5D,gFAA0E;AAG1E,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,8CAA2B,CAAA;IAC3B,wCAAqB,CAAA;IACrB,gCAAa,CAAA;IACb,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;AACrB,CAAC,EAPW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAO1B;AAED,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,2CAAqB,CAAA;AACvB,CAAC,EAHW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAG7B;AAWD,MAAa,SAAS;IAiBpB,YACE,GAAqB,EACrB,EACE,EAAE,EACF,IAAI,EACJ,MAAM,EACN,OAAO,EACP,OAAO,EACP,EAAE,EACF,gBAAgB,EAAE,qBAAqB,EACvC,KAAK,GAUN;QAtBK,aAAQ,GAAG,KAAK,CAAC;QA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C;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;IAEO,kBAAkB,CAAC,IAAwB,EAAE,OAAgB;QACnE,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,CAAC;SACb;QACD,IAAI,OAAO,EAAE;YACX,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,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;AAxOD,8BAwOC","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/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 type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\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 constructor(\n ctx: BuildStepContext,\n {\n id,\n name,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n }: {\n id: string;\n name?: 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 = this.getStepDisplayName(name, command);\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.id}\"`\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.id}\" 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.id}\" 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.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 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 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"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BuildStepContext = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const template_js_1 = require("./utils/template.cjs");
|
|
10
|
+
const BuildStepRuntimeError_js_1 = require("./errors/BuildStepRuntimeError.cjs");
|
|
11
|
+
class BuildStepContext {
|
|
12
|
+
constructor(buildId, logger, skipCleanup, workingDirectory) {
|
|
13
|
+
this.buildId = buildId;
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
this.skipCleanup = skipCleanup;
|
|
16
|
+
this.stepById = {};
|
|
17
|
+
this.baseWorkingDirectory = path_1.default.join(os_1.default.tmpdir(), 'eas-build', buildId);
|
|
18
|
+
this.workingDirectory = workingDirectory !== null && workingDirectory !== void 0 ? workingDirectory : path_1.default.join(this.baseWorkingDirectory, 'project');
|
|
19
|
+
}
|
|
20
|
+
registerStep(step) {
|
|
21
|
+
this.stepById[step.id] = step;
|
|
22
|
+
}
|
|
23
|
+
getStepOutputValue(path) {
|
|
24
|
+
const { stepId, outputId } = (0, template_js_1.parseOutputPath)(path);
|
|
25
|
+
if (!(stepId in this.stepById)) {
|
|
26
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Step "${stepId}" does not exist.`);
|
|
27
|
+
}
|
|
28
|
+
return this.stepById[stepId].getOutputValueByName(outputId);
|
|
29
|
+
}
|
|
30
|
+
child({ logger, workingDirectory, } = {}) {
|
|
31
|
+
return new BuildStepContext(this.buildId, logger !== null && logger !== void 0 ? logger : this.logger, this.skipCleanup, workingDirectory !== null && workingDirectory !== void 0 ? workingDirectory : this.workingDirectory);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.BuildStepContext = BuildStepContext;
|
|
35
|
+
//# sourceMappingURL=BuildStepContext.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { bunyan } from '@expo/logger';
|
|
2
|
+
import { BuildStep } from './BuildStep.js';
|
|
3
|
+
export declare class BuildStepContext {
|
|
4
|
+
readonly buildId: string;
|
|
5
|
+
readonly logger: bunyan;
|
|
6
|
+
readonly skipCleanup: boolean;
|
|
7
|
+
readonly baseWorkingDirectory: string;
|
|
8
|
+
readonly workingDirectory: string;
|
|
9
|
+
private stepById;
|
|
10
|
+
constructor(buildId: string, logger: bunyan, skipCleanup: boolean, workingDirectory?: string);
|
|
11
|
+
registerStep(step: BuildStep): void;
|
|
12
|
+
getStepOutputValue(path: string): string | undefined;
|
|
13
|
+
child({ logger, workingDirectory, }?: {
|
|
14
|
+
logger?: bunyan;
|
|
15
|
+
workingDirectory?: string;
|
|
16
|
+
}): BuildStepContext;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@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AAM,GAAI,IAAI,CAAC,MAAM,EACrB,IAAI,CAAC,WAAW,EAChB,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,IAAI,CAAC,gBAAgB,CAC1C,CAAC;IACJ,CAAC;CACF;AA1CD,4CA0CC","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/BuildStepRuntimeError.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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type BuildStepEnv = Record<string, string | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildStepEnv.js","sourceRoot":"","sources":["../src/BuildStepEnv.ts"],"names":[],"mappings":"","sourcesContent":["export type BuildStepEnv = Record<string, string | undefined>;\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBuildStepInputByIdMap = exports.BuildStepInput = void 0;
|
|
4
|
+
const BuildStepRuntimeError_js_1 = require("./errors/BuildStepRuntimeError.cjs");
|
|
5
|
+
const template_js_1 = require("./utils/template.cjs");
|
|
6
|
+
class BuildStepInput {
|
|
7
|
+
static createProvider(params) {
|
|
8
|
+
return (ctx, stepId) => new BuildStepInput(ctx, { ...params, stepId });
|
|
9
|
+
}
|
|
10
|
+
constructor(ctx, { id, stepId, defaultValue, required = true, }) {
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.stepId = stepId;
|
|
14
|
+
this.defaultValue = defaultValue;
|
|
15
|
+
this.required = required;
|
|
16
|
+
}
|
|
17
|
+
get value() {
|
|
18
|
+
var _a;
|
|
19
|
+
const rawValue = (_a = this._value) !== null && _a !== void 0 ? _a : this.defaultValue;
|
|
20
|
+
if (this.required && rawValue === undefined) {
|
|
21
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepId}" is required but it was not set.`);
|
|
22
|
+
}
|
|
23
|
+
if (rawValue === undefined) {
|
|
24
|
+
return rawValue;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return (0, template_js_1.interpolateWithOutputs)(rawValue, (path) => { var _a; return (_a = this.ctx.getStepOutputValue(path)) !== null && _a !== void 0 ? _a : ''; });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
set(value) {
|
|
31
|
+
if (this.required && value === undefined) {
|
|
32
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepId}" is required.`);
|
|
33
|
+
}
|
|
34
|
+
this._value = value;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.BuildStepInput = BuildStepInput;
|
|
39
|
+
function makeBuildStepInputByIdMap(inputs) {
|
|
40
|
+
if (inputs === undefined) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
return inputs.reduce((acc, input) => {
|
|
44
|
+
acc[input.id] = input;
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
}
|
|
48
|
+
exports.makeBuildStepInputByIdMap = makeBuildStepInputByIdMap;
|
|
49
|
+
//# sourceMappingURL=BuildStepInput.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
+
export type BuildStepInputById = Record<string, BuildStepInput>;
|
|
3
|
+
export type BuildStepInputProvider = (ctx: BuildStepContext, stepId: string) => BuildStepInput;
|
|
4
|
+
export declare class BuildStepInput {
|
|
5
|
+
private readonly ctx;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly stepId: string;
|
|
8
|
+
readonly defaultValue?: string;
|
|
9
|
+
readonly required: boolean;
|
|
10
|
+
private _value?;
|
|
11
|
+
static createProvider(params: {
|
|
12
|
+
id: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
}): BuildStepInputProvider;
|
|
16
|
+
constructor(ctx: BuildStepContext, { id, stepId, defaultValue, required, }: {
|
|
17
|
+
id: string;
|
|
18
|
+
stepId: string;
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
});
|
|
22
|
+
get value(): string | undefined;
|
|
23
|
+
set(value: string | undefined): BuildStepInput;
|
|
24
|
+
}
|
|
25
|
+
export declare function makeBuildStepInputByIdMap(inputs?: BuildStepInput[]): BuildStepInputById;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildStepInput.js","sourceRoot":"","sources":["../src/BuildStepInput.ts"],"names":[],"mappings":";;;AACA,gFAA0E;AAC1E,qDAA6D;AAK7D,MAAa,cAAc;IAQlB,MAAM,CAAC,cAAc,CAAC,MAI5B;QACC,OAAO,CAAC,GAAG,EAAE,M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AA5DD,wCA4DC;AAED,SAAgB,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;AARD,8DAQC","sourcesContent":["import { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors/BuildStepRuntimeError.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 stepId: 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, stepId) => new BuildStepInput(ctx, { ...params, stepId });\n }\n\n constructor(\n private readonly ctx: BuildStepContext,\n {\n id,\n stepId,\n defaultValue,\n required = true,\n }: {\n id: string;\n stepId: string;\n defaultValue?: string;\n required?: boolean;\n }\n ) {\n this.id = id;\n this.stepId = stepId;\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.stepId}\" 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.stepId}\" 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"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBuildStepOutputByIdMap = exports.BuildStepOutput = void 0;
|
|
4
|
+
const BuildStepRuntimeError_js_1 = require("./errors/BuildStepRuntimeError.cjs");
|
|
5
|
+
class BuildStepOutput {
|
|
6
|
+
static createProvider(params) {
|
|
7
|
+
return (ctx, stepId) => new BuildStepOutput(ctx, { ...params, stepId });
|
|
8
|
+
}
|
|
9
|
+
constructor(
|
|
10
|
+
// @ts-expect-error ctx is not used in this class but let's keep it here for consistency
|
|
11
|
+
ctx, { id, stepId, required = true }) {
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.stepId = stepId;
|
|
15
|
+
this.required = required;
|
|
16
|
+
}
|
|
17
|
+
get value() {
|
|
18
|
+
if (this.required && this._value === undefined) {
|
|
19
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Output parameter "${this.id}" for step "${this.stepId}" is required but it was not set.`);
|
|
20
|
+
}
|
|
21
|
+
return this._value;
|
|
22
|
+
}
|
|
23
|
+
set(value) {
|
|
24
|
+
if (this.required && value === undefined) {
|
|
25
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Output parameter "${this.id}" for step "${this.stepId}" is required.`);
|
|
26
|
+
}
|
|
27
|
+
this._value = value;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.BuildStepOutput = BuildStepOutput;
|
|
32
|
+
function makeBuildStepOutputByIdMap(outputs) {
|
|
33
|
+
if (outputs === undefined) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
return outputs.reduce((acc, output) => {
|
|
37
|
+
acc[output.id] = output;
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
}
|
|
41
|
+
exports.makeBuildStepOutputByIdMap = makeBuildStepOutputByIdMap;
|
|
42
|
+
//# sourceMappingURL=BuildStepOutput.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
+
export type BuildStepOutputById = Record<string, BuildStepOutput>;
|
|
3
|
+
export type BuildStepOutputProvider = (ctx: BuildStepContext, stepId: string) => BuildStepOutput;
|
|
4
|
+
export declare class BuildStepOutput {
|
|
5
|
+
private readonly ctx;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly stepId: string;
|
|
8
|
+
readonly required: boolean;
|
|
9
|
+
private _value?;
|
|
10
|
+
static createProvider(params: {
|
|
11
|
+
id: string;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
}): BuildStepOutputProvider;
|
|
14
|
+
constructor(ctx: BuildStepContext, { id, stepId, required }: {
|
|
15
|
+
id: string;
|
|
16
|
+
stepId: string;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
});
|
|
19
|
+
get value(): string | undefined;
|
|
20
|
+
set(value: string | undefined): BuildStepOutput;
|
|
21
|
+
}
|
|
22
|
+
export declare function makeBuildStepOutputByIdMap(outputs?: BuildStepOutput[]): BuildStepOutputById;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildStepOutput.js","sourceRoot":"","sources":["../src/BuildStepOutput.ts"],"names":[],"mappings":";;;AACA,gFAA0E;AAK1E,MAAa,eAAe;IAOnB,MAAM,CAAC,cAAc,CAAC,MAG5B;QACC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED;IACE,wFAAwF;IACvE,GAAqB,EACtC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,EAAsD;QADlE,QAAG,GAAH,GAAG,CAAkB;QAGtC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,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,gDAAqB,CAC7B,qBAAqB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,MAAM,mCAAmC,CAC1F,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,gDAAqB,CAC7B,qBAAqB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,MAAM,gBAAgB,CACvE,CAAC;SACH;QACD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA1CD,0CA0CC;AAED,SAAgB,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;AARD,gEAQC","sourcesContent":["import { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors/BuildStepRuntimeError.js';\n\nexport type BuildStepOutputById = Record<string, BuildStepOutput>;\nexport type BuildStepOutputProvider = (ctx: BuildStepContext, stepId: string) => BuildStepOutput;\n\nexport class BuildStepOutput {\n public readonly id: string;\n public readonly stepId: 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, stepId) => new BuildStepOutput(ctx, { ...params, stepId });\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 { id, stepId, required = true }: { id: string; stepId: string; required?: boolean }\n ) {\n this.id = id;\n this.stepId = stepId;\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.stepId}\" 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.stepId}\" 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"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cleanUpStepTemporaryDirectoriesAsync = exports.createTemporaryOutputsDirectoryAsync = exports.saveScriptToTemporaryFileAsync = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const uuid_1 = require("uuid");
|
|
10
|
+
async function saveScriptToTemporaryFileAsync(ctx, stepId, scriptContents) {
|
|
11
|
+
const scriptsDir = getTemporaryScriptsDirPath(ctx, stepId);
|
|
12
|
+
await promises_1.default.mkdir(scriptsDir, { recursive: true });
|
|
13
|
+
const temporaryScriptPath = path_1.default.join(scriptsDir, `${(0, uuid_1.v4)()}.sh`);
|
|
14
|
+
await promises_1.default.writeFile(temporaryScriptPath, scriptContents);
|
|
15
|
+
return temporaryScriptPath;
|
|
16
|
+
}
|
|
17
|
+
exports.saveScriptToTemporaryFileAsync = saveScriptToTemporaryFileAsync;
|
|
18
|
+
async function createTemporaryOutputsDirectoryAsync(ctx, stepId) {
|
|
19
|
+
const directory = getTemporaryOutputsDirPath(ctx, stepId);
|
|
20
|
+
await promises_1.default.mkdir(directory, { recursive: true });
|
|
21
|
+
return directory;
|
|
22
|
+
}
|
|
23
|
+
exports.createTemporaryOutputsDirectoryAsync = createTemporaryOutputsDirectoryAsync;
|
|
24
|
+
async function cleanUpStepTemporaryDirectoriesAsync(ctx, stepId) {
|
|
25
|
+
if (ctx.skipCleanup) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const stepTemporaryDirectory = getTemporaryStepDirPath(ctx, stepId);
|
|
29
|
+
await promises_1.default.rm(stepTemporaryDirectory, { recursive: true, force: true });
|
|
30
|
+
ctx.logger.debug({ stepTemporaryDirectory }, 'Removed step temporary directory');
|
|
31
|
+
}
|
|
32
|
+
exports.cleanUpStepTemporaryDirectoriesAsync = cleanUpStepTemporaryDirectoriesAsync;
|
|
33
|
+
function getTemporaryStepDirPath(ctx, stepId) {
|
|
34
|
+
return path_1.default.join(ctx.baseWorkingDirectory, 'steps', stepId);
|
|
35
|
+
}
|
|
36
|
+
function getTemporaryScriptsDirPath(ctx, stepId) {
|
|
37
|
+
return path_1.default.join(getTemporaryStepDirPath(ctx, stepId), 'scripts');
|
|
38
|
+
}
|
|
39
|
+
function getTemporaryOutputsDirPath(ctx, stepId) {
|
|
40
|
+
return path_1.default.join(getTemporaryStepDirPath(ctx, stepId), 'outputs');
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=BuildTemporaryFiles.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
|
+
export declare function saveScriptToTemporaryFileAsync(ctx: BuildStepContext, stepId: string, scriptContents: string): Promise<string>;
|
|
3
|
+
export declare function createTemporaryOutputsDirectoryAsync(ctx: BuildStepContext, stepId: string): Promise<string>;
|
|
4
|
+
export declare function cleanUpStepTemporaryDirectoriesAsync(ctx: BuildStepContext, stepId: string): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildTemporaryFiles.js","sourceRoot":"","sources":["../src/BuildTemporaryFiles.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,2DAA6B;AAE7B,+BAAoC;AAI7B,KAAK,UAAU,8BAA8B,CAClD,GAAqB,EACrB,MAAc,EACd,cAAsB;IAEtB,MAAM,UAAU,GAAG,0BAA0B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,kBAAE,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,mBAAmB,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,IAAA,SAAM,GAAE,KAAK,CAAC,CAAC;IACpE,MAAM,kBAAE,CAAC,SAAS,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACxD,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAVD,wEAUC;AAEM,KAAK,UAAU,oCAAoC,CACxD,GAAqB,EACrB,MAAc;IAEd,MAAM,SAAS,GAAG,0BAA0B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC1D,MAAM,kBAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC;AACnB,CAAC;AAPD,oFAOC;AAEM,KAAK,UAAU,oCAAoC,CACxD,GAAqB,EACrB,MAAc;IAEd,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,OAAO;KACR;IACD,MAAM,sBAAsB,GAAG,uBAAuB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpE,MAAM,kBAAE,CAAC,EAAE,CAAC,sBAAsB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,sBAAsB,EAAE,EAAE,kCAAkC,CAAC,CAAC;AACnF,CAAC;AAVD,oFAUC;AACD,SAAS,uBAAuB,CAAC,GAAqB,EAAE,MAAc;IACpE,OAAO,cAAI,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,0BAA0B,CAAC,GAAqB,EAAE,MAAc;IACvE,OAAO,cAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,0BAA0B,CAAC,GAAqB,EAAE,MAAc;IACvE,OAAO,cAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import path from 'path';\nimport fs from 'fs/promises';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext } from './BuildStepContext.js';\n\nexport async function saveScriptToTemporaryFileAsync(\n ctx: BuildStepContext,\n stepId: string,\n scriptContents: string\n): Promise<string> {\n const scriptsDir = getTemporaryScriptsDirPath(ctx, stepId);\n await fs.mkdir(scriptsDir, { recursive: true });\n const temporaryScriptPath = path.join(scriptsDir, `${uuidv4()}.sh`);\n await fs.writeFile(temporaryScriptPath, scriptContents);\n return temporaryScriptPath;\n}\n\nexport async function createTemporaryOutputsDirectoryAsync(\n ctx: BuildStepContext,\n stepId: string\n): Promise<string> {\n const directory = getTemporaryOutputsDirPath(ctx, stepId);\n await fs.mkdir(directory, { recursive: true });\n return directory;\n}\n\nexport async function cleanUpStepTemporaryDirectoriesAsync(\n ctx: BuildStepContext,\n stepId: string\n): Promise<void> {\n if (ctx.skipCleanup) {\n return;\n }\n const stepTemporaryDirectory = getTemporaryStepDirPath(ctx, stepId);\n await fs.rm(stepTemporaryDirectory, { recursive: true, force: true });\n ctx.logger.debug({ stepTemporaryDirectory }, 'Removed step temporary directory');\n}\nfunction getTemporaryStepDirPath(ctx: BuildStepContext, stepId: string): string {\n return path.join(ctx.baseWorkingDirectory, 'steps', stepId);\n}\n\nfunction getTemporaryScriptsDirPath(ctx: BuildStepContext, stepId: string): string {\n return path.join(getTemporaryStepDirPath(ctx, stepId), 'scripts');\n}\n\nfunction getTemporaryOutputsDirPath(ctx: BuildStepContext, stepId: string): string {\n return path.join(getTemporaryStepDirPath(ctx, stepId), 'outputs');\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuildWorkflow = void 0;
|
|
4
|
+
class BuildWorkflow {
|
|
5
|
+
constructor(
|
|
6
|
+
// @ts-expect-error ctx is not used in this class but let's keep it here for consistency
|
|
7
|
+
ctx, { buildSteps, buildFunctions }) {
|
|
8
|
+
this.ctx = ctx;
|
|
9
|
+
this.buildSteps = buildSteps;
|
|
10
|
+
this.buildFunctions = buildFunctions;
|
|
11
|
+
}
|
|
12
|
+
async executeAsync(env = process.env) {
|
|
13
|
+
for (const step of this.buildSteps) {
|
|
14
|
+
await step.executeAsync(env);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BuildWorkflow = BuildWorkflow;
|
|
19
|
+
//# sourceMappingURL=BuildWorkflow.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BuildFunctionById } from './BuildFunction.js';
|
|
2
|
+
import { BuildStep } from './BuildStep.js';
|
|
3
|
+
import { BuildStepContext } from './BuildStepContext.js';
|
|
4
|
+
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
5
|
+
export declare class BuildWorkflow {
|
|
6
|
+
private readonly ctx;
|
|
7
|
+
readonly buildSteps: BuildStep[];
|
|
8
|
+
readonly buildFunctions: BuildFunctionById;
|
|
9
|
+
constructor(ctx: BuildStepContext, { buildSteps, buildFunctions }: {
|
|
10
|
+
buildSteps: BuildStep[];
|
|
11
|
+
buildFunctions: BuildFunctionById;
|
|
12
|
+
});
|
|
13
|
+
executeAsync(env?: BuildStepEnv): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildWorkflow.js","sourceRoot":"","sources":["../src/BuildWorkflow.ts"],"names":[],"mappings":";;;AAKA,MAAa,aAAa;IAIxB;IACE,wFAAwF;IACvE,GAAqB,EACtC,EAAE,UAAU,EAAE,cAAc,EAAkE;QAD7E,QAAG,GAAH,GAAG,CAAkB;QAGtC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,MAAoB,OAAO,CAAC,GAAG;QACvD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YAClC,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;SAC9B;IACH,CAAC;CACF;AAlBD,sCAkBC","sourcesContent":["import { BuildFunctionById } from './BuildFunction.js';\nimport { BuildStep } from './BuildStep.js';\nimport { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\nexport class BuildWorkflow {\n public readonly buildSteps: BuildStep[];\n public readonly buildFunctions: BuildFunctionById;\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 { buildSteps, buildFunctions }: { buildSteps: BuildStep[]; buildFunctions: BuildFunctionById }\n ) {\n this.buildSteps = buildSteps;\n this.buildFunctions = buildFunctions;\n }\n\n public async executeAsync(env: BuildStepEnv = process.env): Promise<void> {\n for (const step of this.buildSteps) {\n await step.executeAsync(env);\n }\n }\n}\n"]}
|