@@ -17,11 +17,19 @@ FIND_SRC_FILES_ARGS := -name '*.purs' -type f
17
17
NODE_MODULES := $(ROOT_DIR ) /node_modules/.stamp
18
18
PACKAGE_JSON := $(ROOT_DIR ) /package.json
19
19
PSA_ARGS ?= --censor-lib --stash=$(BUILD_DIR ) /.psa_stash --is-lib=.spago --strict --censor-codes=UserDefinedWarning
20
+ PURS_TIDY ?= purs-tidy
20
21
SRC_FILES := $(shell find $(SRC_DIR ) $(FIND_SRC_FILES_ARGS ) )
21
22
TEST_FILES := $(shell find $(TEST_DIR ) $(FIND_SRC_FILES_ARGS ) )
22
23
UI_GUIDE_FILES := $(shell find $(UI_GUIDE_DIR ) $(FIND_SRC_FILES_ARGS ) )
23
24
YARN_LOCK := $(ROOT_DIR ) /yarn.lock
24
25
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
+
25
33
# Colors for printing
26
34
CYAN := \033[0;36m
27
35
RESET := \033[0;0m
@@ -72,6 +80,14 @@ $(DIST_DIR)/bundled.js: $(OUTPUT_DIR)/Main/index.js
72
80
$(DIST_DIR ) /index.js : $(OUTPUT_DIR ) /Main/index.js
73
81
$(NPX ) browserify dist/main.js --outfile $@
74
82
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
+
75
91
$(NODE_MODULES ) : $(PACKAGE_JSON ) $(YARN_LOCK )
76
92
$(NPX ) yarn install
77
93
touch $@
@@ -88,6 +104,18 @@ build: $(BUILD_DEPS) ## Build everything — all the CSS, and the UI Guide — i
88
104
.PHONY : build-ui
89
105
build-ui : $(DIST_DIR ) /index.js # # Build the UI Guide, installing any missing dependencies along the way
90
106
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
+
91
119
.PHONY : clean
92
120
clean : $(CLEAN_DEPS ) # # Remove all dependencies and build artifacts, starting with a clean slate
93
121
rm -fr \
@@ -98,6 +126,18 @@ clean: $(CLEAN_DEPS) ## Remove all dependencies and build artifacts, starting wi
98
126
$(ROOT_DIR ) /.spago \
99
127
$(ROOT_DIR ) /node_modules
100
128
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
+
101
141
.PHONY : help
102
142
help : $(BUILD_DIR ) /help # # Display this help message
103
143
@awk ' BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-30s$(RESET) %s\n", $$1, $$2}' $<
0 commit comments