All files / iac/lib/stacks customStack.ts

88.88% Statements 8/9
100% Branches 0/0
80% Functions 4/5
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                              1x   1x   1x               1x       1x       1x           2x         2x    
import { Stack, type StackProps, Tags } from "aws-cdk-lib";
import type { Construct } from "constructs";
import type { AppEnvironment } from "../core/types";
import { formatRepoNameForCloudFormation } from "./utils";
 
export interface DomainConfig {
	subdomain?: string;
	domainName: string;
	hostedZoneId: string;
	certificateId: string;
}
 
export interface CustomStackProps extends StackProps {
	githubRepo: string;
	envName: AppEnvironment;
	name: string;
	stackName: string;
}
 
export class CustomStack extends Stack {
	props: CustomStackProps;
 
	constructor(scope: Construct, props: CustomStackProps) {
		super(scope, getStackName(props), props);
 
		this.props = props;
 
		this.addProjectTags();
	}
 
	getStackId(): string {
		return getStackName(this.props);
	}
 
	private addProjectTags(): void {
		Tags.of(this).add("StackId", getStackName(this.props), {
			priority: 300,
		});
 
		Tags.of(this).add("Environment", this.props.envName.valueOf(), {
			priority: 300,
		});
 
		Tags.of(this).add("Project", this.props.githubRepo, {
			priority: 300,
		});
	}
 
	public getCloudFormationRepoName(): string {
		return formatRepoNameForCloudFormation(this.props.githubRepo);
	}
}
 
function getStackName(props: CustomStackProps): string {
	return `macalbert-${formatRepoNameForCloudFormation(props.githubRepo)}-${props.name}-${props.envName}-stack`.toLowerCase();
}