@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.
Files changed (158) hide show
  1. package/dist_commonjs/BuildConfig.cjs +112 -0
  2. package/dist_commonjs/BuildConfig.d.ts +52 -0
  3. package/dist_commonjs/BuildConfig.js.map +1 -0
  4. package/dist_commonjs/BuildConfigParser.cjs +177 -0
  5. package/dist_commonjs/BuildConfigParser.d.ts +24 -0
  6. package/dist_commonjs/BuildConfigParser.js.map +1 -0
  7. package/dist_commonjs/BuildFunction.cjs +51 -0
  8. package/dist_commonjs/BuildFunction.d.ts +37 -0
  9. package/dist_commonjs/BuildFunction.js.map +1 -0
  10. package/dist_commonjs/BuildPlatform.cjs +9 -0
  11. package/dist_commonjs/BuildPlatform.d.ts +4 -0
  12. package/dist_commonjs/BuildPlatform.js.map +1 -0
  13. package/dist_commonjs/BuildStep.cjs +199 -0
  14. package/dist_commonjs/BuildStep.d.ts +56 -0
  15. package/dist_commonjs/BuildStep.js.map +1 -0
  16. package/dist_commonjs/BuildStepContext.cjs +35 -0
  17. package/dist_commonjs/BuildStepContext.d.ts +17 -0
  18. package/dist_commonjs/BuildStepContext.js.map +1 -0
  19. package/dist_commonjs/BuildStepEnv.cjs +3 -0
  20. package/dist_commonjs/BuildStepEnv.d.ts +1 -0
  21. package/dist_commonjs/BuildStepEnv.js.map +1 -0
  22. package/dist_commonjs/BuildStepInput.cjs +49 -0
  23. package/dist_commonjs/BuildStepInput.d.ts +25 -0
  24. package/dist_commonjs/BuildStepInput.js.map +1 -0
  25. package/dist_commonjs/BuildStepOutput.cjs +42 -0
  26. package/dist_commonjs/BuildStepOutput.d.ts +22 -0
  27. package/dist_commonjs/BuildStepOutput.js.map +1 -0
  28. package/dist_commonjs/BuildTemporaryFiles.cjs +42 -0
  29. package/dist_commonjs/BuildTemporaryFiles.d.ts +4 -0
  30. package/dist_commonjs/BuildTemporaryFiles.js.map +1 -0
  31. package/dist_commonjs/BuildWorkflow.cjs +19 -0
  32. package/dist_commonjs/BuildWorkflow.d.ts +14 -0
  33. package/dist_commonjs/BuildWorkflow.js.map +1 -0
  34. package/dist_commonjs/BuildWorkflowValidator.cjs +67 -0
  35. package/dist_commonjs/BuildWorkflowValidator.d.ts +8 -0
  36. package/dist_commonjs/BuildWorkflowValidator.js.map +1 -0
  37. package/dist_commonjs/cli/cli.cjs +33 -0
  38. package/dist_commonjs/cli/cli.d.ts +1 -0
  39. package/dist_commonjs/cli/cli.js.map +1 -0
  40. package/dist_commonjs/errors/BuildConfigError.cjs +8 -0
  41. package/dist_commonjs/errors/BuildConfigError.d.ts +3 -0
  42. package/dist_commonjs/errors/BuildConfigError.js.map +1 -0
  43. package/dist_commonjs/errors/BuildInternalError.cjs +7 -0
  44. package/dist_commonjs/errors/BuildInternalError.d.ts +2 -0
  45. package/dist_commonjs/errors/BuildInternalError.js.map +1 -0
  46. package/dist_commonjs/errors/BuildStepRuntimeError.cjs +8 -0
  47. package/dist_commonjs/errors/BuildStepRuntimeError.d.ts +3 -0
  48. package/dist_commonjs/errors/BuildStepRuntimeError.js.map +1 -0
  49. package/dist_commonjs/errors/BuildWorkflowError.cjs +13 -0
  50. package/dist_commonjs/errors/BuildWorkflowError.d.ts +10 -0
  51. package/dist_commonjs/errors/BuildWorkflowError.js.map +1 -0
  52. package/dist_commonjs/errors/UserError.cjs +14 -0
  53. package/dist_commonjs/errors/UserError.d.ts +9 -0
  54. package/dist_commonjs/errors/UserError.js.map +1 -0
  55. package/dist_commonjs/index.cjs +14 -0
  56. package/dist_commonjs/index.d.ts +5 -0
  57. package/dist_commonjs/index.js.map +1 -0
  58. package/dist_commonjs/utils/expodash/duplicates.cjs +18 -0
  59. package/dist_commonjs/utils/expodash/duplicates.d.ts +1 -0
  60. package/dist_commonjs/utils/expodash/duplicates.js.map +1 -0
  61. package/dist_commonjs/utils/expodash/uniq.cjs +9 -0
  62. package/dist_commonjs/utils/expodash/uniq.d.ts +1 -0
  63. package/dist_commonjs/utils/expodash/uniq.js.map +1 -0
  64. package/dist_commonjs/utils/nullthrows.cjs +11 -0
  65. package/dist_commonjs/utils/nullthrows.d.ts +1 -0
  66. package/dist_commonjs/utils/nullthrows.js.map +1 -0
  67. package/dist_commonjs/utils/shell/bin.cjs +11 -0
  68. package/dist_commonjs/utils/shell/bin.d.ts +1 -0
  69. package/dist_commonjs/utils/shell/bin.js.map +1 -0
  70. package/dist_commonjs/utils/shell/command.cjs +36 -0
  71. package/dist_commonjs/utils/shell/command.d.ts +6 -0
  72. package/dist_commonjs/utils/shell/command.js.map +1 -0
  73. package/dist_commonjs/utils/shell/spawn.cjs +25 -0
  74. package/dist_commonjs/utils/shell/spawn.d.ts +9 -0
  75. package/dist_commonjs/utils/shell/spawn.js.map +1 -0
  76. package/dist_commonjs/utils/template.cjs +47 -0
  77. package/dist_commonjs/utils/template.d.ts +11 -0
  78. package/dist_commonjs/utils/template.js.map +1 -0
  79. package/dist_esm/BuildConfig.d.ts +52 -0
  80. package/dist_esm/BuildConfig.js +101 -0
  81. package/dist_esm/BuildConfig.js.map +1 -0
  82. package/dist_esm/BuildConfigParser.d.ts +24 -0
  83. package/dist_esm/BuildConfigParser.js +170 -0
  84. package/dist_esm/BuildConfigParser.js.map +1 -0
  85. package/dist_esm/BuildFunction.d.ts +37 -0
  86. package/dist_esm/BuildFunction.js +44 -0
  87. package/dist_esm/BuildFunction.js.map +1 -0
  88. package/dist_esm/BuildPlatform.d.ts +4 -0
  89. package/dist_esm/BuildPlatform.js +6 -0
  90. package/dist_esm/BuildPlatform.js.map +1 -0
  91. package/dist_esm/BuildStep.d.ts +56 -0
  92. package/dist_esm/BuildStep.js +192 -0
  93. package/dist_esm/BuildStep.js.map +1 -0
  94. package/dist_esm/BuildStepContext.d.ts +17 -0
  95. package/dist_esm/BuildStepContext.js +28 -0
  96. package/dist_esm/BuildStepContext.js.map +1 -0
  97. package/dist_esm/BuildStepEnv.d.ts +1 -0
  98. package/dist_esm/BuildStepEnv.js +2 -0
  99. package/dist_esm/BuildStepEnv.js.map +1 -0
  100. package/dist_esm/BuildStepInput.d.ts +25 -0
  101. package/dist_esm/BuildStepInput.js +44 -0
  102. package/dist_esm/BuildStepInput.js.map +1 -0
  103. package/dist_esm/BuildStepOutput.d.ts +22 -0
  104. package/dist_esm/BuildStepOutput.js +37 -0
  105. package/dist_esm/BuildStepOutput.js.map +1 -0
  106. package/dist_esm/BuildTemporaryFiles.d.ts +4 -0
  107. package/dist_esm/BuildTemporaryFiles.js +33 -0
  108. package/dist_esm/BuildTemporaryFiles.js.map +1 -0
  109. package/dist_esm/BuildWorkflow.d.ts +14 -0
  110. package/dist_esm/BuildWorkflow.js +15 -0
  111. package/dist_esm/BuildWorkflow.js.map +1 -0
  112. package/dist_esm/BuildWorkflowValidator.d.ts +8 -0
  113. package/dist_esm/BuildWorkflowValidator.js +63 -0
  114. package/dist_esm/BuildWorkflowValidator.js.map +1 -0
  115. package/dist_esm/cli/cli.d.ts +1 -0
  116. package/dist_esm/cli/cli.js +28 -0
  117. package/dist_esm/cli/cli.js.map +1 -0
  118. package/dist_esm/errors/BuildConfigError.d.ts +3 -0
  119. package/dist_esm/errors/BuildConfigError.js +4 -0
  120. package/dist_esm/errors/BuildConfigError.js.map +1 -0
  121. package/dist_esm/errors/BuildInternalError.d.ts +2 -0
  122. package/dist_esm/errors/BuildInternalError.js +3 -0
  123. package/dist_esm/errors/BuildInternalError.js.map +1 -0
  124. package/dist_esm/errors/BuildStepRuntimeError.d.ts +3 -0
  125. package/dist_esm/errors/BuildStepRuntimeError.js +4 -0
  126. package/dist_esm/errors/BuildStepRuntimeError.js.map +1 -0
  127. package/dist_esm/errors/BuildWorkflowError.d.ts +10 -0
  128. package/dist_esm/errors/BuildWorkflowError.js +9 -0
  129. package/dist_esm/errors/BuildWorkflowError.js.map +1 -0
  130. package/dist_esm/errors/UserError.d.ts +9 -0
  131. package/dist_esm/errors/UserError.js +10 -0
  132. package/dist_esm/errors/UserError.js.map +1 -0
  133. package/dist_esm/index.d.ts +5 -0
  134. package/dist_esm/index.js +6 -0
  135. package/dist_esm/index.js.map +1 -0
  136. package/dist_esm/utils/expodash/duplicates.d.ts +1 -0
  137. package/dist_esm/utils/expodash/duplicates.js +14 -0
  138. package/dist_esm/utils/expodash/duplicates.js.map +1 -0
  139. package/dist_esm/utils/expodash/uniq.d.ts +1 -0
  140. package/dist_esm/utils/expodash/uniq.js +5 -0
  141. package/dist_esm/utils/expodash/uniq.js.map +1 -0
  142. package/dist_esm/utils/nullthrows.d.ts +1 -0
  143. package/dist_esm/utils/nullthrows.js +7 -0
  144. package/dist_esm/utils/nullthrows.js.map +1 -0
  145. package/dist_esm/utils/shell/bin.d.ts +1 -0
  146. package/dist_esm/utils/shell/bin.js +5 -0
  147. package/dist_esm/utils/shell/bin.js.map +1 -0
  148. package/dist_esm/utils/shell/command.d.ts +6 -0
  149. package/dist_esm/utils/shell/command.js +28 -0
  150. package/dist_esm/utils/shell/command.js.map +1 -0
  151. package/dist_esm/utils/shell/spawn.d.ts +9 -0
  152. package/dist_esm/utils/shell/spawn.js +18 -0
  153. package/dist_esm/utils/shell/spawn.js.map +1 -0
  154. package/dist_esm/utils/template.d.ts +11 -0
  155. package/dist_esm/utils/template.js +40 -0
  156. package/dist_esm/utils/template.js.map +1 -0
  157. package/package.json +3 -1
  158. package/bin/upload-artifact +0 -12
