-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (97 loc) · 3.83 KB
/
Makefile
File metadata and controls
110 lines (97 loc) · 3.83 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
.DEFAULT_GOAL := test
EXERCISE ?= ""
EXERCISES = $(shell find ./exercises/practice -maxdepth 1 -mindepth 1 -type d | cut -s -d '/' -f4 | sort)
OUTDIR ?= "tmp"
# Define the files you want to ensure are synced across all exercises
FILES_TO_CHECK = package.json package-lock.json rescript.json .gitignore LICENSE .meta/testTemplate.js
# check all exercise files that need to be in sync
check-exercise-files:
@for exercise in $(EXERCISES); do \
echo "Checking exercise: $$exercise"; \
for file in $(FILES_TO_CHECK); do \
target="exercises/practice/$$exercise/$$file"; \
\
# Map the source template path \
if [ "$$file" = ".meta/testTemplate.js" ]; then \
source="./templates/testTemplate.js"; \
elif [ -f "./templates/$$file" ]; then \
source="./templates/$$file"; \
else \
source="./$$file"; \
fi; \
\
# 1. Check if the file exists \
if [ ! -f "$$target" ]; then \
echo "ERROR: Missing file $$file in $$exercise. Run make sync-exercise-files and commit the changes."; \
exit 1; \
fi; \
\
# 2. Check if the content matches (ignoring name/version) \
if [ "$$file" != ".meta/testTemplate.js" ]; then \
diff -q -I '"name":' -I '"version":' "$$source" "$$target" > /dev/null || { \
echo "ERROR: $$target does not match template $$source."; \
diff -u -I '"name":' -I '"version":' "$$source" "$$target" | head -n 20; \
exit 1; \
}; \
fi; \
done; \
done
@echo "All exercises contain all required files and are in sync."
add-test-template:
@cp templates/testTemplate.js exercises/practice/$(EXERCISE)/.meta/testTemplate.js
# copy all relevant files for a single exercise - test template, config etc.
copy-exercise-files:
@cp package.json exercises/practice/$(EXERCISE)/package.json
@cp package-lock.json exercises/practice/$(EXERCISE)/package-lock.json
@cp templates/rescript.json exercises/practice/$(EXERCISE)/rescript.json
@cp templates/.gitignore exercises/practice/$(EXERCISE)/.gitignore
@cp LICENSE exercises/practice/$(EXERCISE)/LICENSE
# sync all files for each exercise directory
sync-exercise-files:
@echo "Syncing exercise files..."
@for exercise in $(EXERCISES); do EXERCISE=$$exercise $(MAKE) -s copy-exercise-files || exit 1; done
# copy single exercise build artifacts for testing
copy-exercise:
if [ -f exercises/practice/$(EXERCISE)/src/*.res ]; then \
echo "Copying $(EXERCISE)"; \
cp exercises/practice/$(EXERCISE)/.meta/*.res $(OUTDIR)/src/; \
cp exercises/practice/$(EXERCISE)/.meta/*.resi $(OUTDIR)/src/; \
cp exercises/practice/$(EXERCISE)/tests/*.res $(OUTDIR)/tests/; \
fi
# copy build artifacts for testing
copy-all-exercises:
@echo "Copying exercises for testing..."
@mkdir -p $(OUTDIR)/src
@mkdir -p $(OUTDIR)/tests
@for exercise in $(EXERCISES); do EXERCISE=$$exercise $(MAKE) -s copy-exercise || exit 1; done
# Remove the OUTDIR
clean:
@echo "Cleaning tmp directory..."
@rm -rf $(OUTDIR)
# Format all ReScript files in the project
format:
@echo "Formatting ReScript files..."
@find . -name "node_modules" -prune -o -name "*.res" -print -o -name "*.resi" -print | xargs npx rescript format
# Generate tests for all exercises
generate-tests:
@echo "Generating tests for all exercises..."
@for exercise in $(EXERCISES); do \
if [ -f exercises/practice/$$exercise/.meta/testTemplate.js ]; then \
echo "-> Generating: $$exercise"; \
node exercises/practice/$$exercise/.meta/testTemplate.js || exit 1; \
else \
echo "-> Skipping: $$exercise (no generator found)"; \
fi \
done
@echo "All tests generated successfully."
# Generate test for exercise
generate-test:
ifeq ($(EXERCISE),"")
$(error EXERCISE variable is required. usage: make generate_test EXERCISE=hello-world)
endif
@node exercises/practice/$(EXERCISE)/.meta/generateTests.js
test:
$(MAKE) -s clean
$(MAKE) -s check-exercise-files
$(MAKE) -s copy-all-exercises
npm run ci