Skip to content

Commit e73e188

Browse files
committed
Merge branch 'tailwind-4'
2 parents 39ed753 + b237917 commit e73e188

31 files changed

+1746
-3658
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
.tmp
33
/result
44
/venv
5+
.direnv/
56

67
# project
8+
/website/static/css/main.css
9+
/website/static/js/main.js
710
node_modules/
811
*.tar
912
*.json
13+
!package.json
14+
!package-lock.json
1015
/*.pickle
16+
.ruff_cache/
1117

1218
# Created by https://www.toptal.com/developers/gitignore/api/django
1319
# Edit at https://www.toptal.com/developers/gitignore?templates=django

flake.nix

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
sourcePreference = "wheel";
4848
};
4949

50-
pythonSets =
50+
pythonSet =
5151
let
5252
baseSet = pkgs.callPackage pyproject-nix.build.packages {
5353
inherit python;
@@ -75,29 +75,16 @@
7575
]
7676
);
7777

78-
inherit (pkgs.stdenv) mkDerivation;
7978
inherit (pkgs) writeShellApplication;
8079

8180
in
8281
{
8382
packages = {
84-
venv = pythonSets.mkVirtualEnv "strykeforce-env" workspace.deps.default;
85-
86-
static = mkDerivation {
87-
pname = "strykeforce-static";
88-
inherit (pythonSets.website) version;
89-
src = self;
90-
phases = "installPhase";
91-
installPhase = ''
92-
export DJANGO_SETTINGS_MODULE=website.settings.production
93-
export SECRET_KEY=notsecret
94-
export TBA_READ_KEY=
95-
export EMAIL_HOST_USER=
96-
export EMAIL_HOST_PASSWORD=
97-
export STATIC_ROOT=$out
98-
mkdir -p $out
99-
${self.packages.${system}.venv}/bin/strykeforce-manage collectstatic --no-input
100-
'';
83+
venv = pythonSet.mkVirtualEnv "strykeforce-env" workspace.deps.default;
84+
85+
static = import ./lib/static.nix {
86+
inherit pkgs pythonSet;
87+
inherit (self.packages.${system}) venv;
10188
};
10289

10390
manage = import ./lib/manage.nix {

justfile

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ _default:
44
@just --list
55

66
# bootstrap the development environment
7-
bootstrap: venv pre-commit
7+
bootstrap: pre-commit
88

99
# open the project in Pycharm
1010
edit:
@@ -32,51 +32,19 @@ test: (manage "test --keepdb")
3232
push:
3333
nix build --json .#venv | jq -r '.[].outputs | to_entries[].value' | cachix push strykeforce
3434
nix build --json .#static | jq -r '.[].outputs | to_entries[].value' | cachix push strykeforce
35-
36-
# update CSS and download all JS dependencies
37-
update: venv update-css update-alpine
38-
39-
# update CSS with classes from HTML templates
35+
#
36+
# update CSS
4037
update-css:
41-
tailwindcss -i website/static/css/base.css -o website/static/css/main.css
42-
43-
# watch HTML templates and update CSS
44-
watch:
45-
tailwindcss -i website/static/css/base.css -o website/static/css/main.css --watch
46-
47-
# download all JS dependencies
48-
update-alpine:
49-
curl --no-progress-meter --location https://unpkg.com/alpinejs --output website/static/js/alpine.js
38+
npx @tailwindcss/cli --input=website/static/css/base.css --output=website/static/css/main.css
5039

51-
# update dev dependencies to latest version
52-
update-dev: && poetry-check
53-
poetry add --group=dev --lock black@latest
54-
# poetry add --group=dev --lock django-debug-toolbar@latest
55-
poetry add --group=dev --lock ipython@latest
56-
poetry add --group=dev --lock rich@latest
40+
# update JS
41+
update-js:
42+
npx esbuild --bundle --outfile=website/static/js/main.js website/static/js/base.js
5743

58-
# checks poetry.lock against the version of pyproject.toml and locks if neccessary
59-
poetry-check:
60-
poetry check --lock --quiet || (just poetry-lock)
61-
62-
# locks the python packages in pyproject.toml without updating the poetry env
63-
poetry-lock:
64-
poetry lock --no-update
44+
# Watch CSS and JS for changes
45+
watch: update-css
46+
npx @tailwindcss/cli --watch --input=website/static/css/base.css --output=website/static/css/main.css
6547

6648
# install pre-commit hooks
6749
pre-commit:
6850
pre-commit install --install-hooks
69-
70-
# refresh the python packages in the dev env
71-
venv: poetry-check
72-
nix build .#venv -o .venv
73-
74-
# grep for version
75-
version:
76-
@rg "version = " -m 1 pyproject.toml flake.nix
77-
78-
# supply a new project version for pyproject.toml and flake.nix
79-
set-version version:
80-
@sed --in-place 's/^version = ".*"/version = "{{ version }}"/' pyproject.toml
81-
@sed --in-place --regexp-extended 's/(\s+version = )".*";/\1"{{ version }}";/' flake.nix
82-
@git diff -U0 pyproject.toml flake.nix

lib/static.nix

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
pkgs,
3+
pythonSet,
4+
venv,
5+
}:
6+
let
7+
baseCss = "website/static/css/base.css";
8+
9+
djangoStaticDeps = pkgs.buildNpmPackage {
10+
name = "django-static-deps";
11+
src = ../.;
12+
npmDepsHash = "sha256-K7GLUG25KdvTT5gqounSi3U0UJonw9gPEuHUF4pP8os=";
13+
dontNpmBuild = true;
14+
15+
patchPhase = ''
16+
runHook prePatch
17+
runHook postPatch
18+
'';
19+
20+
buildPhase = ''
21+
runHook preBuild
22+
npx @tailwindcss/cli --minify --input=${baseCss} --output=$out/css/main.css
23+
npx esbuild --bundle --minify --outfile=$out/js/main.js website/static/js/base.js
24+
runHook postBuild
25+
'';
26+
27+
installPhase = ''
28+
runHook postInstall
29+
'';
30+
};
31+
inherit (pkgs.stdenv) mkDerivation;
32+
in
33+
mkDerivation {
34+
pname = "strykeforce-static";
35+
inherit (pythonSet.website) version;
36+
nativeBuildInputs = [ venv ];
37+
38+
dontUnpack = true;
39+
dontConfigure = true;
40+
dontBuild = true;
41+
42+
installPhase = ''
43+
export DJANGO_SETTINGS_MODULE=website.settings.production
44+
export DJANGO_STATICFILES_DIR="${djangoStaticDeps}"
45+
export SECRET_KEY=
46+
export STATIC_ROOT=$out
47+
export TBA_READ_KEY=
48+
export EMAIL_HOST_USER=
49+
export EMAIL_HOST_PASSWORD=
50+
mkdir -p $out
51+
${venv}/bin/strykeforce-manage collectstatic --no-input --ignore="css/base.css" --ignore="js/base.js"
52+
'';
53+
54+
}

0 commit comments

Comments
 (0)