@@ -0,0 +1,101 @@
1
+ import assert from 'assert';
2
+ import Joi from 'joi';
3
+ import { BuildConfigError } from './errors/BuildConfigError.js';
4
+ import { BuildPlatform } from './BuildPlatform.js';
5
+ const BuildInputOutputParametersSchema = Joi.array().items(Joi.alternatives().try(Joi.string().required(), Joi.object({
6
+ name: Joi.string().required(),
7
+ required: Joi.boolean(),
8
+ }).required()));
9
+ const BuildFunctionCallSchema = Joi.object({
10
+ id: Joi.string(),
11
+ inputs: Joi.object().pattern(Joi.string(), Joi.string()),
12
+ name: Joi.string(),
13
+ workingDirectory: Joi.string(),
14
+ shell: Joi.string(),
15
+ }).rename('working_directory', 'workingDirectory');
16
+ const BuildStepConfigSchema = Joi.any()
17
+ .when(Joi.object().pattern(Joi.string().disallow('run').required(), Joi.object().unknown().required()), {
18
+ then: Joi.object().pattern(Joi.string().disallow('run').min(1).required(), BuildFunctionCallSchema.required(), { matches: Joi.array().length(1) }),
19
+ })
20
+ .when(Joi.object({ run: Joi.object().unknown().required() }), {
21
+ then: Joi.object({
22
+ run: BuildFunctionCallSchema.keys({
23
+ outputs: BuildInputOutputParametersSchema,
24
+ command: Joi.string().required(),
25
+ }),
26
+ }),
27
+ })
28
+ .when(Joi.object({ run: Joi.string().required() }), {
29
+ then: Joi.object({
30
+ run: Joi.string().min(1).required(),
31
+ }),
32
+ })
33
+ .when(Joi.string(), {
34
+ then: Joi.string().min(1),
35
+ });
36
+ const BuildFunctionConfigSchema = Joi.object({
37
+ name: Joi.string(),
38
+ platforms: Joi.string().allow(...Object.values(BuildPlatform)),
39
+ inputs: BuildInputOutputParametersSchema,
40
+ outputs: BuildInputOutputParametersSchema,
41
+ command: Joi.string().required(),
42
+ shell: Joi.string(),
43
+ });
44
+ export const BuildConfigSchema = Joi.object({
45
+ build: Joi.object({
46
+ name: Joi.string(),
47
+ steps: Joi.array().items(BuildStepConfigSchema.required()).required(),
48
+ }).required(),
49
+ functions: Joi.object().pattern(Joi.string()
50
+ .pattern(/^[\w-]+$/, 'function names')
51
+ .min(1)
52
+ .required()
53
+ .disallow('run'), BuildFunctionConfigSchema.required()),
54
+ }).required();
55
+ export function isBuildStepCommandRun(step) {
56
+ return typeof step === 'object' && typeof step.run === 'object';
57
+ }
58
+ export function isBuildStepBareCommandRun(step) {
59
+ return typeof step === 'object' && typeof step.run === 'string';
60
+ }
61
+ export function isBuildStepFunctionCall(step) {
62
+ return typeof step === 'object' && !('run' in step);
63
+ }
64
+ export function isBuildStepBareFunctionCall(step) {
65
+ return typeof step === 'string';
66
+ }
67
+ export function validateBuildConfig(rawConfig, externalFunctionIds) {
68
+ const { error, value: buildConfig } = BuildConfigSchema.validate(rawConfig, {
69
+ allowUnknown: false,
70
+ abortEarly: false,
71
+ });
72
+ if (error) {
73
+ const errorMessage = error.details.map(({ message }) => message).join(', ');
74
+ throw new BuildConfigError(errorMessage, { cause: error });
75
+ }
76
+ validateAllFunctionsExist(buildConfig, externalFunctionIds);
77
+ return buildConfig;
78
+ }
79
+ function validateAllFunctionsExist(config, externalFunctionIds) {
80
+ const calledFunctionsSet = new Set();
81
+ for (const step of config.build.steps) {
82
+ if (typeof step === 'string') {
83
+ calledFunctionsSet.add(step);
84
+ }
85
+ else if (!('run' in step)) {
86
+ const keys = Object.keys(step);
87
+ assert(keys.length === 1, 'There must be at most one function call in the step (enforced by joi).');
88
+ calledFunctionsSet.add(keys[0]);
89
+ }
90
+ }
91
+ const calledFunctions = Array.from(calledFunctionsSet);
92
+ const externalFunctionIdsSet = new Set(externalFunctionIds);
93
+ const nonExistentFunctions = calledFunctions.filter((calledFunction) => {
94
+ var _a;
95
+ return (!(calledFunction in ((_a = config.functions) !== null && _a !== void 0 ? _a : {})) && !externalFunctionIdsSet.has(calledFunction));
96
+ });
97
+ if (nonExistentFunctions.length > 0) {
98
+ throw new BuildConfigError(`Calling non-existent functions: ${nonExistentFunctions.map((f) => `"${f}"`).join(', ')}.`);
99
+ }
100
+ }
101
+ //# sourceMappingURL=BuildConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA2DnD,MAAM,gCAAgC,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CACxD,GAAG,CAAC,YAAY,EAAE,CAAC,GAAG,CACpB,G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H,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,MAAM,IAAI,gBAAgB,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,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,170 @@
1
+ import assert from 'assert';
2
+ import fs from 'fs/promises';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ import YAML from 'yaml';
5
+ import { isBuildStepBareCommandRun, isBuildStepBareFunctionCall, isBuildStepCommandRun, validateBuildConfig, } from './BuildConfig.js';
6
+ import { BuildFunction } from './BuildFunction.js';
7
+ import { BuildStep } from './BuildStep.js';
8
+ import { BuildStepInput } from './BuildStepInput.js';
9
+ import { BuildStepOutput } from './BuildStepOutput.js';
10
+ import { BuildWorkflow } from './BuildWorkflow.js';
11
+ import { BuildWorkflowValidator } from './BuildWorkflowValidator.js';
12
+ import { BuildStepRuntimeError } from './errors/BuildStepRuntimeError.js';
13
+ import { duplicates } from './utils/expodash/duplicates.js';
14
+ import { uniq } from './utils/expodash/uniq.js';
15
+ export class BuildConfigParser {
16
+ constructor(ctx, { configPath, externalFunctions }) {
17
+ this.ctx = ctx;
18
+ this.validateExternalFunctions(externalFunctions);
19
+ this.configPath = configPath;
20
+ this.externalFunctions = externalFunctions;
21
+ }
22
+ async parseAsync() {
23
+ const rawConfig = await this.readRawConfigAsync();
24
+ const config = validateBuildConfig(rawConfig, this.getUniqueExternalFunctionIds());
25
+ const configBuildFunctions = this.createBuildFunctionsFromConfig(config.functions);
26
+ const buildFunctions = this.mergeBuildFunctionsWithExternal(configBuildFunctions, this.externalFunctions);
27
+ const buildSteps = config.build.steps.map((stepConfig) => this.createBuildStepFromConfig(stepConfig, buildFunctions));
28
+ const workflow = new BuildWorkflow(this.ctx, { buildSteps, buildFunctions });
29
+ new BuildWorkflowValidator(workflow).validate();
30
+ return workflow;
31
+ }
32
+ async readRawConfigAsync() {
33
+ const contents = await fs.readFile(this.configPath, 'utf-8');
34
+ return YAML.parse(contents);
35
+ }
36
+ createBuildStepFromConfig(buildStepConfig, buildFunctions) {
37
+ if (isBuildStepCommandRun(buildStepConfig)) {
38
+ const { id, inputs: inputsConfig, outputs: outputsConfig, name, workingDirectory, shell, command, } = buildStepConfig.run;
39
+ const stepId = id !== null && id !== void 0 ? id : uuidv4();
40
+ const inputs = inputsConfig &&
41
+ this.createBuildStepInputsFromBuildStepInputsDefinition(inputsConfig, stepId);
42
+ const outputs = outputsConfig && this.createBuildStepOutputsFromDefinition(outputsConfig, stepId);
43
+ return new BuildStep(this.ctx, {
44
+ id: stepId,
45
+ inputs,
46
+ outputs,
47
+ name,
48
+ workingDirectory,
49
+ shell,
50
+ command,
51
+ });
52
+ }
53
+ else if (isBuildStepBareCommandRun(buildStepConfig)) {
54
+ const command = buildStepConfig.run;
55
+ return new BuildStep(this.ctx, {
56
+ id: uuidv4(),
57
+ command,
58
+ });
59
+ }
60
+ else if (isBuildStepBareFunctionCall(buildStepConfig)) {
61
+ const functionId = buildStepConfig;
62
+ const buildFunction = buildFunctions[functionId];
63
+ return buildFunction.createBuildStepFromFunctionCall(this.ctx);
64
+ }
65
+ else {
66
+ const keys = Object.keys(buildStepConfig);
67
+ assert(keys.length === 1, 'There must be at most one function call in the step (enforced by joi).');
68
+ const functionId = keys[0];
69
+ const buildFunctionCallConfig = buildStepConfig[functionId];
70
+ const buildFunction = buildFunctions[functionId];
71
+ return buildFunction.createBuildStepFromFunctionCall(this.ctx, {
72
+ id: buildFunctionCallConfig.id,
73
+ name: buildFunctionCallConfig.name,
74
+ callInputs: buildFunctionCallConfig.inputs,
75
+ workingDirectory: buildFunctionCallConfig.workingDirectory,
76
+ shell: buildFunctionCallConfig.shell,
77
+ });
78
+ }
79
+ }
80
+ createBuildFunctionsFromConfig(buildFunctionsConfig) {
81
+ if (!buildFunctionsConfig) {
82
+ return {};
83
+ }
84
+ const result = {};
85
+ for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {
86
+ const buildFunction = this.createBuildFunctionFromConfig({
87
+ id: functionId,
88
+ ...buildFunctionConfig,
89
+ });
90
+ result[buildFunction.getFullId()] = buildFunction;
91
+ }
92
+ return result;
93
+ }
94
+ createBuildFunctionFromConfig({ id, name, inputs: inputsConfig, outputs: outputsConfig, shell, command, }) {
95
+ const inputProviders = inputsConfig && this.createBuildStepInputProvidersFromBuildFunctionInputs(inputsConfig);
96
+ const outputProviders = outputsConfig && this.createBuildStepOutputProvidersFromBuildFunctionOutputs(outputsConfig);
97
+ return new BuildFunction({ id, name, inputProviders, outputProviders, shell, command });
98
+ }
99
+ createBuildStepInputsFromBuildStepInputsDefinition(buildStepInputs, stepId) {
100
+ return Object.entries(buildStepInputs).map(([key, value]) => new BuildStepInput(this.ctx, {
101
+ id: key,
102
+ stepId,
103
+ defaultValue: value,
104
+ required: true,
105
+ }));
106
+ }
107
+ createBuildStepInputProvidersFromBuildFunctionInputs(buildFunctionInputs) {
108
+ return buildFunctionInputs.map((entry) => {
109
+ var _a;
110
+ return typeof entry === 'string'
111
+ ? BuildStepInput.createProvider({ id: entry })
112
+ : BuildStepInput.createProvider({ id: entry.name, required: (_a = entry.required) !== null && _a !== void 0 ? _a : true });
113
+ });
114
+ }
115
+ createBuildStepOutputsFromDefinition(buildStepOutputs, stepId) {
116
+ return buildStepOutputs.map((entry) => {
117
+ var _a;
118
+ return typeof entry === 'string'
119
+ ? new BuildStepOutput(this.ctx, { id: entry, stepId, required: true })
120
+ : new BuildStepOutput(this.ctx, {
121
+ id: entry.name,
122
+ stepId,
123
+ required: (_a = entry.required) !== null && _a !== void 0 ? _a : true,
124
+ });
125
+ });
126
+ }
127
+ createBuildStepOutputProvidersFromBuildFunctionOutputs(buildFunctionOutputs) {
128
+ return buildFunctionOutputs.map((entry) => {
129
+ var _a;
130
+ return typeof entry === 'string'
131
+ ? BuildStepOutput.createProvider({ id: entry, required: true })
132
+ : BuildStepOutput.createProvider({ id: entry.name, required: (_a = entry.required) !== null && _a !== void 0 ? _a : true });
133
+ });
134
+ }
135
+ mergeBuildFunctionsWithExternal(configFunctions, externalFunctions) {
136
+ const result = { ...configFunctions };
137
+ if (externalFunctions === undefined) {
138
+ return result;
139
+ }
140
+ for (const buildFunction of externalFunctions) {
141
+ // functions defined in config shadow the external ones
142
+ const fullId = buildFunction.getFullId();
143
+ if (!(fullId in result)) {
144
+ result[fullId] = buildFunction;
145
+ }
146
+ }
147
+ return result;
148
+ }
149
+ validateExternalFunctions(externalFunctions) {
150
+ if (externalFunctions === undefined) {
151
+ return;
152
+ }
153
+ const externalFunctionIds = externalFunctions.map((f) => f.getFullId());
154
+ const duplicatedExternalFunctionIds = duplicates(externalFunctionIds);
155
+ if (duplicatedExternalFunctionIds.length === 0) {
156
+ return;
157
+ }
158
+ throw new BuildStepRuntimeError(`Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds
159
+ .map((id) => `"${id}"`)
160
+ .join(', ')}`);
161
+ }
162
+ getUniqueExternalFunctionIds() {
163
+ if (this.externalFunctions === undefined) {
164
+ return [];
165
+ }
166
+ const ids = this.externalFunctions.map((f) => f.getFullId());
167
+ return uniq(ids);
168
+ }
169
+ }
170
+ //# sourceMappingURL=BuildConfigParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAE7B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAQL,yBAAyB,EACzB,2BAA2B,EAC3B,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAqB,MAAM,oBAAoB,CAA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AC,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE;gBACvB,MAAM,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC;aAChC;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,yBAAyB,CAAC,iBAAmC;QACnE,IAAI,iBAAiB,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,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACtE,IAAI,6BAA6B,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,OAAO;SACR;QACD,MAAM,IAAI,qBAAqB,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,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","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,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
+ }
@@ -0,0 +1,44 @@
1
+ import assert from 'assert';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { BuildStep } from './BuildStep.js';
4
+ export class BuildFunction {
5
+ constructor({ namespace, id, name, platforms, inputProviders, outputProviders, command, fn, shell, }) {
6
+ assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
7
+ assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
8
+ this.namespace = namespace;
9
+ this.id = id;
10
+ this.name = name;
11
+ this.platforms = platforms;
12
+ this.inputProviders = inputProviders;
13
+ this.outputProviders = outputProviders;
14
+ this.command = command;
15
+ this.fn = fn;
16
+ this.shell = shell;
17
+ }
18
+ getFullId() {
19
+ return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;
20
+ }
21
+ createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, } = {}) {
22
+ var _a, _b;
23
+ const buildStepId = id !== null && id !== void 0 ? id : uuidv4();
24
+ const inputs = (_a = this.inputProviders) === null || _a === void 0 ? void 0 : _a.map((inputProvider) => {
25
+ const input = inputProvider(ctx, buildStepId);
26
+ if (input.id in callInputs) {
27
+ input.set(callInputs[input.id]);
28
+ }
29
+ return input;
30
+ });
31
+ const outputs = (_b = this.outputProviders) === null || _b === void 0 ? void 0 : _b.map((outputProvider) => outputProvider(ctx, buildStepId));
32
+ return new BuildStep(ctx, {
33
+ id: buildStepId,
34
+ name: name !== null && name !== void 0 ? name : this.name,
35
+ command: this.command,
36
+ fn: this.fn,
37
+ workingDirectory,
38
+ inputs,
39
+ outputs,
40
+ shell,
41
+ });
42
+ }
43
+ }
44
+ //# sourceMappingURL=BuildFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BuildFunction.js","sourceRoot":"","sources":["../src/BuildFunction.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAQ9D,M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E,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,SAAS,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","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,4 @@
1
+ export declare enum BuildPlatform {
2
+ DARWIN = "darwin",
3
+ LINUX = "linux"
4
+ }
@@ -0,0 +1,6 @@
1
+ export var BuildPlatform;
2
+ (function (BuildPlatform) {
3
+ BuildPlatform["DARWIN"] = "darwin";
4
+ BuildPlatform["LINUX"] = "linux";
5
+ })(BuildPlatform || (BuildPlatform = {}));
6
+ //# sourceMappingURL=BuildPlatform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BuildPlatform.js","sourceRoot":"","sources":["../src/BuildPlatform.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,gCAAe,CAAA;AACjB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB","sourcesContent":["export enum BuildPlatform {\n DARWIN = 'darwin',\n LINUX = 'linux',\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import { BuildStepContext } from './BuildStepContext.js';
2
+ import { BuildStepInput, BuildStepInputById } from './BuildStepInput.js';
3
+ import { BuildStepOutput, BuildStepOutputById } from './BuildStepOutput.js';
4
+ import { BuildStepEnv } from './BuildStepEnv.js';
5
+ export declare enum BuildStepStatus {
6
+ NEW = "new",
7
+ IN_PROGRESS = "in-progress",
8
+ CANCELED = "canceled",
9
+ FAIL = "fail",
10
+ WARNING = "warning",
11
+ SUCCESS = "success"
12
+ }
13
+ export declare enum BuildStepLogMarker {
14
+ START_STEP = "start-step",
15
+ END_STEP = "end-step"
16
+ }
17
+ export type BuildStepFunction = (ctx: BuildStepContext, { inputs, outputs, env, }: {
18
+ inputs: BuildStepInputById;
19
+ outputs: BuildStepOutputById;
20
+ env: BuildStepEnv;
21
+ }) => unknown;
22
+ export declare class BuildStep {
23
+ readonly id: string;
24
+ readonly name?: string;
25
+ readonly displayName?: string;
26
+ readonly inputs?: BuildStepInput[];
27
+ readonly outputs?: BuildStepOutput[];
28
+ readonly command?: string;
29
+ readonly fn?: BuildStepFunction;
30
+ readonly shell: string;
31
+ readonly ctx: BuildStepContext;
32
+ status: BuildStepStatus;
33
+ private readonly internalId;
34
+ private readonly inputById;
35
+ private readonly outputById;
36
+ private executed;
37
+ constructor(ctx: BuildStepContext, { id, name, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, }: {
38
+ id: string;
39
+ name?: string;
40
+ inputs?: BuildStepInput[];
41
+ outputs?: BuildStepOutput[];
42
+ command?: string;
43
+ fn?: BuildStepFunction;
44
+ workingDirectory?: string;
45
+ shell?: string;
46
+ });
47
+ executeAsync(env?: BuildStepEnv): Promise<void>;
48
+ hasOutputParameter(name: string): boolean;
49
+ getOutputValueByName(name: string): string | undefined;
50
+ private executeCommandAsync;
51
+ private exectuteFnAsync;
52
+ private interpolateInputsInCommand;
53
+ private collectAndValidateOutputsAsync;
54
+ private getScriptEnv;
55
+ private getStepDisplayName;
56
+ }