Skip to content

Commit 806c4f0

Browse files
committed
task: Make targets reuse JavaScript build
Ideally, the `makefile` serves as the de facto interface for project scripts. This avoids multiple sources of truth and simplifies project onboarding and documentation. Previously, rerunning various `make` targets resulted in rerunning the expensive and slow `make build` target. It's important to ensure the build output exists for many targets, but is often unnecessary to rerun the build when running targets multiple times--e.g., Swift test targets. This introduces a caching mechanism. The `make build` target skips running and relies upon the cache unless one of the following is true. - dist doesn't exist - REFRESH_JS_BUILD is set to true or 1 - build was invoked directly This enables quicker reruns while also ensure the build is always recreated when important to do so--e.g., direct invocations, CI runs, releases. See #253 (comment)
1 parent a8ad51c commit 806c4f0

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

.buildkite/pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ env:
66

77
steps:
88
- label: ':react: Build React App'
9-
command: make build REFRESH_L10N=1
9+
command: make build REFRESH_L10N=1 REFRESH_JS_BUILD=1
1010
plugins: &plugins
1111
- $CI_TOOLKIT_PLUGIN
1212
- $NVM_PLUGIN
@@ -21,7 +21,7 @@ steps:
2121

2222
- label: ':android: Publish Android Library'
2323
command: |
24-
make build REFRESH_L10N=1
24+
make build REFRESH_L10N=1 REFRESH_JS_BUILD=1
2525
echo "--- :android: Publishing Android Library"
2626
./android/gradlew -p ./android :gutenberg:prepareToPublishToS3 $(prepare_to_publish_to_s3_params) :gutenberg:publish
2727
agents:

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ make build
8282
# - ios/Sources/GutenbergKit/Gutenberg/
8383
# - android/Gutenberg/src/main/assets/
8484

85-
# By default, dependencies and translations are only installed if their directories don't exist
86-
# Force refresh of dependencies and translations
87-
make build REFRESH_DEPS=1 REFRESH_L10N=1
85+
# By default, the build is skipped if output directories already exist
86+
# Force refresh of dependencies, translations, and JS build
87+
make build REFRESH_DEPS=1 REFRESH_L10N=1 REFRESH_JS_BUILD=1
8888

8989
# Clean build artifacts
9090
make clean # Clean both dist and translations

Makefile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@ clean: ## Remove build artifacts and translation string files
6868

6969
.PHONY: build
7070
build: npm-dependencies prep-translations ## Build the project for all platforms (iOS, Android, web)
71-
@echo "--- :node: Building Gutenberg"
72-
73-
npm run build
74-
75-
# Copy build products into place
76-
@echo "--- :open_file_folder: Copying Build Products into place"
77-
rm -rf ./ios/Sources/GutenbergKit/Gutenberg/ ./android/Gutenberg/src/main/assets/
78-
cp -r ./dist/. ./ios/Sources/GutenbergKit/Gutenberg/
79-
cp -r ./dist/. ./android/Gutenberg/src/main/assets
71+
# Skip unless...
72+
# - dist doesn't exist
73+
# - REFRESH_JS_BUILD is set to true or 1
74+
# - build was invoked directly
75+
@if [ ! -d "dist" ] || [ "$(REFRESH_JS_BUILD)" = "true" ] || [ "$(REFRESH_JS_BUILD)" = "1" ] || echo "$(MAKECMDGOALS)" | grep -q "^build$$"; then \
76+
echo "--- :node: Building Gutenberg"; \
77+
npm run build; \
78+
echo "--- :open_file_folder: Copying Build Products into place"; \
79+
rm -rf ./ios/Sources/GutenbergKit/Gutenberg/ ./android/Gutenberg/src/main/assets/; \
80+
cp -r ./dist/. ./ios/Sources/GutenbergKit/Gutenberg/; \
81+
cp -r ./dist/. ./android/Gutenberg/src/main/assets; \
82+
else \
83+
echo "--- :white_check_mark: Skipping JS build (dist already exists). Use REFRESH_JS_BUILD=1 to force refresh."; \
84+
fi
8085

8186
.PHONY: build-swift-package
8287
build-swift-package: build ## Build the Swift package for iOS

bin/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ build_project() {
243243
return
244244
fi
245245

246-
make build REFRESH_DEPS=1 REFRESH_L10N=1 STRICT_L10N=1
246+
make build REFRESH_DEPS=1 REFRESH_L10N=1 REFRESH_JS_BUILD=1 STRICT_L10N=1
247247
print_success "Build completed successfully"
248248
}
249249

0 commit comments

Comments
 (0)