diff --git a/.gitignore b/.gitignore index 851e426..0f08154 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ dist/ .python-version .direnv .hermes/ + +# TypeScript: compiled output and codegen are build-only +/games/static/js/dist/ +/ts/generated/ diff --git a/Makefile b/Makefile index fc20c4f..5c61872 100644 --- a/Makefile +++ b/Makefile @@ -25,12 +25,22 @@ init: server: uv run python -Wa manage.py runserver +gen-element-types: + uv run python manage.py gen_element_types + +ts: gen-element-types + pnpm exec tsc + +ts-check: gen-element-types + pnpm exec tsc --noEmit + dev: @pnpm concurrently \ - --names "Django,Tailwind" \ - --prefix-colors "blue,green" \ + --names "Django,Tailwind,TS" \ + --prefix-colors "blue,green,magenta" \ "uv run python -Wa manage.py runserver" \ - "pnpm tailwindcss -i ./common/input.css -o ./games/static/base.css --watch" + "pnpm tailwindcss -i ./common/input.css -o ./games/static/base.css --watch" \ + "pnpm exec tsc --watch" caddy: @@ -85,7 +95,7 @@ format: format-check: uv run ruff format --check -check: lint format-check test +check: lint format-check ts-check test date: uv run python -c 'import datetime; from zoneinfo import ZoneInfo; print(datetime.datetime.isoformat(datetime.datetime.now(ZoneInfo("Europe/Prague")), timespec="minutes", sep=" "))' diff --git a/package.json b/package.json index 9860a1e..7666c0d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "@tailwindcss/typography": "^0.5.13", "concurrently": "^8.2.2", "npm-check-updates": "^16.14.20", - "tailwindcss": "^4.1.18" + "tailwindcss": "^4.1.18", + "typescript": "^5.6.0" }, "dependencies": { "@tailwindcss/cli": "^4.1.18", diff --git a/ts/globals.d.ts b/ts/globals.d.ts new file mode 100644 index 0000000..b0c8127 --- /dev/null +++ b/ts/globals.d.ts @@ -0,0 +1,7 @@ +export {}; + +declare global { + interface Window { + fetchWithHtmxTriggers(input: RequestInfo | URL, init?: RequestInit): Promise; + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..20c5484 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ES2022", + "moduleResolution": "Bundler", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "strict": true, + "noEmitOnError": true, + "forceConsistentCasingInFileNames": true, + "rootDir": "ts", + "outDir": "games/static/js/dist" + }, + "include": ["ts/**/*.ts"] +}