Repository navigation
Expand file tree
/
Copy pathJustfile
More file actions
147 lines (116 loc) · 4.85 KB
/
Copy pathJustfile
File metadata and controls
147 lines (116 loc) · 4.85 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
DEV_PORT := "5186"
DEV_HTTP_PORT := "8012"
default:
@just --list --unsorted
# === Type generation ===
# TypeScript types for the JSON API, from the router's OpenAPI document
types-routes:
uv run python -c 'from datasette_otel_viewer.router import router; import json; print(json.dumps(router.openapi_document_json()))' \
| npx --prefix frontend openapi-typescript > frontend/api.d.ts
# TypeScript types for the embedded page data, from the Pydantic models
types-pagedata:
uv run scripts/typegen-pagedata.py
for f in frontend/src/page_data/*_schema.json; do \
npx --prefix frontend json2ts "$f" > "${f%_schema.json}.types.ts"; \
done
# Regenerate all TypeScript types from Python
types:
just types-routes
just types-pagedata
# Watch Python files and regenerate types on change
types-watch:
watchexec -e py --clear -- just types
# === Frontend ===
# Build the frontend into datasette_otel_viewer/static/gen + manifest.json.
# Vite's outDir is the package itself, so emptyOutDir is off; clear the old
# hashed bundles here or every build piles into the wheel.
frontend *flags:
rm -rf datasette_otel_viewer/static/gen datasette_otel_viewer/manifest.json
npm run build --prefix frontend {{flags}}
# Vite dev server (HMR) on port 5186
frontend-dev *flags:
npm run dev --prefix frontend -- --port {{DEV_PORT}} {{flags}}
# === Formatting / checks ===
format-backend *flags:
uv run ruff format {{flags}}
format-backend-check *flags:
uv run ruff format --check {{flags}}
format-frontend *flags:
npm run format --prefix frontend {{flags}}
format-frontend-check *flags:
npm run format:check --prefix frontend {{flags}}
format:
just format-backend
just format-frontend
format-check:
just format-backend-check
just format-frontend-check
check-backend:
uv run ruff check
uv run ty check
check-frontend:
npm run check --prefix frontend
check:
just check-backend
just check-frontend
# === Tests ===
# Python tests (page routes run in vite dev mode, so no frontend build needed).
# --exact: `just dev` installs the devserver group into the same environment
# and a plain `uv run` would leave it there, loading datasette-debug-gotham
# (and the debug bar) into every Datasette the suite builds.
test *options:
uv run --exact pytest {{ options }}
test-frontend *flags:
npm test --prefix frontend {{flags}}
test-all:
just test
just test-frontend
# === Dev servers ===
# Generate demo.db (200-row table) if missing
demo-db:
@[ -e demo.db ] || sqlite3 demo.db "create table plants(id integer primary key, name text, height_cm real); with recursive n(i) as (select 1 union all select i + 1 from n where i < 200) insert into plants select i, 'plant ' || i, abs(random() % 300) from n;"
# Self mode against demo.db. Serves the built bundle: run `just frontend`
# first, or use dev-with-hmr.
#
# Permissions are exercised for real: datasette-debug-gotham adds an actor
# switcher to the debug bar, and only `clark` (plus --root) is granted the
# datasette-otel-viewer action. Pick Clark Kent to see /-/otel, anyone else
# to get the 403.
#
# It comes from the `devserver` dependency group. A plain `uv run` does not
# uninstall it afterwards, which is why `test`, `demo` and the screenshot
# harness all pass --exact. Switching between `just dev` and `just test`
# re-syncs the environment; that is uv keeping the group out of the tests.
dev *options: demo-db
DATASETTE_SECRET=abc123 uv run --group devserver \
datasette demo.db --root \
-s permissions.datasette-otel-viewer.id clark \
-p {{DEV_HTTP_PORT}} {{ options }}
# `dev` + Vite HMR: page routes load assets from `just frontend-dev` (other
# terminal) and watchexec restarts Datasette on .py/.html changes.
dev-with-hmr *options:
watchexec \
--stop-signal SIGKILL \
-e py,html \
--ignore '*.db' \
--restart \
--clear -- \
just dev -s plugins.datasette-vite.dev_paths.datasette_otel_viewer "http://localhost:{{DEV_PORT}}/" {{ options }}
# Self mode demo: browse the instance, then open http://localhost:8003/-/otel/traces
demo *options: demo-db frontend
uv run --exact datasette demo.db --root \
-s plugins.datasette-otel-viewer.public_viewer true \
-p 8003 {{ options }}
# Delete demo output
clean:
rm -f otel.db demo.db
# === Screenshots ===
# Regenerate the committed doc screenshots in docs/screenshots/. Self-contained:
# boots a throwaway datasette, seeds traces and metrics with the
# `scripts/shots_plugins` seed plugin (--plugins-dir), drives Playwright, tears
# down. Builds the bundle first so shots reflect the current frontend.
# Not run in CI — re-run and confirm `git status` is clean. Subset: `just shots trace`.
shots *names:
just frontend
npm --prefix frontend exec -- playwright install chromium
node frontend/scripts/screenshots.mjs {{names}}