44LAMBDA_DIR := lib/lambda-at-edge
55CF_DIR := lib/cloudfront-functions
66
7+ LAMBDA_FUNCTIONS := filter-function prerender-proxy geo-redirect response-handler
8+ SEED_VERSION ?= 1.0.0
9+ EDGE_ARTIFACTS_BUCKET ?= $(shell terraform output -raw edge_artifacts_bucket 2>/dev/null)
10+
711# #@ General
812
913.PHONY : help
@@ -96,6 +100,11 @@ build-response-handler: ## Build response-handler (Lambda@Edge)
96100build-uri-rewrite : # # Build uri-rewrite (CloudFront Function)
97101 cd $(CF_DIR ) && yarn workspace @krishanthisera/uri-rewrite build
98102
103+ .PHONY : build-uri-rewrite-committed
104+ build-uri-rewrite-committed : # # Rebuild + stage the committed uri-rewrite bundle (used by pre-commit)
105+ cd $(CF_DIR ) && yarn install --frozen-lockfile --silent && yarn workspace @krishanthisera/uri-rewrite build
106+ git add $(CF_DIR ) /packages/uri-rewrite/build/index.js
107+
99108# #@ Lint
100109
101110.PHONY : lint
@@ -109,12 +118,16 @@ lint-fix: ## Run linters and fix issues (Lambda@Edge)
109118# #@ Format
110119
111120.PHONY : format
112- format : # # Check code formatting (Lambda@Edge)
121+ format : # # Check code formatting (Lambda@Edge + Terraform/HCL )
113122 cd $(LAMBDA_DIR ) && yarn format:check
123+ @echo " Checking Terraform/HCL formatting..."
124+ terraform fmt -check -recursive
114125
115126.PHONY : format-fix
116- format-fix : # # Fix code formatting (Lambda@Edge)
127+ format-fix : # # Fix code formatting (Lambda@Edge + Terraform/HCL )
117128 cd $(LAMBDA_DIR ) && yarn format:fix
129+ @echo " Formatting Terraform/HCL..."
130+ terraform fmt -recursive
118131
119132# #@ Release
120133
@@ -152,6 +165,19 @@ tf-docs: ## Regenerate Terraform documentation (requires terraform-docs)
152165 terraform-docs markdown table --output-file README.md --output-mode inject .
153166 terraform-docs markdown table --output-file modules/edge-functions/README.md --output-mode inject modules/edge-functions
154167
168+ .PHONY : mirror-seed
169+ mirror-seed : build-lambda # # One-time: upload locally-built Lambda@Edge bundles to the artifacts bucket (EDGE_ARTIFACTS_BUCKET=... , SEED_VERSION=1.0.0)
170+ @test -n " $( EDGE_ARTIFACTS_BUCKET) " || { echo " EDGE_ARTIFACTS_BUCKET is empty - apply the bucket first or pass it explicitly" ; exit 1; }
171+ @for fn in $(LAMBDA_FUNCTIONS ) ; do \
172+ tmp=$$(mktemp -d ) ; \
173+ cp $(LAMBDA_DIR ) /packages/$$ fn/build/index.js $$ tmp/index.js; \
174+ ( cd $$ tmp && zip -q fn.zip index.js ); \
175+ echo " -> s3://$( EDGE_ARTIFACTS_BUCKET) /lambda-at-edge/$$ fn/$( SEED_VERSION) .zip" ; \
176+ aws s3 cp $$ tmp/fn.zip s3://$(EDGE_ARTIFACTS_BUCKET ) /lambda-at-edge/$$ fn/$(SEED_VERSION ) .zip; \
177+ rm -rf $$ tmp; \
178+ done
179+ @echo " ✓ seeded $( LAMBDA_FUNCTIONS) at $( SEED_VERSION) "
180+
155181# #@ Development
156182
157183.PHONY : dev
@@ -184,6 +210,8 @@ clean: ## Clean build artifacts
184210 cd $(LAMBDA_DIR ) && rm -rf packages/* /build function_archives .turbo packages/* /.turbo
185211 @echo " Cleaning CloudFront Functions build artifacts..."
186212 cd $(CF_DIR ) && rm -rf packages/* /build .turbo packages/* /.turbo
213+ @echo " Restoring the committed uri-rewrite bundle (consumed by Terraform)..."
214+ cd $(CF_DIR ) && yarn workspace @krishanthisera/uri-rewrite build
187215 @echo " ✓ Build artifacts cleaned"
188216
189217.PHONY : clean-all
0 commit comments