@@ -17,11 +17,19 @@ FIND_SRC_FILES_ARGS := -name '*.purs' -type f
1717NODE_MODULES := $(ROOT_DIR ) /node_modules/.stamp
1818PACKAGE_JSON := $(ROOT_DIR ) /package.json
1919PSA_ARGS ?= --censor-lib --stash=$(BUILD_DIR ) /.psa_stash --is-lib=.spago --strict --censor-codes=UserDefinedWarning
20+ PURS_TIDY ?= purs-tidy
2021SRC_FILES := $(shell find $(SRC_DIR ) $(FIND_SRC_FILES_ARGS ) )
2122TEST_FILES := $(shell find $(TEST_DIR ) $(FIND_SRC_FILES_ARGS ) )
2223UI_GUIDE_FILES := $(shell find $(UI_GUIDE_DIR ) $(FIND_SRC_FILES_ARGS ) )
2324YARN_LOCK := $(ROOT_DIR ) /yarn.lock
2425
26+ FORMAT_SRC_PURS_TIDY_STAMP := $(BUILD_DIR ) /.format-src-purs-tidy-stamp
27+ FORMAT_TEST_PURS_TIDY_STAMP := $(BUILD_DIR ) /.format-test-purs-tidy-stamp
28+
29+ FORMAT_DEPENDENCIES := \
30+ $(FORMAT_SRC_PURS_TIDY_STAMP ) \
31+ $(FORMAT_TEST_PURS_TIDY_STAMP )
32+
2533# Colors for printing
2634CYAN := \033[0;36m
2735RESET := \033[0;0m
@@ -72,6 +80,14 @@ $(DIST_DIR)/bundled.js: $(OUTPUT_DIR)/Main/index.js
7280$(DIST_DIR ) /index.js : $(OUTPUT_DIR ) /Main/index.js
7381 $(NPX ) browserify dist/main.js --outfile $@
7482
83+ $(FORMAT_SRC_PURS_TIDY_STAMP ) : $(SRC_FILES ) $(NODE_MODULES_STAMP ) | $(BUILD )
84+ $(PURS_TIDY ) $(PURS_TIDY_CMD ) $(SRC_DIR )
85+ @touch $@
86+
87+ $(FORMAT_TEST_PURS_TIDY_STAMP ) : $(TEST_FILES ) $(NODE_MODULES_STAMP ) | $(BUILD )
88+ $(PURS_TIDY ) $(PURS_TIDY_CMD ) $(TEST_DIR )
89+ @touch $@
90+
7591$(NODE_MODULES ) : $(PACKAGE_JSON ) $(YARN_LOCK )
7692 $(NPX ) yarn install
7793 touch $@
@@ -88,6 +104,18 @@ build: $(BUILD_DEPS) ## Build everything — all the CSS, and the UI Guide — i
88104.PHONY : build-ui
89105build-ui : $(DIST_DIR ) /index.js # # Build the UI Guide, installing any missing dependencies along the way
90106
107+ .PHONY : check-format
108+ check-format : PURS_TIDY_CMD=check
109+ check-format : $(FORMAT_DEPENDENCIES ) # # Validate formatting of all code
110+
111+ .PHONY : check-format-src
112+ check-format-src : PURS_TIDY_CMD=check
113+ check-format-src : $(FORMAT_SRC_PURS_TIDY_STAMP ) # # Validate formatting of the `src` directory
114+
115+ .PHONY : check-format-test
116+ check-format-test : PURS_TIDY_CMD=check
117+ check-format-test : $(FORMAT_TEST_PURS_TIDY_STAMP ) # # Validate formatting of the `test` directory
118+
91119.PHONY : clean
92120clean : $(CLEAN_DEPS ) # # Remove all dependencies and build artifacts, starting with a clean slate
93121 rm -fr \
@@ -98,6 +126,18 @@ clean: $(CLEAN_DEPS) ## Remove all dependencies and build artifacts, starting wi
98126 $(ROOT_DIR ) /.spago \
99127 $(ROOT_DIR ) /node_modules
100128
129+ .PHONY : format
130+ format : PURS_TIDY_CMD=format-in-place
131+ format : $(FORMAT_DEPENDENCIES ) # # Format all code
132+
133+ .PHONY : format-src
134+ format-src : PURS_TIDY_CMD=format-in-place
135+ format-src : $(FORMAT_SRC_PURS_TIDY_STAMP ) # # Format the `src` directory
136+
137+ .PHONY : format-test
138+ format-test : PURS_TIDY_CMD=format-in-place
139+ format-test : $(FORMAT_TEST_PURS_TIDY_STAMP ) # # Format the `test` directory
140+
101141.PHONY : help
102142help : $(BUILD_DIR ) /help # # Display this help message
103143 @awk ' BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-30s$(RESET) %s\n", $$1, $$2}' $<
0 commit comments