generated from Austionian/axum_tailwind_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
179 lines (143 loc) · 4.68 KB
/
justfile
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
set dotenv-load
# List available commands
default:
just -l
alias u := update
alias d := dev
alias t := test
alias t-u := test-update
ROLLUP := "rollup client/index.js --file assets/static/index.min.js --format iife"
TAILWIND := "./tailwindcss -i ./src/styles/styles.css -o ./assets/styles.css"
# Runs the Tailwind binary in watch mode
run-tailwind:
#!/bin/bash
echo "Starting the Tailwind binary."
{{TAILWIND}} --watch
# Builds and minifies the CSS with the Tailwind binary
build-tailwind:
#!/bin/bash
echo "minifying css"
{{TAILWIND}} --minify
# Runs the axum server in watch mode.
run-axum:
#!/bin/bash
echo "Starting the Axum server."
export API_TOKEN=$API_TOKEN
# Start cargo watch in the background
cargo watch -w src -x run
# Runs rollup in watch mode.
run-rollup:
#!/bin/bash
echo "Starting rollup."
{{ROLLUP}} --watch --watch.exclude "src/**" --no-watch.clearScreen
# Builds and minifies the JS with rollup
build-rollup:
#!/bin/bash
echo "building JS"
{{ROLLUP}} -p @rollup/plugin-terser
# Updates the requested versions of assets found in the
# base.html template to bust cached versions of old assets.
bump-assets:
#!/bin/bash
echo "bumping static assets version numbers in base.html"
target/release/bump-versions
# Builds all the static assets and bumps their versions
build:
#!/bin/bash
just build-tailwind &
just build-rollup &
just bump-assets &
wait
echo "complete!"
# Run the axum server, rollup, and tailwind binary in watch mode so updates
# will automatically be reflected. On exit, will minify tailwind's css and js.
#
# Install Just and run with `just dev`
dev:
#!/bin/bash
minify() {
just build
}
# Add a trap to run the minify function before exiting
trap "minify; kill 0" SIGINT
open 'http://127.0.0.1:8080'
just run-axum & just run-rollup & just run-tailwind
TAILWIND_PID=$!
wait $TAILWIND_PID
# Update dependencies and run the tests.
update:
#!/bin/bash
cargo update
echo -e "Dependencies updated! \n"
cargo clippy
just test
# Runs the tests, writes new snapshots
test:
#!/bin/bash
# unseen: writes new snapshots and writes .snap.new for exisiting
INSTA_UPDATE=unseen cargo t --features mock-time && node --test
# Runs the tests, and updates all snapshots
test-update:
#!/bin/bash
# always: overwrites old snapshot files with new ones unasked
INSTA_UPDATE=always cargo t --features mock-time
# Installs rollup and the terser plugin globally
install-rollup:
#!/bin/bash
echo "Installing rollup"
npm install --global rollup
echo "Installing rollup terser plugin"
npm install --global @rollup/plugin-terser
# Compiles the helper binary to bump static asset versions in base.html
install-bump-versions:
#!/bin/bash
FILE=./target/release/bump-versions
if [ ! -f "$FILE" ]
then
echo "Building bump-versions"
cargo build --bin bump-versions --release
fi
# Installs the projects dependencies required to run the project, other
# than Just obviously. MacOS only.
install:
#!/bin/bash
if command -v cargo &> /dev/null; then
echo "Cargo found, skipping Rust install"
else
# install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
fi
if command cargo watch --version &> /dev/null; then
echo "Cargo watch found, skipping install"
else
# install cargo watch
cargo install cargo-watch
fi
just install-bump-versions
# install the Tailwind binary
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64
chmod +x tailwindcss-macos-arm64
mv tailwindcss-macos-arm64 tailwindcss
# check if npm is available
if command -v node &> /dev/null; then
just install-rollup
else
echo "npm not found. Installing fnm and node."
# installs fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash
# activate fnm
source ~/.bashrc
# download and install Node.js
fnm use --install-if-missing 22
just install-rollup
fi
# Builds the docker image
docker-build:
docker buildx build --platform linux/arm64/v8 --tag gathering_surf --file Dockerfile.prod .
docker-deploy:
DOCKER_HOST="ssh://[email protected]" docker compose up -d
docker-local:
docker build --tag gathering_surf --file Dockerfile.local . && docker compose up -d
# Transfers the docker image to the pi and runs the deploy script
deploy:
just docker-build && docker save gathering_surf | bzip2 | ssh [email protected] docker load && just docker-deploy