-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
221 lines (182 loc) · 7.59 KB
/
Makefile
File metadata and controls
221 lines (182 loc) · 7.59 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
SHELL = /bin/bash -u -e -o pipefail
export PATH := node_modules/.bin:$(PATH)
ELM_MAKE_FLAGS=--debug
build: ELM_MAKE_FLAGS=--optimize
build: css format compile schema test test-go test-json-compatibility
diff:
git diff -bw -- ':!dist'
compile: dist/tiny-form-fields.js dist/tiny-form-fields.esm.js dist/base-custom-field.js
dist/tiny-form-fields.js: src/Main.elm Makefile
elm make src/Main.elm $(ELM_MAKE_FLAGS) --output dist/tiny-form-fields.js
dist/tiny-form-fields.esm.js: src/Main.elm Makefile
npx elm-esm make src/Main.elm $(ELM_MAKE_FLAGS) --output=dist/tiny-form-fields.esm.js
cp src/base-custom-field.js dist/
dist/base-custom-field.js: src/base-custom-field.js
cp src/base-custom-field.js dist/
css: dist/tiny-form-fields.min.css
dist/tiny-form-fields.min.css: input.css tailwind.config.js index.html src/Main.elm
npx tailwindcss --input input.css --output dist/tiny-form-fields.min.css --minify
touch dist/tiny-form-fields.min.css
run: node_modules/.bin/elm-esm
npx elm-live src/Main.elm \
--start-page index.html \
--path-to-elm node_modules/.bin/elm-esm \
-- --output=dist/tiny-form-fields.dev.esm.js $(ELM_MAKE_FLAGS)
node_modules/.bin/elm-esm:
npm ci
run-ignore-error:
make run ELM_MAKE_FLAGS=--optimize || echo shutdown test server
run-background:
(make run > /dev/null 2>&1 &) && sleep 1 && echo "Dev server started in background"
test-all: test test-go test-json-compatibility test-playwright
test:
npx elm-test
TEST_MOCK_EXIT=0
test-mock:
exit $(TEST_MOCK_EXIT)
# Usage: make test-playwright [PLAYWRIGHT_FILE=e2e/mytest.spec.ts] [PLAYWRIGHT_ARGS=--reporter=line]
# If PLAYWRIGHT_FILE is specified, only that file will be tested
# Otherwise, all tests will be run
PLAYWRIGHT_ARGS ?= --reporter=line
test-playwright:
@if [ -z "$(PLAYWRIGHT_FILE)" ]; then \
npx playwright test $(PLAYWRIGHT_ARGS); \
else \
npx playwright test "$(PLAYWRIGHT_FILE)" $(PLAYWRIGHT_ARGS); \
fi
echo playwright pass
CI_TEST_TARGET ?= test-playwright
test-playwright-ci:
@set +e; \
make run-background && \
make run-httpbin-background && \
make ping-both && \
{ make $(CI_TEST_TARGET); EXIT_CODE=$$?; } ; \
echo "Cleaning up servers..."; \
make stop-run stop-httpbin; \
exit $${EXIT_CODE:-0}
test-playwright-ui:
npx playwright test --ui
generate-elm-test-json:
@echo "Generating Go test fixtures..."
@cd go && go test -run TestGenerateGoFixtures > /dev/null 2>&1
@echo "Generating cross-validation test data..."
node scripts/generate-cross-validation-tests.js
@echo "Formatting generated Elm test data..."
npx elm-format tests/GoElmCrossValidationTestData.elm --yes
generate-go-test-json: go/testdata/elm_json_fixtures.json
go/testdata/elm_json_fixtures.json: scripts/GenerateGoTestJSON.elm src/Main.elm
elm make scripts/GenerateGoTestJSON.elm --output=scripts/generate-go-test-json-elm.js
node -e "const {Elm} = require('./scripts/generate-go-test-json-elm.js'); const fs = require('fs'); const app = Elm.GenerateGoTestJSON.init(); app.ports.output.subscribe(json => { fs.writeFileSync('go/testdata/elm_json_fixtures.json', json); console.log('Generated go/testdata/elm_json_fixtures.json'); process.exit(0); });"
rm scripts/generate-go-test-json-elm.js
test-go: generate-go-test-json
make -C go test
test-json-compatibility: generate-go-test-json generate-elm-test-json
@echo "Testing JSON compatibility between Elm and Go..."
@if make -C go test > /dev/null 2>&1; then \
echo "✓ JSON compatibility test passed"; \
else \
echo "✗ JSON compatibility test failed - Elm/Go JSON structures are out of sync"; \
exit 1; \
fi
@echo "Testing JSON compatibility between Go and Elm..."
npx elm-test tests/GoElmCrossValidationTest.elm
run-httpbin-ignore-error:
go build -o httpbin-server go/httpbin/main.go
./httpbin-server || echo shutdown httpbin server
run-httpbin-background:
go build -o httpbin-server go/httpbin/main.go
(./httpbin-server > /dev/null 2>&1 &) && sleep 1 && echo "Httpbin server started in background"
ping-both:
wget --tries=90 --retry-connrefused -SO - http://localhost:8000
wget --tries=90 --retry-connrefused -SO - http://localhost:9000
stop-run:
killall node
stop-httpbin:
killall httpbin-server
elm-review:
(yes | npx elm-review --fix-all) || npx elm-review
schema: dist/config.schema.json
dist/config.schema.json: src/ConfigSchema.elm src/GenerateSchema.elm Makefile
elm make src/GenerateSchema.elm --output=elm-schema.js
node generate-schema.js
rm elm-schema.js
npx --package=ajv-cli ajv compile -s dist/config.schema.json
test-schema-compile:
elm make src/GenerateSchema.elm --output=elm-schema-test.js
rm elm-schema-test.js
validate-config:
@if [ -z "$(CONFIG)" ]; then \
echo "Usage: make validate-config CONFIG=path/to/config.json"; \
exit 1; \
fi
node validate-config.js "$(CONFIG)"
format:
npx elm-format src/ tests/ --yes
npx prettier --write "index.html" "input.css" "e2e/**/*.ts"
clean:
rm -f go/testdata/elm_json_fixtures.json scripts/generate-go-test-json-elm.js dist/*
# Display current version information from package.json, git tags, and npm registry
# This helps determine what version to publish next
show-versions:
@echo "Current version information:"
@echo ""
@echo " package.json: $$(grep '"version"' package.json | head -1 | sed 's/.*: "\(.*\)".*/\1/')"
@echo " Latest git tag: $$(git describe --tags --abbrev=0 2>/dev/null || echo '(no tags)')"
@echo " npm registry: $$(npm view tiny-form-fields version --registry=https://registry.npmjs.org/ 2>/dev/null || echo '(not published)')"
@echo ""
# Prepare for npm publish: validate environment, clean, build, bump version
# Validates:
# - VERSION parameter is provided
# - Currently on main branch
# - Working directory is clean (warning only, prompts to continue)
# - Logged into npm
# Then runs: make clean && make build && npm version
# Usage: make publish-prepare VERSION=1.2.0
publish-prepare:
@echo "==> Validating environment..."
@if [ -z "$(VERSION)" ]; then \
echo "ERROR: VERSION is required."; \
echo ""; \
make show-versions; \
echo "Usage: make publish-npm VERSION=x.y.z"; \
exit 1; \
fi
@if [ "$$(git branch --show-current)" != "main" ]; then \
echo "ERROR: Must be on main branch to publish"; \
echo "Current branch: $$(git branch --show-current)"; \
exit 1; \
fi
@if [ -n "$$(git status --porcelain)" ]; then \
echo "WARNING: Working directory is not clean."; \
git status --short; \
read -p "Press Enter to continue or Ctrl+C to cancel... " confirm; \
fi
@if ! npm whoami --registry=https://registry.npmjs.org/ > /dev/null 2>&1; then \
echo "ERROR: Not logged into npm."; \
echo "Run: npm login --registry=https://registry.npmjs.org/"; \
exit 1; \
fi
@echo "==> Cleaning and building..."
make clean
make build
@echo "==> Bumping version to $(VERSION)..."
npm version $(VERSION) --no-git-tag-version
git add package.json package-lock.json dist/
git commit -m "chore: release v$(VERSION)"
git tag -a "v$(VERSION)" -m "Release v$(VERSION)"
@echo "✅ Ready to publish v$(VERSION)"
# Publish package to npm and push version commit + tag to git
# Depends on publish-prepare (runs validation, clean, build, version bump first)
# Always publishes to public npm registry (not corporate proxies)
# Example workflow:
# make show-versions # Check current versions
# make publish-npm VERSION=1.2.0 # Full publish workflow
# Usage: make publish-npm VERSION=1.2.0
publish-npm: publish-prepare
@echo "==> Publishing to npm..."
npm publish --registry=https://registry.npmjs.org/ --access=public
@echo "==> Pushing to git..."
git push origin main --tags
@echo "✅ Published v$(VERSION) to npm and pushed to git"
@echo "Verify at: https://www.npmjs.com/package/tiny-form-fields"