@expo/steps 0.0.8 → 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 +13 -9
- package/dist_commonjs/BuildConfig.d.ts +1 -2
- package/dist_commonjs/BuildConfig.js.map +1 -1
- package/dist_commonjs/BuildConfigParser.cjs +68 -45
- package/dist_commonjs/BuildConfigParser.d.ts +9 -4
- package/dist_commonjs/BuildConfigParser.js.map +1 -1
- package/dist_commonjs/BuildFunction.cjs +23 -12
- package/dist_commonjs/BuildFunction.d.ts +20 -15
- package/dist_commonjs/BuildFunction.js.map +1 -1
- package/dist_commonjs/BuildStep.cjs +56 -36
- package/dist_commonjs/BuildStep.d.ts +17 -9
- package/dist_commonjs/BuildStep.js.map +1 -1
- package/dist_commonjs/BuildStepContext.cjs +3 -0
- package/dist_commonjs/BuildStepContext.d.ts +4 -0
- package/dist_commonjs/BuildStepContext.js.map +1 -1
- package/dist_commonjs/BuildStepInput.cjs +14 -1
- package/dist_commonjs/BuildStepInput.d.ts +8 -1
- package/dist_commonjs/BuildStepInput.js.map +1 -1
- package/dist_commonjs/BuildStepOutput.cjs +14 -1
- package/dist_commonjs/BuildStepOutput.d.ts +7 -1
- package/dist_commonjs/BuildStepOutput.js.map +1 -1
- package/dist_commonjs/BuildTemporaryFiles.cjs +1 -59
- package/dist_commonjs/BuildTemporaryFiles.d.ts +0 -4
- package/dist_commonjs/BuildTemporaryFiles.js.map +1 -1
- package/dist_commonjs/BuildWorkflow.cjs +3 -16
- package/dist_commonjs/BuildWorkflow.d.ts +0 -3
- package/dist_commonjs/BuildWorkflow.js.map +1 -1
- package/dist_commonjs/BuildWorkflowValidator.cjs +2 -11
- package/dist_commonjs/BuildWorkflowValidator.js.map +1 -1
- package/dist_commonjs/cli/cli.cjs +0 -4
- package/dist_commonjs/cli/cli.js.map +1 -1
- package/dist_commonjs/index.cjs +7 -3
- package/dist_commonjs/index.d.ts +3 -1
- package/dist_commonjs/index.js.map +1 -1
- package/dist_commonjs/utils/expodash/duplicates.cjs +18 -0
- package/dist_commonjs/utils/expodash/duplicates.d.ts +1 -0
- package/dist_commonjs/utils/expodash/duplicates.js.map +1 -0
- package/dist_esm/BuildConfig.d.ts +1 -2
- package/dist_esm/BuildConfig.js +13 -9
- package/dist_esm/BuildConfig.js.map +1 -1
- package/dist_esm/BuildConfigParser.d.ts +9 -4
- package/dist_esm/BuildConfigParser.js +68 -45
- package/dist_esm/BuildConfigParser.js.map +1 -1
- package/dist_esm/BuildFunction.d.ts +20 -15
- package/dist_esm/BuildFunction.js +20 -12
- package/dist_esm/BuildFunction.js.map +1 -1
- package/dist_esm/BuildStep.d.ts +17 -9
- package/dist_esm/BuildStep.js +56 -36
- package/dist_esm/BuildStep.js.map +1 -1
- package/dist_esm/BuildStepContext.d.ts +4 -0
- package/dist_esm/BuildStepContext.js +3 -0
- package/dist_esm/BuildStepContext.js.map +1 -1
- package/dist_esm/BuildStepInput.d.ts +8 -1
- package/dist_esm/BuildStepInput.js +12 -0
- package/dist_esm/BuildStepInput.js.map +1 -1
- package/dist_esm/BuildStepOutput.d.ts +7 -1
- package/dist_esm/BuildStepOutput.js +12 -0
- package/dist_esm/BuildStepOutput.js.map +1 -1
- package/dist_esm/BuildTemporaryFiles.d.ts +0 -4
- package/dist_esm/BuildTemporaryFiles.js +0 -55
- package/dist_esm/BuildTemporaryFiles.js.map +1 -1
- package/dist_esm/BuildWorkflow.d.ts +0 -3
- package/dist_esm/BuildWorkflow.js +3 -16
- package/dist_esm/BuildWorkflow.js.map +1 -1
- package/dist_esm/BuildWorkflowValidator.js +2 -11
- package/dist_esm/BuildWorkflowValidator.js.map +1 -1
- package/dist_esm/cli/cli.js +0 -4
- package/dist_esm/cli/cli.js.map +1 -1
- package/dist_esm/index.d.ts +3 -1
- package/dist_esm/index.js +3 -1
- package/dist_esm/index.js.map +1 -1
- package/dist_esm/utils/expodash/duplicates.d.ts +1 -0
- package/dist_esm/utils/expodash/duplicates.js +14 -0
- package/dist_esm/utils/expodash/duplicates.js.map +1 -0
- package/package.json +2 -1
- package/bin/upload-artifact +0 -12
- package/dist_commonjs/BuildArtifacts.cjs +0 -9
- package/dist_commonjs/BuildArtifacts.d.ts +0 -5
- package/dist_commonjs/BuildArtifacts.js.map +0 -1
- package/dist_commonjs/bin/uploadArtifact.cjs +0 -30
- package/dist_commonjs/bin/uploadArtifact.d.ts +0 -1
- package/dist_commonjs/bin/uploadArtifact.js.map +0 -1
- package/dist_esm/BuildArtifacts.d.ts +0 -5
- package/dist_esm/BuildArtifacts.js +0 -6
- package/dist_esm/BuildArtifacts.js.map +0 -1
- package/dist_esm/bin/uploadArtifact.d.ts +0 -1
- package/dist_esm/bin/uploadArtifact.js +0 -25
- package/dist_esm/bin/uploadArtifact.js.map +0 -1
|
@@ -39,8 +39,7 @@ const BuildStepConfigSchema = joi_1.default.any()
|
|
|
39
39
|
.when(joi_1.default.string(), {
|
|
40
40
|
then: joi_1.default.string().min(1),
|
|
41
41
|
});
|
|
42
|
-
const
|
|
43
|
-
id: joi_1.default.string(),
|
|
42
|
+
const BuildFunctionConfigSchema = joi_1.default.object({
|
|
44
43
|
name: joi_1.default.string(),
|
|
45
44
|
platforms: joi_1.default.string().allow(...Object.values(BuildPlatform_js_1.BuildPlatform)),
|
|
46
45
|
inputs: BuildInputOutputParametersSchema,
|
|
@@ -53,7 +52,11 @@ exports.BuildConfigSchema = joi_1.default.object({
|
|
|
53
52
|
name: joi_1.default.string(),
|
|
54
53
|
steps: joi_1.default.array().items(BuildStepConfigSchema.required()).required(),
|
|
55
54
|
}).required(),
|
|
56
|
-
functions: joi_1.default.object().pattern(joi_1.default.string()
|
|
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()),
|
|
57
60
|
}).required();
|
|
58
61
|
function isBuildStepCommandRun(step) {
|
|
59
62
|
return typeof step === 'object' && typeof step.run === 'object';
|
|
@@ -71,7 +74,7 @@ function isBuildStepBareFunctionCall(step) {
|
|
|
71
74
|
return typeof step === 'string';
|
|
72
75
|
}
|
|
73
76
|
exports.isBuildStepBareFunctionCall = isBuildStepBareFunctionCall;
|
|
74
|
-
function validateBuildConfig(rawConfig) {
|
|
77
|
+
function validateBuildConfig(rawConfig, externalFunctionIds) {
|
|
75
78
|
const { error, value: buildConfig } = exports.BuildConfigSchema.validate(rawConfig, {
|
|
76
79
|
allowUnknown: false,
|
|
77
80
|
abortEarly: false,
|
|
@@ -80,11 +83,11 @@ function validateBuildConfig(rawConfig) {
|
|
|
80
83
|
const errorMessage = error.details.map(({ message }) => message).join(', ');
|
|
81
84
|
throw new BuildConfigError_js_1.BuildConfigError(errorMessage, { cause: error });
|
|
82
85
|
}
|
|
83
|
-
validateAllFunctionsExist(buildConfig);
|
|
86
|
+
validateAllFunctionsExist(buildConfig, externalFunctionIds);
|
|
84
87
|
return buildConfig;
|
|
85
88
|
}
|
|
86
89
|
exports.validateBuildConfig = validateBuildConfig;
|
|
87
|
-
function validateAllFunctionsExist(config) {
|
|
90
|
+
function validateAllFunctionsExist(config, externalFunctionIds) {
|
|
88
91
|
const calledFunctionsSet = new Set();
|
|
89
92
|
for (const step of config.build.steps) {
|
|
90
93
|
if (typeof step === 'string') {
|
|
@@ -92,17 +95,18 @@ function validateAllFunctionsExist(config) {
|
|
|
92
95
|
}
|
|
93
96
|
else if (!('run' in step)) {
|
|
94
97
|
const keys = Object.keys(step);
|
|
95
|
-
(0, assert_1.default)(keys.length === 1, 'There must be at most one function call in the step (enforced by joi)');
|
|
98
|
+
(0, assert_1.default)(keys.length === 1, 'There must be at most one function call in the step (enforced by joi).');
|
|
96
99
|
calledFunctionsSet.add(keys[0]);
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
const calledFunctions = Array.from(calledFunctionsSet);
|
|
103
|
+
const externalFunctionIdsSet = new Set(externalFunctionIds);
|
|
100
104
|
const nonExistentFunctions = calledFunctions.filter((calledFunction) => {
|
|
101
105
|
var _a;
|
|
102
|
-
return !(calledFunction in ((_a = config.functions) !== null && _a !== void 0 ? _a : {}));
|
|
106
|
+
return (!(calledFunction in ((_a = config.functions) !== null && _a !== void 0 ? _a : {})) && !externalFunctionIdsSet.has(calledFunction));
|
|
103
107
|
});
|
|
104
108
|
if (nonExistentFunctions.length > 0) {
|
|
105
|
-
throw new BuildConfigError_js_1.BuildConfigError(`Calling non-existent functions: ${nonExistentFunctions.join(', ')}
|
|
109
|
+
throw new BuildConfigError_js_1.BuildConfigError(`Calling non-existent functions: ${nonExistentFunctions.map((f) => `"${f}"`).join(', ')}.`);
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
//# sourceMappingURL=BuildConfig.js.map
|
|
@@ -31,7 +31,6 @@ export type BuildFunctionCallConfig = {
|
|
|
31
31
|
export type BuildStepInputs = Record<string, string>;
|
|
32
32
|
export type BuildStepOutputs = BuildInputOutputParameters;
|
|
33
33
|
export interface BuildFunctionConfig {
|
|
34
|
-
id?: string;
|
|
35
34
|
inputs?: BuildFunctionInputs;
|
|
36
35
|
outputs?: BuildFunctionOutputs;
|
|
37
36
|
name?: string;
|
|
@@ -50,4 +49,4 @@ export declare function isBuildStepCommandRun(step: BuildStepConfig): step is Bu
|
|
|
50
49
|
export declare function isBuildStepBareCommandRun(step: BuildStepConfig): step is BuildStepBareCommandRun;
|
|
51
50
|
export declare function isBuildStepFunctionCall(step: BuildStepConfig): step is BuildStepFunctionCall;
|
|
52
51
|
export declare function isBuildStepBareFunctionCall(step: BuildStepConfig): step is BuildStepBareFunctionCall;
|
|
53
|
-
export declare function validateBuildConfig(rawConfig: object): BuildConfig;
|
|
52
|
+
export declare function validateBuildConfig(rawConfig: object, externalFunctionIds: string[]): BuildConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildConfig.js","source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I,CAAC,MAAA,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,MAAM,IAAI,sCAAgB,CACxB,mCAAmC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACrE,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 id?: string;\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 BuildFunctionSchema = Joi.object({\n id: Joi.string(),\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().min(1).required().disallow('run'),\n BuildFunctionSchema.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): 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);\n return buildConfig;\n}\n\nfunction validateAllFunctionsExist(config: BuildConfig): 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 nonExistentFunctions = calledFunctions.filter((calledFunction) => {\n return !(calledFunction in (config.functions ?? {}));\n });\n if (nonExistentFunctions.length > 0) {\n throw new BuildConfigError(\n `Calling non-existent functions: ${nonExistentFunctions.join(', ')}`\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,8CAAsB;AAEtB,sEAAgE;AAChE,yDAAmD;AA2DnD,MAAM,gCAAgC,GAAG,aAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CACxD,aAAG,CAAC,YAAY,EAAE,CAAC,GAAG,CACpB,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EACvB,aAAG,CAAC,MAAM,CAAC;IACT,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,QAAQ,EAAE,aAAG,CAAC,OAAO,EAAE;CACxB,CAAC,CAAC,QAAQ,EAAE,CACd,CACF,CAAC;AAEF,MAAM,uBAAuB,GAAG,aAAG,CAAC,MAA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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"]}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BuildConfigParser = void 0;
|
|
7
7
|
const assert_1 = __importDefault(require("assert"));
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
9
|
const uuid_1 = require("uuid");
|
|
11
10
|
const yaml_1 = __importDefault(require("yaml"));
|
|
12
11
|
const BuildConfig_js_1 = require("./BuildConfig.cjs");
|
|
@@ -16,15 +15,21 @@ const BuildStepInput_js_1 = require("./BuildStepInput.cjs");
|
|
|
16
15
|
const BuildStepOutput_js_1 = require("./BuildStepOutput.cjs");
|
|
17
16
|
const BuildWorkflow_js_1 = require("./BuildWorkflow.cjs");
|
|
18
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");
|
|
19
21
|
class BuildConfigParser {
|
|
20
|
-
constructor(ctx, { configPath }) {
|
|
22
|
+
constructor(ctx, { configPath, externalFunctions }) {
|
|
21
23
|
this.ctx = ctx;
|
|
24
|
+
this.validateExternalFunctions(externalFunctions);
|
|
22
25
|
this.configPath = configPath;
|
|
26
|
+
this.externalFunctions = externalFunctions;
|
|
23
27
|
}
|
|
24
28
|
async parseAsync() {
|
|
25
29
|
const rawConfig = await this.readRawConfigAsync();
|
|
26
|
-
const config = (0, BuildConfig_js_1.validateBuildConfig)(rawConfig);
|
|
27
|
-
const
|
|
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);
|
|
28
33
|
const buildSteps = config.build.steps.map((stepConfig) => this.createBuildStepFromConfig(stepConfig, buildFunctions));
|
|
29
34
|
const workflow = new BuildWorkflow_js_1.BuildWorkflow(this.ctx, { buildSteps, buildFunctions });
|
|
30
35
|
new BuildWorkflowValidator_js_1.BuildWorkflowValidator(workflow).validate();
|
|
@@ -46,7 +51,7 @@ class BuildConfigParser {
|
|
|
46
51
|
inputs,
|
|
47
52
|
outputs,
|
|
48
53
|
name,
|
|
49
|
-
workingDirectory
|
|
54
|
+
workingDirectory,
|
|
50
55
|
shell,
|
|
51
56
|
command,
|
|
52
57
|
});
|
|
@@ -55,27 +60,25 @@ class BuildConfigParser {
|
|
|
55
60
|
const command = buildStepConfig.run;
|
|
56
61
|
return new BuildStep_js_1.BuildStep(this.ctx, {
|
|
57
62
|
id: (0, uuid_1.v4)(),
|
|
58
|
-
workingDirectory: this.ctx.workingDirectory,
|
|
59
63
|
command,
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
else if ((0, BuildConfig_js_1.isBuildStepBareFunctionCall)(buildStepConfig)) {
|
|
63
67
|
const functionId = buildStepConfig;
|
|
64
68
|
const buildFunction = buildFunctions[functionId];
|
|
65
|
-
return buildFunction.createBuildStepFromFunctionCall(
|
|
66
|
-
workingDirectory: this.getStepWorkingDirectory(),
|
|
67
|
-
});
|
|
69
|
+
return buildFunction.createBuildStepFromFunctionCall(this.ctx);
|
|
68
70
|
}
|
|
69
71
|
else {
|
|
70
72
|
const keys = Object.keys(buildStepConfig);
|
|
71
|
-
(0, assert_1.default)(keys.length === 1, 'There must be at most one function call in the step (enforced by joi)');
|
|
73
|
+
(0, assert_1.default)(keys.length === 1, 'There must be at most one function call in the step (enforced by joi).');
|
|
72
74
|
const functionId = keys[0];
|
|
73
75
|
const buildFunctionCallConfig = buildStepConfig[functionId];
|
|
74
76
|
const buildFunction = buildFunctions[functionId];
|
|
75
|
-
return buildFunction.createBuildStepFromFunctionCall({
|
|
77
|
+
return buildFunction.createBuildStepFromFunctionCall(this.ctx, {
|
|
76
78
|
id: buildFunctionCallConfig.id,
|
|
79
|
+
name: buildFunctionCallConfig.name,
|
|
77
80
|
callInputs: buildFunctionCallConfig.inputs,
|
|
78
|
-
workingDirectory:
|
|
81
|
+
workingDirectory: buildFunctionCallConfig.workingDirectory,
|
|
79
82
|
shell: buildFunctionCallConfig.shell,
|
|
80
83
|
});
|
|
81
84
|
}
|
|
@@ -86,14 +89,18 @@ class BuildConfigParser {
|
|
|
86
89
|
}
|
|
87
90
|
const result = {};
|
|
88
91
|
for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {
|
|
89
|
-
|
|
92
|
+
const buildFunction = this.createBuildFunctionFromConfig({
|
|
93
|
+
id: functionId,
|
|
94
|
+
...buildFunctionConfig,
|
|
95
|
+
});
|
|
96
|
+
result[buildFunction.getFullId()] = buildFunction;
|
|
90
97
|
}
|
|
91
98
|
return result;
|
|
92
99
|
}
|
|
93
100
|
createBuildFunctionFromConfig({ id, name, inputs: inputsConfig, outputs: outputsConfig, shell, command, }) {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
return new BuildFunction_js_1.BuildFunction(
|
|
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 });
|
|
97
104
|
}
|
|
98
105
|
createBuildStepInputsFromBuildStepInputsDefinition(buildStepInputs, stepId) {
|
|
99
106
|
return Object.entries(buildStepInputs).map(([key, value]) => new BuildStepInput_js_1.BuildStepInput(this.ctx, {
|
|
@@ -103,21 +110,12 @@ class BuildConfigParser {
|
|
|
103
110
|
required: true,
|
|
104
111
|
}));
|
|
105
112
|
}
|
|
106
|
-
|
|
113
|
+
createBuildStepInputProvidersFromBuildFunctionInputs(buildFunctionInputs) {
|
|
107
114
|
return buildFunctionInputs.map((entry) => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return (stepId) => {
|
|
113
|
-
var _a;
|
|
114
|
-
return new BuildStepInput_js_1.BuildStepInput(this.ctx, {
|
|
115
|
-
id: entry.name,
|
|
116
|
-
required: (_a = entry.required) !== null && _a !== void 0 ? _a : true,
|
|
117
|
-
stepId,
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
}
|
|
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 });
|
|
121
119
|
});
|
|
122
120
|
}
|
|
123
121
|
createBuildStepOutputsFromDefinition(buildStepOutputs, stepId) {
|
|
@@ -132,22 +130,47 @@ class BuildConfigParser {
|
|
|
132
130
|
});
|
|
133
131
|
});
|
|
134
132
|
}
|
|
135
|
-
|
|
136
|
-
return buildFunctionOutputs.map((entry) =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
stepId,
|
|
143
|
-
required: (_a = entry.required) !== null && _a !== void 0 ? _a : true,
|
|
144
|
-
});
|
|
145
|
-
});
|
|
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
|
+
});
|
|
146
140
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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);
|
|
151
174
|
}
|
|
152
175
|
}
|
|
153
176
|
exports.BuildConfigParser = BuildConfigParser;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { BuildFunction } from './BuildFunction.js';
|
|
1
2
|
import { BuildStepContext } from './BuildStepContext.js';
|
|
2
3
|
import { BuildWorkflow } from './BuildWorkflow.js';
|
|
3
4
|
export declare class BuildConfigParser {
|
|
4
5
|
private readonly ctx;
|
|
5
6
|
private readonly configPath;
|
|
6
|
-
|
|
7
|
+
private readonly externalFunctions?;
|
|
8
|
+
constructor(ctx: BuildStepContext, { configPath, externalFunctions }: {
|
|
7
9
|
configPath: string;
|
|
10
|
+
externalFunctions?: BuildFunction[];
|
|
8
11
|
});
|
|
9
12
|
parseAsync(): Promise<BuildWorkflow>;
|
|
10
13
|
private readRawConfigAsync;
|
|
@@ -12,8 +15,10 @@ export declare class BuildConfigParser {
|
|
|
12
15
|
private createBuildFunctionsFromConfig;
|
|
13
16
|
private createBuildFunctionFromConfig;
|
|
14
17
|
private createBuildStepInputsFromBuildStepInputsDefinition;
|
|
15
|
-
private
|
|
18
|
+
private createBuildStepInputProvidersFromBuildFunctionInputs;
|
|
16
19
|
private createBuildStepOutputsFromDefinition;
|
|
17
|
-
private
|
|
18
|
-
private
|
|
20
|
+
private createBuildStepOutputProvidersFromBuildFunctionOutputs;
|
|
21
|
+
private mergeBuildFunctionsWithExternal;
|
|
22
|
+
private validateExternalFunctions;
|
|
23
|
+
private getUniqueExternalFunctionIds;
|
|
19
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2DAA6B;AAC7B,gDAAwB;AAExB,+BAAoC;AACpC,gDAAwB;AAExB,qDAY0B;AAC1B,yDAAsE;AACtE,iDAA2C;AAE3C,2DAA4E;AAC5E,6DAA+E;AAC/E,yDAAmD;AACnD,2EAAqE;AAErE,MAAa,iBAAiB;IAG5B,YAA6B,GAAqB,EAAE,EAAE,UAAU,EAA0B;QAA7D,QAAG,GAAH,GAAG,CAAkB;QAChD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,IAAA,oCAAmB,EAAC,SAAS,CAAC,CAAC;QAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,8BAA8B,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7E,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACvD,IAAI,CAAC,yBAAyB,CAAC,UAAU,EAAE,cAAc,CAAC,CAC3D,CAAC;QACF,MAAM,QAAQ,GAAG,IAAI,gCAAa,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC,CAAC;QAC7E,IAAI,kDAAsB,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,KAAK,CAAC,kBAAkB;QAC9B,MAAM,QAAQ,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,E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8CAmLC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\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, BuildStepInputCreator } from './BuildStepInput.js';\nimport { BuildStepOutput, BuildStepOutputCreator } from './BuildStepOutput.js';\nimport { BuildWorkflow } from './BuildWorkflow.js';\nimport { BuildWorkflowValidator } from './BuildWorkflowValidator.js';\n\nexport class BuildConfigParser {\n private readonly configPath: string;\n\n constructor(private readonly ctx: BuildStepContext, { configPath }: { configPath: string }) {\n this.configPath = configPath;\n }\n\n public async parseAsync(): Promise<BuildWorkflow> {\n const rawConfig = await this.readRawConfigAsync();\n const config = validateBuildConfig(rawConfig);\n const buildFunctions = this.createBuildFunctionsFromConfig(config.functions);\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: this.getStepWorkingDirectory(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 workingDirectory: this.ctx.workingDirectory,\n command,\n });\n } else if (isBuildStepBareFunctionCall(buildStepConfig)) {\n const functionId = buildStepConfig;\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall({\n workingDirectory: this.getStepWorkingDirectory(),\n });\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({\n id: buildFunctionCallConfig.id,\n callInputs: buildFunctionCallConfig.inputs,\n workingDirectory: this.getStepWorkingDirectory(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 result[functionId] = this.createBuildFunctionFromConfig(buildFunctionConfig);\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): BuildFunction {\n const inputCreators =\n inputsConfig && this.createBuildStepInputCreatorsFromBuildFunctionInputs(inputsConfig);\n const outputCreators =\n outputsConfig && this.createBuildStepOutputCreatorsFromBuildFunctionOutputs(outputsConfig);\n return new BuildFunction(this.ctx, { id, name, inputCreators, outputCreators, 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 createBuildStepInputCreatorsFromBuildFunctionInputs(\n buildFunctionInputs: BuildFunctionInputs\n ): BuildStepInputCreator[] {\n return buildFunctionInputs.map((entry) => {\n if (typeof entry === 'string') {\n return (stepId: string) => new BuildStepInput(this.ctx, { id: entry, stepId });\n } else {\n return (stepId: string) =>\n new BuildStepInput(this.ctx, {\n id: entry.name,\n required: entry.required ?? true,\n stepId,\n });\n }\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 createBuildStepOutputCreatorsFromBuildFunctionOutputs(\n buildFunctionOutputs: BuildFunctionOutputs\n ): BuildStepOutputCreator[] {\n return buildFunctionOutputs.map((entry) =>\n typeof entry === 'string'\n ? (stepId: string) => new BuildStepOutput(this.ctx, { id: entry, stepId, required: true })\n : (stepId: string) =>\n new BuildStepOutput(this.ctx, {\n id: entry.name,\n stepId,\n required: entry.required ?? true,\n })\n );\n }\n\n private getStepWorkingDirectory(workingDirectory?: string): string {\n return workingDirectory !== undefined\n ? path.resolve(this.ctx.workingDirectory, workingDirectory)\n : this.ctx.workingDirectory;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2DA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B,KAAK,SAAS,EAAE;YACnC,OAAO;SACR;QACD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACxE,MAAM,6BAA6B,GAAG,IAAA,0BAAU,EAAC,mBAAmB,CAAC,CAAC;QACtE,IAAI,6BAA6B,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,OAAO;SACR;QACD,MAAM,IAAI,gDAAqB,CAC7B,oDAAoD,6BAA6B;aAC9E,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;aACtB,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;IACJ,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"]}
|
|
@@ -1,34 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.BuildFunction = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
4
8
|
const uuid_1 = require("uuid");
|
|
5
9
|
const BuildStep_js_1 = require("./BuildStep.cjs");
|
|
6
10
|
class BuildFunction {
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
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;
|
|
9
15
|
this.id = id;
|
|
10
16
|
this.name = name;
|
|
11
17
|
this.platforms = platforms;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
18
|
+
this.inputProviders = inputProviders;
|
|
19
|
+
this.outputProviders = outputProviders;
|
|
14
20
|
this.command = command;
|
|
21
|
+
this.fn = fn;
|
|
15
22
|
this.shell = shell;
|
|
16
23
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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);
|
|
22
32
|
if (input.id in callInputs) {
|
|
23
33
|
input.set(callInputs[input.id]);
|
|
24
34
|
}
|
|
25
35
|
return input;
|
|
26
36
|
});
|
|
27
|
-
const outputs = (
|
|
28
|
-
return new BuildStep_js_1.BuildStep(
|
|
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, {
|
|
29
39
|
id: buildStepId,
|
|
30
|
-
name: this.name,
|
|
40
|
+
name: name !== null && name !== void 0 ? name : this.name,
|
|
31
41
|
command: this.command,
|
|
42
|
+
fn: this.fn,
|
|
32
43
|
workingDirectory,
|
|
33
44
|
inputs,
|
|
34
45
|
outputs,
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
import { BuildPlatform } from './BuildPlatform.js';
|
|
2
|
-
import { BuildStep } from './BuildStep.js';
|
|
2
|
+
import { BuildStep, BuildStepFunction } from './BuildStep.js';
|
|
3
3
|
import { BuildStepContext } from './BuildStepContext.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { BuildStepInputProvider } from './BuildStepInput.js';
|
|
5
|
+
import { BuildStepOutputProvider } from './BuildStepOutput.js';
|
|
6
6
|
export type BuildFunctionById = Record<string, BuildFunction>;
|
|
7
7
|
export type BuildFunctionCallInputs = Record<string, string>;
|
|
8
8
|
export declare class BuildFunction {
|
|
9
|
-
|
|
10
|
-
readonly id
|
|
9
|
+
readonly namespace?: string;
|
|
10
|
+
readonly id: string;
|
|
11
11
|
readonly name?: string;
|
|
12
12
|
readonly platforms?: BuildPlatform[];
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly command
|
|
13
|
+
readonly inputProviders?: BuildStepInputProvider[];
|
|
14
|
+
readonly outputProviders?: BuildStepOutputProvider[];
|
|
15
|
+
readonly command?: string;
|
|
16
|
+
readonly fn?: BuildStepFunction;
|
|
16
17
|
readonly shell?: string;
|
|
17
|
-
constructor(
|
|
18
|
-
|
|
18
|
+
constructor({ namespace, id, name, platforms, inputProviders, outputProviders, command, fn, shell, }: {
|
|
19
|
+
namespace?: string;
|
|
20
|
+
id: string;
|
|
19
21
|
name?: string;
|
|
20
22
|
platforms?: BuildPlatform[];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
command
|
|
23
|
+
inputProviders?: BuildStepInputProvider[];
|
|
24
|
+
outputProviders?: BuildStepOutputProvider[];
|
|
25
|
+
command?: string;
|
|
26
|
+
fn?: BuildStepFunction;
|
|
24
27
|
shell?: string;
|
|
25
28
|
});
|
|
26
|
-
|
|
29
|
+
getFullId(): string;
|
|
30
|
+
createBuildStepFromFunctionCall(ctx: BuildStepContext, { id, name, callInputs, workingDirectory, shell, }?: {
|
|
27
31
|
id?: string;
|
|
32
|
+
name?: string;
|
|
28
33
|
callInputs?: BuildFunctionCallInputs;
|
|
29
|
-
workingDirectory
|
|
34
|
+
workingDirectory?: string;
|
|
30
35
|
shell?: string;
|
|
31
36
|
}): BuildStep;
|
|
32
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildFunction.js","sourceRoot":"","sources":["../src/BuildFunction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BuildFunction.js","sourceRoot":"","sources":["../src/BuildFunction.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,+BAAoC;AAGpC,iDAA8D;AAQ9D,MAAa,aAAa;IAWxB,YAAY,EACV,SAAS,EACT,EAAE,EACF,IAAI,EACJ,SAAS,EACT,cAAc,EACd,eAAe,EACf,OAAO,EACP,EAAE,EACF,KAAK,GAWN;QACC,IAAA,gBAAM,EAAC,OAAO,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS,EAAE,u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C,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"]}
|