@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,112 @@
|
|
|
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.validateBuildConfig = exports.isBuildStepBareFunctionCall = exports.isBuildStepFunctionCall = exports.isBuildStepBareCommandRun = exports.isBuildStepCommandRun = exports.BuildConfigSchema = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const joi_1 = __importDefault(require("joi"));
|
|
9
|
+
const BuildConfigError_js_1 = require("./errors/BuildConfigError.cjs");
|
|
10
|
+
const BuildPlatform_js_1 = require("./BuildPlatform.cjs");
|
|
11
|
+
const BuildInputOutputParametersSchema = joi_1.default.array().items(joi_1.default.alternatives().try(joi_1.default.string().required(), joi_1.default.object({
|
|
12
|
+
name: joi_1.default.string().required(),
|
|
13
|
+
required: joi_1.default.boolean(),
|
|
14
|
+
}).required()));
|
|
15
|
+
const BuildFunctionCallSchema = joi_1.default.object({
|
|
16
|
+
id: joi_1.default.string(),
|
|
17
|
+
inputs: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.string()),
|
|
18
|
+
name: joi_1.default.string(),
|
|
19
|
+
workingDirectory: joi_1.default.string(),
|
|
20
|
+
shell: joi_1.default.string(),
|
|
21
|
+
}).rename('working_directory', 'workingDirectory');
|
|
22
|
+
const BuildStepConfigSchema = joi_1.default.any()
|
|
23
|
+
.when(joi_1.default.object().pattern(joi_1.default.string().disallow('run').required(), joi_1.default.object().unknown().required()), {
|
|
24
|
+
then: joi_1.default.object().pattern(joi_1.default.string().disallow('run').min(1).required(), BuildFunctionCallSchema.required(), { matches: joi_1.default.array().length(1) }),
|
|
25
|
+
})
|
|
26
|
+
.when(joi_1.default.object({ run: joi_1.default.object().unknown().required() }), {
|
|
27
|
+
then: joi_1.default.object({
|
|
28
|
+
run: BuildFunctionCallSchema.keys({
|
|
29
|
+
outputs: BuildInputOutputParametersSchema,
|
|
30
|
+
command: joi_1.default.string().required(),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
})
|
|
34
|
+
.when(joi_1.default.object({ run: joi_1.default.string().required() }), {
|
|
35
|
+
then: joi_1.default.object({
|
|
36
|
+
run: joi_1.default.string().min(1).required(),
|
|
37
|
+
}),
|
|
38
|
+
})
|
|
39
|
+
.when(joi_1.default.string(), {
|
|
40
|
+
then: joi_1.default.string().min(1),
|
|
41
|
+
});
|
|
42
|
+
const BuildFunctionConfigSchema = joi_1.default.object({
|
|
43
|
+
name: joi_1.default.string(),
|
|
44
|
+
platforms: joi_1.default.string().allow(...Object.values(BuildPlatform_js_1.BuildPlatform)),
|
|
45
|
+
inputs: BuildInputOutputParametersSchema,
|
|
46
|
+
outputs: BuildInputOutputParametersSchema,
|
|
47
|
+
command: joi_1.default.string().required(),
|
|
48
|
+
shell: joi_1.default.string(),
|
|
49
|
+
});
|
|
50
|
+
exports.BuildConfigSchema = joi_1.default.object({
|
|
51
|
+
build: joi_1.default.object({
|
|
52
|
+
name: joi_1.default.string(),
|
|
53
|
+
steps: joi_1.default.array().items(BuildStepConfigSchema.required()).required(),
|
|
54
|
+
}).required(),
|
|
55
|
+
functions: joi_1.default.object().pattern(joi_1.default.string()
|
|
56
|
+
.pattern(/^[\w-]+$/, 'function names')
|
|
57
|
+
.min(1)
|
|
58
|
+
.required()
|
|
59
|
+
.disallow('run'), BuildFunctionConfigSchema.required()),
|
|
60
|
+
}).required();
|
|
61
|
+
function isBuildStepCommandRun(step) {
|
|
62
|
+
return typeof step === 'object' && typeof step.run === 'object';
|
|
63
|
+
}
|
|
64
|
+
exports.isBuildStepCommandRun = isBuildStepCommandRun;
|
|
65
|
+
function isBuildStepBareCommandRun(step) {
|
|
66
|
+
return typeof step === 'object' && typeof step.run === 'string';
|
|
67
|
+
}
|
|
68
|
+
exports.isBuildStepBareCommandRun = isBuildStepBareCommandRun;
|
|
69
|
+
function isBuildStepFunctionCall(step) {
|
|
70
|
+
return typeof step === 'object' && !('run' in step);
|
|
71
|
+
}
|
|
72
|
+
exports.isBuildStepFunctionCall = isBuildStepFunctionCall;
|
|
73
|
+
function isBuildStepBareFunctionCall(step) {
|
|
74
|
+
return typeof step === 'string';
|
|
75
|
+
}
|
|
76
|
+
exports.isBuildStepBareFunctionCall = isBuildStepBareFunctionCall;
|
|
77
|
+
function validateBuildConfig(rawConfig, externalFunctionIds) {
|
|
78
|
+
const { error, value: buildConfig } = exports.BuildConfigSchema.validate(rawConfig, {
|
|
79
|
+
allowUnknown: false,
|
|
80
|
+
abortEarly: false,
|
|
81
|
+
});
|
|
82
|
+
if (error) {
|
|
83
|
+
const errorMessage = error.details.map(({ message }) => message).join(', ');
|
|
84
|
+
throw new BuildConfigError_js_1.BuildConfigError(errorMessage, { cause: error });
|
|
85
|
+
}
|
|
86
|
+
validateAllFunctionsExist(buildConfig, externalFunctionIds);
|
|
87
|
+
return buildConfig;
|
|
88
|
+
}
|
|
89
|
+
exports.validateBuildConfig = validateBuildConfig;
|
|
90
|
+
function validateAllFunctionsExist(config, externalFunctionIds) {
|
|
91
|
+
const calledFunctionsSet = new Set();
|
|
92
|
+
for (const step of config.build.steps) {
|
|
93
|
+
if (typeof step === 'string') {
|
|
94
|
+
calledFunctionsSet.add(step);
|
|
95
|
+
}
|
|
96
|
+
else if (!('run' in step)) {
|
|
97
|
+
const keys = Object.keys(step);
|
|
98
|
+
(0, assert_1.default)(keys.length === 1, 'There must be at most one function call in the step (enforced by joi).');
|
|
99
|
+
calledFunctionsSet.add(keys[0]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const calledFunctions = Array.from(calledFunctionsSet);
|
|
103
|
+
const externalFunctionIdsSet = new Set(externalFunctionIds);
|
|
104
|
+
const nonExistentFunctions = calledFunctions.filter((calledFunction) => {
|
|
105
|
+
var _a;
|
|
106
|
+
return (!(calledFunction in ((_a = config.functions) !== null && _a !== void 0 ? _a : {})) && !externalFunctionIdsSet.has(calledFunction));
|
|
107
|
+
});
|
|
108
|
+
if (nonExistentFunctions.length > 0) {
|
|
109
|
+
throw new BuildConfigError_js_1.BuildConfigError(`Calling non-existent functions: ${nonExistentFunctions.map((f) => `"${f}"`).join(', ')}.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=BuildConfig.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
import { BuildPlatform } from './BuildPlatform.js';
|
|
3
|
+
export interface BuildConfig {
|
|
4
|
+
build: {
|
|
5
|
+
name?: string;
|
|
6
|
+
steps: BuildStepConfig[];
|
|
7
|
+
};
|
|
8
|
+
functions?: Record<string, BuildFunctionConfig>;
|
|
9
|
+
}
|
|
10
|
+
export type BuildStepConfig = BuildStepCommandRun | BuildStepBareCommandRun | BuildStepFunctionCall | BuildStepBareFunctionCall;
|
|
11
|
+
export type BuildStepCommandRun = {
|
|
12
|
+
run: BuildFunctionCallConfig & {
|
|
13
|
+
outputs?: BuildStepOutputs;
|
|
14
|
+
command: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type BuildStepBareCommandRun = {
|
|
18
|
+
run: string;
|
|
19
|
+
};
|
|
20
|
+
export type BuildStepFunctionCall = {
|
|
21
|
+
[functionId: string]: BuildFunctionCallConfig;
|
|
22
|
+
};
|
|
23
|
+
export type BuildStepBareFunctionCall = string;
|
|
24
|
+
export type BuildFunctionCallConfig = {
|
|
25
|
+
id?: string;
|
|
26
|
+
inputs?: BuildStepInputs;
|
|
27
|
+
name?: string;
|
|
28
|
+
workingDirectory?: string;
|
|
29
|
+
shell?: string;
|
|
30
|
+
};
|
|
31
|
+
export type BuildStepInputs = Record<string, string>;
|
|
32
|
+
export type BuildStepOutputs = BuildInputOutputParameters;
|
|
33
|
+
export interface BuildFunctionConfig {
|
|
34
|
+
inputs?: BuildFunctionInputs;
|
|
35
|
+
outputs?: BuildFunctionOutputs;
|
|
36
|
+
name?: string;
|
|
37
|
+
platforms?: BuildPlatform[];
|
|
38
|
+
shell?: string;
|
|
39
|
+
command: string;
|
|
40
|
+
}
|
|
41
|
+
export type BuildFunctionInputs = BuildInputOutputParameters;
|
|
42
|
+
export type BuildFunctionOutputs = BuildInputOutputParameters;
|
|
43
|
+
export type BuildInputOutputParameters = (string | {
|
|
44
|
+
name: string;
|
|
45
|
+
required?: boolean;
|
|
46
|
+
})[];
|
|
47
|
+
export declare const BuildConfigSchema: Joi.ObjectSchema<BuildConfig>;
|
|
48
|
+
export declare function isBuildStepCommandRun(step: BuildStepConfig): step is BuildStepCommandRun;
|
|
49
|
+
export declare function isBuildStepBareCommandRun(step: BuildStepConfig): step is BuildStepBareCommandRun;
|
|
50
|
+
export declare function isBuildStepFunctionCall(step: BuildStepConfig): step is BuildStepFunctionCall;
|
|
51
|
+
export declare function isBuildStepBareFunctionCall(step: BuildStepConfig): step is BuildStepBareFunctionCall;
|
|
52
|
+
export declare function validateBuildConfig(rawConfig: object, externalFunctionIds: string[]): BuildConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig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G,eAAe,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,EAAE;;QACrE,OAAO,CACL,CAAC,CAAC,cAAc,IAAI,CAAC,MAAA,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,cAAc,CAAC,CAC7F,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,MAAM,IAAI,sCAAgB,CACxB,mCAAmC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC3F,CAAC;KACH;AACH,CAAC","sourcesContent":["import assert from 'assert';\n\nimport Joi from 'joi';\n\nimport { BuildConfigError } from './errors/BuildConfigError.js';\nimport { BuildPlatform } from './BuildPlatform.js';\n\nexport interface BuildConfig {\n build: {\n name?: string;\n steps: BuildStepConfig[];\n };\n functions?: Record<string, BuildFunctionConfig>;\n}\n\nexport type BuildStepConfig =\n | BuildStepCommandRun\n | BuildStepBareCommandRun\n | BuildStepFunctionCall\n | BuildStepBareFunctionCall;\n\nexport type BuildStepCommandRun = {\n run: BuildFunctionCallConfig & {\n outputs?: BuildStepOutputs;\n command: string;\n };\n};\nexport type BuildStepBareCommandRun = { run: string };\nexport type BuildStepFunctionCall = {\n [functionId: string]: BuildFunctionCallConfig;\n};\nexport type BuildStepBareFunctionCall = string;\n\nexport type BuildFunctionCallConfig = {\n id?: string;\n inputs?: BuildStepInputs;\n name?: string;\n workingDirectory?: string;\n shell?: string;\n};\n\nexport type BuildStepInputs = Record<string, string>;\nexport type BuildStepOutputs = BuildInputOutputParameters;\n\nexport interface BuildFunctionConfig {\n inputs?: BuildFunctionInputs;\n outputs?: BuildFunctionOutputs;\n name?: string;\n platforms?: BuildPlatform[];\n shell?: string;\n command: string;\n}\n\nexport type BuildFunctionInputs = BuildInputOutputParameters;\nexport type BuildFunctionOutputs = BuildInputOutputParameters;\n\nexport type BuildInputOutputParameters = (\n | string\n | {\n name: string;\n required?: boolean;\n }\n)[];\n\nconst BuildInputOutputParametersSchema = Joi.array().items(\n Joi.alternatives().try(\n Joi.string().required(),\n Joi.object({\n name: Joi.string().required(),\n required: Joi.boolean(),\n }).required()\n )\n);\n\nconst BuildFunctionCallSchema = Joi.object({\n id: Joi.string(),\n inputs: Joi.object().pattern(Joi.string(), Joi.string()),\n name: Joi.string(),\n workingDirectory: Joi.string(),\n shell: Joi.string(),\n}).rename('working_directory', 'workingDirectory');\n\nconst BuildStepConfigSchema = Joi.any<BuildStepConfig>()\n .when(\n Joi.object().pattern(\n Joi.string().disallow('run').required(),\n Joi.object().unknown().required()\n ),\n {\n then: Joi.object().pattern(\n Joi.string().disallow('run').min(1).required(),\n BuildFunctionCallSchema.required(),\n { matches: Joi.array().length(1) }\n ),\n }\n )\n .when(Joi.object({ run: Joi.object().unknown().required() }), {\n then: Joi.object({\n run: BuildFunctionCallSchema.keys({\n outputs: BuildInputOutputParametersSchema,\n command: Joi.string().required(),\n }),\n }),\n })\n .when(Joi.object({ run: Joi.string().required() }), {\n then: Joi.object({\n run: Joi.string().min(1).required(),\n }),\n })\n .when(Joi.string(), {\n then: Joi.string().min(1),\n });\n\nconst BuildFunctionConfigSchema = Joi.object({\n name: Joi.string(),\n platforms: Joi.string().allow(...Object.values(BuildPlatform)),\n inputs: BuildInputOutputParametersSchema,\n outputs: BuildInputOutputParametersSchema,\n command: Joi.string().required(),\n shell: Joi.string(),\n});\n\nexport const BuildConfigSchema = Joi.object<BuildConfig>({\n build: Joi.object({\n name: Joi.string(),\n steps: Joi.array().items(BuildStepConfigSchema.required()).required(),\n }).required(),\n functions: Joi.object().pattern(\n Joi.string()\n .pattern(/^[\\w-]+$/, 'function names')\n .min(1)\n .required()\n .disallow('run'),\n BuildFunctionConfigSchema.required()\n ),\n}).required();\n\nexport function isBuildStepCommandRun(step: BuildStepConfig): step is BuildStepCommandRun {\n return typeof step === 'object' && typeof step.run === 'object';\n}\n\nexport function isBuildStepBareCommandRun(step: BuildStepConfig): step is BuildStepBareCommandRun {\n return typeof step === 'object' && typeof step.run === 'string';\n}\n\nexport function isBuildStepFunctionCall(step: BuildStepConfig): step is BuildStepFunctionCall {\n return typeof step === 'object' && !('run' in step);\n}\n\nexport function isBuildStepBareFunctionCall(\n step: BuildStepConfig\n): step is BuildStepBareFunctionCall {\n return typeof step === 'string';\n}\n\nexport function validateBuildConfig(rawConfig: object, externalFunctionIds: string[]): BuildConfig {\n const { error, value: buildConfig } = BuildConfigSchema.validate(rawConfig, {\n allowUnknown: false,\n abortEarly: false,\n });\n if (error) {\n const errorMessage = error.details.map(({ message }) => message).join(', ');\n throw new BuildConfigError(errorMessage, { cause: error });\n }\n validateAllFunctionsExist(buildConfig, externalFunctionIds);\n return buildConfig;\n}\n\nfunction validateAllFunctionsExist(config: BuildConfig, externalFunctionIds: string[]): void {\n const calledFunctionsSet = new Set<string>();\n for (const step of config.build.steps) {\n if (typeof step === 'string') {\n calledFunctionsSet.add(step);\n } else if (!('run' in step)) {\n const keys = Object.keys(step);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n calledFunctionsSet.add(keys[0]);\n }\n }\n const calledFunctions = Array.from(calledFunctionsSet);\n const externalFunctionIdsSet = new Set(externalFunctionIds);\n const nonExistentFunctions = calledFunctions.filter((calledFunction) => {\n return (\n !(calledFunction in (config.functions ?? {})) && !externalFunctionIdsSet.has(calledFunction)\n );\n });\n if (nonExistentFunctions.length > 0) {\n throw new BuildConfigError(\n `Calling non-existent functions: ${nonExistentFunctions.map((f) => `\"${f}\"`).join(', ')}.`\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,177 @@
|
|
|
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.BuildConfigParser = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const uuid_1 = require("uuid");
|
|
10
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
11
|
+
const BuildConfig_js_1 = require("./BuildConfig.cjs");
|
|
12
|
+
const BuildFunction_js_1 = require("./BuildFunction.cjs");
|
|
13
|
+
const BuildStep_js_1 = require("./BuildStep.cjs");
|
|
14
|
+
const BuildStepInput_js_1 = require("./BuildStepInput.cjs");
|
|
15
|
+
const BuildStepOutput_js_1 = require("./BuildStepOutput.cjs");
|
|
16
|
+
const BuildWorkflow_js_1 = require("./BuildWorkflow.cjs");
|
|
17
|
+
const BuildWorkflowValidator_js_1 = require("./BuildWorkflowValidator.cjs");
|
|
18
|
+
const BuildStepRuntimeError_js_1 = require("./errors/BuildStepRuntimeError.cjs");
|
|
19
|
+
const duplicates_js_1 = require("./utils/expodash/duplicates.cjs");
|
|
20
|
+
const uniq_js_1 = require("./utils/expodash/uniq.cjs");
|
|
21
|
+
class BuildConfigParser {
|
|
22
|
+
constructor(ctx, { configPath, externalFunctions }) {
|
|
23
|
+
this.ctx = ctx;
|
|
24
|
+
this.validateExternalFunctions(externalFunctions);
|
|
25
|
+
this.configPath = configPath;
|
|
26
|
+
this.externalFunctions = externalFunctions;
|
|
27
|
+
}
|
|
28
|
+
async parseAsync() {
|
|
29
|
+
const rawConfig = await this.readRawConfigAsync();
|
|
30
|
+
const config = (0, BuildConfig_js_1.validateBuildConfig)(rawConfig, this.getUniqueExternalFunctionIds());
|
|
31
|
+
const configBuildFunctions = this.createBuildFunctionsFromConfig(config.functions);
|
|
32
|
+
const buildFunctions = this.mergeBuildFunctionsWithExternal(configBuildFunctions, this.externalFunctions);
|
|
33
|
+
const buildSteps = config.build.steps.map((stepConfig) => this.createBuildStepFromConfig(stepConfig, buildFunctions));
|
|
34
|
+
const workflow = new BuildWorkflow_js_1.BuildWorkflow(this.ctx, { buildSteps, buildFunctions });
|
|
35
|
+
new BuildWorkflowValidator_js_1.BuildWorkflowValidator(workflow).validate();
|
|
36
|
+
return workflow;
|
|
37
|
+
}
|
|
38
|
+
async readRawConfigAsync() {
|
|
39
|
+
const contents = await promises_1.default.readFile(this.configPath, 'utf-8');
|
|
40
|
+
return yaml_1.default.parse(contents);
|
|
41
|
+
}
|
|
42
|
+
createBuildStepFromConfig(buildStepConfig, buildFunctions) {
|
|
43
|
+
if ((0, BuildConfig_js_1.isBuildStepCommandRun)(buildStepConfig)) {
|
|
44
|
+
const { id, inputs: inputsConfig, outputs: outputsConfig, name, workingDirectory, shell, command, } = buildStepConfig.run;
|
|
45
|
+
const stepId = id !== null && id !== void 0 ? id : (0, uuid_1.v4)();
|
|
46
|
+
const inputs = inputsConfig &&
|
|
47
|
+
this.createBuildStepInputsFromBuildStepInputsDefinition(inputsConfig, stepId);
|
|
48
|
+
const outputs = outputsConfig && this.createBuildStepOutputsFromDefinition(outputsConfig, stepId);
|
|
49
|
+
return new BuildStep_js_1.BuildStep(this.ctx, {
|
|
50
|
+
id: stepId,
|
|
51
|
+
inputs,
|
|
52
|
+
outputs,
|
|
53
|
+
name,
|
|
54
|
+
workingDirectory,
|
|
55
|
+
shell,
|
|
56
|
+
command,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if ((0, BuildConfig_js_1.isBuildStepBareCommandRun)(buildStepConfig)) {
|
|
60
|
+
const command = buildStepConfig.run;
|
|
61
|
+
return new BuildStep_js_1.BuildStep(this.ctx, {
|
|
62
|
+
id: (0, uuid_1.v4)(),
|
|
63
|
+
command,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else if ((0, BuildConfig_js_1.isBuildStepBareFunctionCall)(buildStepConfig)) {
|
|
67
|
+
const functionId = buildStepConfig;
|
|
68
|
+
const buildFunction = buildFunctions[functionId];
|
|
69
|
+
return buildFunction.createBuildStepFromFunctionCall(this.ctx);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const keys = Object.keys(buildStepConfig);
|
|
73
|
+
(0, assert_1.default)(keys.length === 1, 'There must be at most one function call in the step (enforced by joi).');
|
|
74
|
+
const functionId = keys[0];
|
|
75
|
+
const buildFunctionCallConfig = buildStepConfig[functionId];
|
|
76
|
+
const buildFunction = buildFunctions[functionId];
|
|
77
|
+
return buildFunction.createBuildStepFromFunctionCall(this.ctx, {
|
|
78
|
+
id: buildFunctionCallConfig.id,
|
|
79
|
+
name: buildFunctionCallConfig.name,
|
|
80
|
+
callInputs: buildFunctionCallConfig.inputs,
|
|
81
|
+
workingDirectory: buildFunctionCallConfig.workingDirectory,
|
|
82
|
+
shell: buildFunctionCallConfig.shell,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
createBuildFunctionsFromConfig(buildFunctionsConfig) {
|
|
87
|
+
if (!buildFunctionsConfig) {
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
const result = {};
|
|
91
|
+
for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {
|
|
92
|
+
const buildFunction = this.createBuildFunctionFromConfig({
|
|
93
|
+
id: functionId,
|
|
94
|
+
...buildFunctionConfig,
|
|
95
|
+
});
|
|
96
|
+
result[buildFunction.getFullId()] = buildFunction;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
createBuildFunctionFromConfig({ id, name, inputs: inputsConfig, outputs: outputsConfig, shell, command, }) {
|
|
101
|
+
const inputProviders = inputsConfig && this.createBuildStepInputProvidersFromBuildFunctionInputs(inputsConfig);
|
|
102
|
+
const outputProviders = outputsConfig && this.createBuildStepOutputProvidersFromBuildFunctionOutputs(outputsConfig);
|
|
103
|
+
return new BuildFunction_js_1.BuildFunction({ id, name, inputProviders, outputProviders, shell, command });
|
|
104
|
+
}
|
|
105
|
+
createBuildStepInputsFromBuildStepInputsDefinition(buildStepInputs, stepId) {
|
|
106
|
+
return Object.entries(buildStepInputs).map(([key, value]) => new BuildStepInput_js_1.BuildStepInput(this.ctx, {
|
|
107
|
+
id: key,
|
|
108
|
+
stepId,
|
|
109
|
+
defaultValue: value,
|
|
110
|
+
required: true,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
createBuildStepInputProvidersFromBuildFunctionInputs(buildFunctionInputs) {
|
|
114
|
+
return buildFunctionInputs.map((entry) => {
|
|
115
|
+
var _a;
|
|
116
|
+
return typeof entry === 'string'
|
|
117
|
+
? BuildStepInput_js_1.BuildStepInput.createProvider({ id: entry })
|
|
118
|
+
: BuildStepInput_js_1.BuildStepInput.createProvider({ id: entry.name, required: (_a = entry.required) !== null && _a !== void 0 ? _a : true });
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
createBuildStepOutputsFromDefinition(buildStepOutputs, stepId) {
|
|
122
|
+
return buildStepOutputs.map((entry) => {
|
|
123
|
+
var _a;
|
|
124
|
+
return typeof entry === 'string'
|
|
125
|
+
? new BuildStepOutput_js_1.BuildStepOutput(this.ctx, { id: entry, stepId, required: true })
|
|
126
|
+
: new BuildStepOutput_js_1.BuildStepOutput(this.ctx, {
|
|
127
|
+
id: entry.name,
|
|
128
|
+
stepId,
|
|
129
|
+
required: (_a = entry.required) !== null && _a !== void 0 ? _a : true,
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
createBuildStepOutputProvidersFromBuildFunctionOutputs(buildFunctionOutputs) {
|
|
134
|
+
return buildFunctionOutputs.map((entry) => {
|
|
135
|
+
var _a;
|
|
136
|
+
return typeof entry === 'string'
|
|
137
|
+
? BuildStepOutput_js_1.BuildStepOutput.createProvider({ id: entry, required: true })
|
|
138
|
+
: BuildStepOutput_js_1.BuildStepOutput.createProvider({ id: entry.name, required: (_a = entry.required) !== null && _a !== void 0 ? _a : true });
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
mergeBuildFunctionsWithExternal(configFunctions, externalFunctions) {
|
|
142
|
+
const result = { ...configFunctions };
|
|
143
|
+
if (externalFunctions === undefined) {
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
for (const buildFunction of externalFunctions) {
|
|
147
|
+
// functions defined in config shadow the external ones
|
|
148
|
+
const fullId = buildFunction.getFullId();
|
|
149
|
+
if (!(fullId in result)) {
|
|
150
|
+
result[fullId] = buildFunction;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
validateExternalFunctions(externalFunctions) {
|
|
156
|
+
if (externalFunctions === undefined) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const externalFunctionIds = externalFunctions.map((f) => f.getFullId());
|
|
160
|
+
const duplicatedExternalFunctionIds = (0, duplicates_js_1.duplicates)(externalFunctionIds);
|
|
161
|
+
if (duplicatedExternalFunctionIds.length === 0) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
throw new BuildStepRuntimeError_js_1.BuildStepRuntimeError(`Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds
|
|
165
|
+
.map((id) => `"${id}"`)
|
|
166
|
+
.join(', ')}`);
|
|
167
|
+
}
|
|
168
|
+
getUniqueExternalFunctionIds() {
|
|
169
|
+
if (this.externalFunctions === undefined) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
const ids = this.externalFunctions.map((f) => f.getFullId());
|
|
173
|
+
return (0, uniq_js_1.uniq)(ids);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.BuildConfigParser = BuildConfigParser;
|
|
177
|
+
//# sourceMappingURL=BuildConfigParser.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BuildFunction } from './BuildFunction.js';
|
|
2
|
+
import { BuildStepContext } from './BuildStepContext.js';
|
|
3
|
+
import { BuildWorkflow } from './BuildWorkflow.js';
|
|
4
|
+
export declare class BuildConfigParser {
|
|
5
|
+
private readonly ctx;
|
|
6
|
+
private readonly configPath;
|
|
7
|
+
private readonly externalFunctions?;
|
|
8
|
+
constructor(ctx: BuildStepContext, { configPath, externalFunctions }: {
|
|
9
|
+
configPath: string;
|
|
10
|
+
externalFunctions?: BuildFunction[];
|
|
11
|
+
});
|
|
12
|
+
parseAsync(): Promise<BuildWorkflow>;
|
|
13
|
+
private readRawConfigAsync;
|
|
14
|
+
private createBuildStepFromConfig;
|
|
15
|
+
private createBuildFunctionsFromConfig;
|
|
16
|
+
private createBuildFunctionFromConfig;
|
|
17
|
+
private createBuildStepInputsFromBuildStepInputsDefinition;
|
|
18
|
+
private createBuildStepInputProvidersFromBuildFunctionInputs;
|
|
19
|
+
private createBuildStepOutputsFromDefinition;
|
|
20
|
+
private createBuildStepOutputProvidersFromBuildFunctionOutputs;
|
|
21
|
+
private mergeBuildFunctionsWithExternal;
|
|
22
|
+
private validateExternalFunctions;
|
|
23
|
+
private getUniqueExternalFunctionIds;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2DAA6B;AAE7B,+BAAoC;AACpC,gDAAwB;AAExB,qDAY0B;AAC1B,yDAAsE;AACtE,iDAA2C;AAE3C,2DAA6E;AAC7E,6DAAgF;AAChF,yDAAmD;AACnD,2EAAqE;AACrE,gFAA0E;AAC1E,kEAA4D;AAC5D,sDAAgD;AAEhD,MAAa,iBAAiB;IAI5B,YACmB,GAAqB,EACtC,EAAE,UAAU,EAAE,iBAAiB,EAA+D;QAD7E,QAAG,GAAH,GAAG,CAAkB;QAGtC,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;QAElD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAEM,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J,CAAC;IAEO,4BAA4B;QAClC,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE;YACxC,OAAO,EAAE,CAAC;SACX;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7D,OAAO,IAAA,cAAI,EAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF;AAxND,8CAwNC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\n\nimport { v4 as uuidv4 } from 'uuid';\nimport YAML from 'yaml';\n\nimport {\n BuildConfig,\n BuildFunctionConfig,\n BuildFunctionInputs,\n BuildFunctionOutputs,\n BuildStepConfig,\n BuildStepInputs,\n BuildStepOutputs,\n isBuildStepBareCommandRun,\n isBuildStepBareFunctionCall,\n isBuildStepCommandRun,\n validateBuildConfig,\n} from './BuildConfig.js';\nimport { BuildFunction, BuildFunctionById } from './BuildFunction.js';\nimport { BuildStep } from './BuildStep.js';\nimport { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputProvider } from './BuildStepInput.js';\nimport { BuildStepOutput, BuildStepOutputProvider } from './BuildStepOutput.js';\nimport { BuildWorkflow } from './BuildWorkflow.js';\nimport { BuildWorkflowValidator } from './BuildWorkflowValidator.js';\nimport { BuildStepRuntimeError } from './errors/BuildStepRuntimeError.js';\nimport { duplicates } from './utils/expodash/duplicates.js';\nimport { uniq } from './utils/expodash/uniq.js';\n\nexport class BuildConfigParser {\n private readonly configPath: string;\n private readonly externalFunctions?: BuildFunction[];\n\n constructor(\n private readonly ctx: BuildStepContext,\n { configPath, externalFunctions }: { configPath: string; externalFunctions?: BuildFunction[] }\n ) {\n this.validateExternalFunctions(externalFunctions);\n\n this.configPath = configPath;\n this.externalFunctions = externalFunctions;\n }\n\n public async parseAsync(): Promise<BuildWorkflow> {\n const rawConfig = await this.readRawConfigAsync();\n const config = validateBuildConfig(rawConfig, this.getUniqueExternalFunctionIds());\n const configBuildFunctions = this.createBuildFunctionsFromConfig(config.functions);\n const buildFunctions = this.mergeBuildFunctionsWithExternal(\n configBuildFunctions,\n this.externalFunctions\n );\n const buildSteps = config.build.steps.map((stepConfig) =>\n this.createBuildStepFromConfig(stepConfig, buildFunctions)\n );\n const workflow = new BuildWorkflow(this.ctx, { buildSteps, buildFunctions });\n new BuildWorkflowValidator(workflow).validate();\n return workflow;\n }\n\n private async readRawConfigAsync(): Promise<any> {\n const contents = await fs.readFile(this.configPath, 'utf-8');\n return YAML.parse(contents);\n }\n\n private createBuildStepFromConfig(\n buildStepConfig: BuildStepConfig,\n buildFunctions: BuildFunctionById\n ): BuildStep {\n if (isBuildStepCommandRun(buildStepConfig)) {\n const {\n id,\n inputs: inputsConfig,\n outputs: outputsConfig,\n name,\n workingDirectory,\n shell,\n command,\n } = buildStepConfig.run;\n const stepId = id ?? uuidv4();\n const inputs =\n inputsConfig &&\n this.createBuildStepInputsFromBuildStepInputsDefinition(inputsConfig, stepId);\n const outputs =\n outputsConfig && this.createBuildStepOutputsFromDefinition(outputsConfig, stepId);\n return new BuildStep(this.ctx, {\n id: stepId,\n inputs,\n outputs,\n name,\n workingDirectory,\n shell,\n command,\n });\n } else if (isBuildStepBareCommandRun(buildStepConfig)) {\n const command = buildStepConfig.run;\n return new BuildStep(this.ctx, {\n id: uuidv4(),\n command,\n });\n } else if (isBuildStepBareFunctionCall(buildStepConfig)) {\n const functionId = buildStepConfig;\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx);\n } else {\n const keys = Object.keys(buildStepConfig);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n const functionId = keys[0];\n const buildFunctionCallConfig = buildStepConfig[functionId];\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx, {\n id: buildFunctionCallConfig.id,\n name: buildFunctionCallConfig.name,\n callInputs: buildFunctionCallConfig.inputs,\n workingDirectory: buildFunctionCallConfig.workingDirectory,\n shell: buildFunctionCallConfig.shell,\n });\n }\n }\n\n private createBuildFunctionsFromConfig(\n buildFunctionsConfig: BuildConfig['functions']\n ): BuildFunctionById {\n if (!buildFunctionsConfig) {\n return {};\n }\n const result: BuildFunctionById = {};\n for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {\n const buildFunction = this.createBuildFunctionFromConfig({\n id: functionId,\n ...buildFunctionConfig,\n });\n result[buildFunction.getFullId()] = buildFunction;\n }\n return result;\n }\n\n private createBuildFunctionFromConfig({\n id,\n name,\n inputs: inputsConfig,\n outputs: outputsConfig,\n shell,\n command,\n }: BuildFunctionConfig & { id: string }): BuildFunction {\n const inputProviders =\n inputsConfig && this.createBuildStepInputProvidersFromBuildFunctionInputs(inputsConfig);\n const outputProviders =\n outputsConfig && this.createBuildStepOutputProvidersFromBuildFunctionOutputs(outputsConfig);\n return new BuildFunction({ id, name, inputProviders, outputProviders, shell, command });\n }\n\n private createBuildStepInputsFromBuildStepInputsDefinition(\n buildStepInputs: BuildStepInputs,\n stepId: string\n ): BuildStepInput[] {\n return Object.entries(buildStepInputs).map(\n ([key, value]) =>\n new BuildStepInput(this.ctx, {\n id: key,\n stepId,\n defaultValue: value,\n required: true,\n })\n );\n }\n\n private createBuildStepInputProvidersFromBuildFunctionInputs(\n buildFunctionInputs: BuildFunctionInputs\n ): BuildStepInputProvider[] {\n return buildFunctionInputs.map((entry) => {\n return typeof entry === 'string'\n ? BuildStepInput.createProvider({ id: entry })\n : BuildStepInput.createProvider({ id: entry.name, required: entry.required ?? true });\n });\n }\n\n private createBuildStepOutputsFromDefinition(\n buildStepOutputs: BuildStepOutputs,\n stepId: string\n ): BuildStepOutput[] {\n return buildStepOutputs.map((entry) =>\n typeof entry === 'string'\n ? new BuildStepOutput(this.ctx, { id: entry, stepId, required: true })\n : new BuildStepOutput(this.ctx, {\n id: entry.name,\n stepId,\n required: entry.required ?? true,\n })\n );\n }\n\n private createBuildStepOutputProvidersFromBuildFunctionOutputs(\n buildFunctionOutputs: BuildFunctionOutputs\n ): BuildStepOutputProvider[] {\n return buildFunctionOutputs.map((entry) =>\n typeof entry === 'string'\n ? BuildStepOutput.createProvider({ id: entry, required: true })\n : BuildStepOutput.createProvider({ id: entry.name, required: entry.required ?? true })\n );\n }\n\n private mergeBuildFunctionsWithExternal(\n configFunctions: BuildFunctionById,\n externalFunctions?: BuildFunction[]\n ): BuildFunctionById {\n const result: BuildFunctionById = { ...configFunctions };\n if (externalFunctions === undefined) {\n return result;\n }\n for (const buildFunction of externalFunctions) {\n // functions defined in config shadow the external ones\n const fullId = buildFunction.getFullId();\n if (!(fullId in result)) {\n result[fullId] = buildFunction;\n }\n }\n return result;\n }\n\n private validateExternalFunctions(externalFunctions?: BuildFunction[]): void {\n if (externalFunctions === undefined) {\n return;\n }\n const externalFunctionIds = externalFunctions.map((f) => f.getFullId());\n const duplicatedExternalFunctionIds = duplicates(externalFunctionIds);\n if (duplicatedExternalFunctionIds.length === 0) {\n return;\n }\n throw new BuildStepRuntimeError(\n `Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds\n .map((id) => `\"${id}\"`)\n .join(', ')}`\n );\n }\n\n private getUniqueExternalFunctionIds(): string[] {\n if (this.externalFunctions === undefined) {\n return [];\n }\n const ids = this.externalFunctions.map((f) => f.getFullId());\n return uniq(ids);\n }\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
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.BuildFunction = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const BuildStep_js_1 = require("./BuildStep.cjs");
|
|
10
|
+
class BuildFunction {
|
|
11
|
+
constructor({ namespace, id, name, platforms, inputProviders, outputProviders, command, fn, shell, }) {
|
|
12
|
+
(0, assert_1.default)(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
|
|
13
|
+
(0, assert_1.default)(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
|
|
14
|
+
this.namespace = namespace;
|
|
15
|
+
this.id = id;
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.platforms = platforms;
|
|
18
|
+
this.inputProviders = inputProviders;
|
|
19
|
+
this.outputProviders = outputProviders;
|
|
20
|
+
this.command = command;
|
|
21
|
+
this.fn = fn;
|
|
22
|
+
this.shell = shell;
|
|
23
|
+
}
|
|
24
|
+
getFullId() {
|
|
25
|
+
return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;
|
|
26
|
+
}
|
|
27
|
+
createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, } = {}) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const buildStepId = id !== null && id !== void 0 ? id : (0, uuid_1.v4)();
|
|
30
|
+
const inputs = (_a = this.inputProviders) === null || _a === void 0 ? void 0 : _a.map((inputProvider) => {
|
|
31
|
+
const input = inputProvider(ctx, buildStepId);
|
|
32
|
+
if (input.id in callInputs) {
|
|
33
|
+
input.set(callInputs[input.id]);
|
|
34
|
+
}
|
|
35
|
+
return input;
|
|
36
|
+
});
|
|
37
|
+
const outputs = (_b = this.outputProviders) === null || _b === void 0 ? void 0 : _b.map((outputProvider) => outputProvider(ctx, buildStepId));
|
|
38
|
+
return new BuildStep_js_1.BuildStep(ctx, {
|
|
39
|
+
id: buildStepId,
|
|
40
|
+
name: name !== null && name !== void 0 ? name : this.name,
|
|
41
|
+
command: this.command,
|
|
42
|
+
fn: this.fn,
|
|
43
|
+
workingDirectory,
|
|
44
|
+
inputs,
|
|
45
|
+
outputs,
|
|
46
|
+
shell,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.BuildFunction = BuildFunction;
|
|
51
|
+
//# sourceMappingURL=BuildFunction.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BuildPlatform } from './BuildPlatform.js';
|
|
2
|
+
import { BuildStep, BuildStepFunction } from './BuildStep.js';
|
|
3
|
+
import { BuildStepContext } from './BuildStepContext.js';
|
|
4
|
+
import { BuildStepInputProvider } from './BuildStepInput.js';
|
|
5
|
+
import { BuildStepOutputProvider } from './BuildStepOutput.js';
|
|
6
|
+
export type BuildFunctionById = Record<string, BuildFunction>;
|
|
7
|
+
export type BuildFunctionCallInputs = Record<string, string>;
|
|
8
|
+
export declare class BuildFunction {
|
|
9
|
+
readonly namespace?: string;
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly name?: string;
|
|
12
|
+
readonly platforms?: BuildPlatform[];
|
|
13
|
+
readonly inputProviders?: BuildStepInputProvider[];
|
|
14
|
+
readonly outputProviders?: BuildStepOutputProvider[];
|
|
15
|
+
readonly command?: string;
|
|
16
|
+
readonly fn?: BuildStepFunction;
|
|
17
|
+
readonly shell?: string;
|
|
18
|
+
constructor({ namespace, id, name, platforms, inputProviders, outputProviders, command, fn, shell, }: {
|
|
19
|
+
namespace?: string;
|
|
20
|
+
id: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
platforms?: BuildPlatform[];
|
|
23
|
+
inputProviders?: BuildStepInputProvider[];
|
|
24
|
+
outputProviders?: BuildStepOutputProvider[];
|
|
25
|
+
command?: string;
|
|
26
|
+
fn?: BuildStepFunction;
|
|
27
|
+
shell?: string;
|
|
28
|
+
});
|
|
29
|
+
getFullId(): string;
|
|
30
|
+
createBuildStepFromFunctionCall(ctx: BuildStepContext, { id, name, callInputs, workingDirectory, shell, }?: {
|
|
31
|
+
id?: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
callInputs?: BuildFunctionCallInputs;
|
|
34
|
+
workingDirectory?: string;
|
|
35
|
+
shell?: string;
|
|
36
|
+
}): BuildStep;
|
|
37
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,EAAE,cAAF,EAAE,GAAI,IAAA,SAAM,GAAE,CAAC;QAEnC,MAAM,MAAM,GAAG,MAAA,IAAI,CAAC,cAAc,0CAAE,GAAG,CAAC,CAAC,aAAa,EAAE,EAAE;YACxD,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;YAC9C,IAAI,KAAK,CAAC,EAAE,IAAI,UAAU,EAAE;gBAC1B,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;aACjC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,eAAe,0CAAE,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;QAEhG,OAAO,IAAI,wBAAS,CAAC,GAAG,EAAE;YACxB,EAAE,EAAE,WAAW;YACf,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC,IAAI;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,gBAAgB;YAChB,MAAM;YACN,OAAO;YACP,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AAxFD,sCAwFC","sourcesContent":["import assert from 'assert';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildPlatform } from './BuildPlatform.js';\nimport { BuildStep, BuildStepFunction } from './BuildStep.js';\nimport { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepInputProvider } from './BuildStepInput.js';\nimport { BuildStepOutputProvider } from './BuildStepOutput.js';\n\nexport type BuildFunctionById = Record<string, BuildFunction>;\nexport type BuildFunctionCallInputs = Record<string, string>;\n\nexport class BuildFunction {\n public readonly namespace?: string;\n public readonly id: string;\n public readonly name?: string;\n public readonly platforms?: BuildPlatform[];\n public readonly inputProviders?: BuildStepInputProvider[];\n public readonly outputProviders?: BuildStepOutputProvider[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell?: string;\n\n constructor({\n namespace,\n id,\n name,\n platforms,\n inputProviders,\n outputProviders,\n command,\n fn,\n shell,\n }: {\n namespace?: string;\n id: string;\n name?: string;\n platforms?: BuildPlatform[];\n inputProviders?: BuildStepInputProvider[];\n outputProviders?: BuildStepOutputProvider[];\n command?: string;\n fn?: BuildStepFunction;\n shell?: string;\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.namespace = namespace;\n this.id = id;\n this.name = name;\n this.platforms = platforms;\n this.inputProviders = inputProviders;\n this.outputProviders = outputProviders;\n this.command = command;\n this.fn = fn;\n this.shell = shell;\n }\n\n public getFullId(): string {\n return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;\n }\n\n public createBuildStepFromFunctionCall(\n ctx: BuildStepContext,\n {\n id,\n name,\n callInputs = {},\n workingDirectory,\n shell,\n }: {\n id?: string;\n name?: string;\n callInputs?: BuildFunctionCallInputs;\n workingDirectory?: string;\n shell?: string;\n } = {}\n ): BuildStep {\n const buildStepId = id ?? uuidv4();\n\n const inputs = this.inputProviders?.map((inputProvider) => {\n const input = inputProvider(ctx, buildStepId);\n if (input.id in callInputs) {\n input.set(callInputs[input.id]);\n }\n return input;\n });\n const outputs = this.outputProviders?.map((outputProvider) => outputProvider(ctx, buildStepId));\n\n return new BuildStep(ctx, {\n id: buildStepId,\n name: name ?? this.name,\n command: this.command,\n fn: this.fn,\n workingDirectory,\n inputs,\n outputs,\n shell,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuildPlatform = void 0;
|
|
4
|
+
var BuildPlatform;
|
|
5
|
+
(function (BuildPlatform) {
|
|
6
|
+
BuildPlatform["DARWIN"] = "darwin";
|
|
7
|
+
BuildPlatform["LINUX"] = "linux";
|
|
8
|
+
})(BuildPlatform = exports.BuildPlatform || (exports.BuildPlatform = {}));
|
|
9
|
+
//# sourceMappingURL=BuildPlatform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuildPlatform.js","sourceRoot":"","sources":["../src/BuildPlatform.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,gCAAe,CAAA;AACjB,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB","sourcesContent":["export enum BuildPlatform {\n DARWIN = 'darwin',\n LINUX = 'linux',\n}\n"]}
|