mirror of
https://github.com/expo/eas-cli.git
synced 2026-11-15 17:31:46 -10:00
* [eas-build-job] Add hook anchors registry and step stamp fields Signed-off-by: Ash Wu <[email protected]> * [steps] Add hook insertion, after-hook gate, and source function retention Signed-off-by: Ash Wu <[email protected]> * [build-tools] Pass job hooks into the steps parser Signed-off-by: Ash Wu <[email protected]> * address comments Signed-off-by: Ash Wu <[email protected]> --------- Signed-off-by: Ash Wu <[email protected]>
99 lines
3.4 KiB
TypeScript
99 lines
3.4 KiB
TypeScript
import { BuildFunction, BuildFunctionById } from './BuildFunction';
|
|
import { BuildFunctionGroup } from './BuildFunctionGroup';
|
|
import { BuildStep } from './BuildStep';
|
|
import { BuildStepGlobalContext } from './BuildStepContext';
|
|
import { BuildWorkflow } from './BuildWorkflow';
|
|
import { BuildWorkflowValidator } from './BuildWorkflowValidator';
|
|
import { BuildConfigError } from './errors';
|
|
import { AnchorHooks } from './hooks';
|
|
import { duplicates } from './utils/expodash/duplicates';
|
|
import { uniq } from './utils/expodash/uniq';
|
|
|
|
export abstract class AbstractConfigParser {
|
|
protected readonly externalFunctions?: BuildFunction[];
|
|
protected readonly externalFunctionGroups?: BuildFunctionGroup[];
|
|
|
|
constructor(
|
|
protected readonly ctx: BuildStepGlobalContext,
|
|
{
|
|
externalFunctions,
|
|
externalFunctionGroups,
|
|
}: {
|
|
externalFunctions?: BuildFunction[];
|
|
externalFunctionGroups?: BuildFunctionGroup[];
|
|
}
|
|
) {
|
|
this.validateExternalFunctions(externalFunctions);
|
|
this.validateExternalFunctionGroups(externalFunctionGroups);
|
|
|
|
this.externalFunctions = externalFunctions;
|
|
this.externalFunctionGroups = externalFunctionGroups;
|
|
}
|
|
|
|
public async parseAsync(): Promise<BuildWorkflow> {
|
|
const { buildSteps, buildFunctionById, hooksByAnchorStep } =
|
|
await this.parseConfigToBuildStepsAndBuildFunctionByIdMappingAsync();
|
|
const workflow = new BuildWorkflow(this.ctx, {
|
|
buildSteps,
|
|
buildFunctions: buildFunctionById,
|
|
hooksByAnchorStep,
|
|
});
|
|
await new BuildWorkflowValidator(workflow).validateAsync();
|
|
return workflow;
|
|
}
|
|
|
|
protected abstract parseConfigToBuildStepsAndBuildFunctionByIdMappingAsync(): Promise<{
|
|
buildSteps: BuildStep[];
|
|
buildFunctionById: BuildFunctionById;
|
|
hooksByAnchorStep: ReadonlyMap<BuildStep, AnchorHooks>;
|
|
}>;
|
|
|
|
private validateExternalFunctions(externalFunctions?: BuildFunction[]): void {
|
|
if (externalFunctions === undefined) {
|
|
return;
|
|
}
|
|
const externalFunctionIds = externalFunctions.map(f => f.getFullId());
|
|
const duplicatedExternalFunctionIds = duplicates(externalFunctionIds);
|
|
if (duplicatedExternalFunctionIds.length === 0) {
|
|
return;
|
|
}
|
|
throw new BuildConfigError(
|
|
`Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds
|
|
.map(id => `"${id}"`)
|
|
.join(', ')}`
|
|
);
|
|
}
|
|
|
|
private validateExternalFunctionGroups(externalFunctionGroups?: BuildFunctionGroup[]): void {
|
|
if (externalFunctionGroups === undefined) {
|
|
return;
|
|
}
|
|
const externalFunctionGroupIds = externalFunctionGroups.map(f => f.getFullId());
|
|
const duplicatedExternalFunctionGroupIds = duplicates(externalFunctionGroupIds);
|
|
if (duplicatedExternalFunctionGroupIds.length === 0) {
|
|
return;
|
|
}
|
|
throw new BuildConfigError(
|
|
`Provided external function groups with duplicated IDs: ${duplicatedExternalFunctionGroupIds
|
|
.map(id => `"${id}"`)
|
|
.join(', ')}`
|
|
);
|
|
}
|
|
|
|
protected getExternalFunctionFullIds(): string[] {
|
|
if (this.externalFunctions === undefined) {
|
|
return [];
|
|
}
|
|
const ids = this.externalFunctions.map(f => f.getFullId());
|
|
return uniq(ids);
|
|
}
|
|
|
|
protected getExternalFunctionGroupFullIds(): string[] {
|
|
if (this.externalFunctionGroups === undefined) {
|
|
return [];
|
|
}
|
|
const ids = this.externalFunctionGroups.map(f => f.getFullId());
|
|
return uniq(ids);
|
|
}
|
|
}
|