-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathjustfile
More file actions
495 lines (437 loc) · 14.8 KB
/
justfile
File metadata and controls
495 lines (437 loc) · 14.8 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# https://just.systems
#
# Run `just` in the root of the project to see a list of recipes relevant to manual builds.
# Backtick commands and recipes without a shebang are executed with the shell set here.
set shell := ['bash', '-c']
set windows-shell := ['powershell', '-Command']
set dotenv-load := true
bash := if os() == 'windows' { 'env -S bash -euo pipefail' } else { '/usr/bin/env -S bash -euo pipefail' }
powershell := if os() == 'windows' {'powershell.exe'} else {'/usr/bin/env pwsh'}
bun := if os() == 'windows' { 'bun.exe' } else { '/usr/bin/env bun' }
RUST_TOOLCHAIN := env('RUST_TOOLCHAIN', 'stable')
RUSTFLAGS := env('RUSTFLAGS','')
CI := env('CI', 'false')
GITHUB_ENV := env('GITHUB_ENV', '.GITHUB_ENV')
KEY_FILE := join(home_directory(), ".tauri", "memospot_updater.key")
KEY_FILE_CONTENTS := if path_exists(KEY_FILE)=="true" { trim_end(read(KEY_FILE))} else {""}
TAURI_SIGNING_PRIVATE_KEY := env('TAURI_SIGNING_PRIVATE_KEY', KEY_FILE_CONTENTS)
TAURI_SIGNING_PRIVATE_KEY_PASSWORD := env('TAURI_SIGNING_PRIVATE_KEY_PASSWORD', '')
GIT_WIN := join(env('PROGRAMFILES',''), 'Git','usr','bin')
PATH := if os() == 'windows' { GIT_WIN +';'+ env('PATH') } else { env('PATH') }
REPO_ROOT := justfile_directory()
BIOME_CONFIG_PATH := join(REPO_ROOT,'biome.jsonc')
DPRINT_CACHE_DIR := join(REPO_ROOT,'.dprint')
RUST_BACKTRACE := 'full'
RUST_TARGETS := if os() == 'windows' {
'x86_64-pc-windows-msvc'
} else if os() == "macos" {
'aarch64-apple-darwin x86_64-apple-darwin'
} else {
'x86_64-unknown-linux-gnu'
}
RUSTC_WRAPPER := env('RUSTC_WRAPPER', '')
CARGO_INCREMENTAL := if RUSTC_WRAPPER == '' { '1' } else { '0' }
TS_RS_EXPORT_DIR:= join(REPO_ROOT,'src-ui','src','lib','types','gen')
set export
[private]
default:
#!{{bash}}
echo "REPO_ROOT is ${REPO_ROOT}"
echo -e "{{BOLD}}This justfile contains recipes for building {{UNDERLINE}}https://github.com/memospot/memospot{{NORMAL}}.\n"
if [[ "{{os()}}" == "windows" ]]; then
git_win="{{replace(GIT_WIN, '\\', '\\\\')}}"
echo -e "To use this justfile on Windows, make sure Git is installed under {{BOLD}}{{UNDERLINE}}$git_win{{NORMAL}}."
echo -e "{{BOLD}}{{UNDERLINE}}https://git-scm.com/download/win{{NORMAL}}"
echo ""
fi
deps=(
"bash"
"bun"
"cargo"
"dprint"
"git"
"rustc"
)
for dep in "${deps[@]}"; do
if ! command -v "$dep" &> /dev/null; then
echo -e "{{RED}}ERROR:{{NORMAL}} Please install {{MAGENTA}}{{BOLD}}{{UNDERLINE}}$dep{{NORMAL}}."
echo -e "Try running {{BOLD}}{{UNDERLINE}}just setup{{NORMAL}}."
exit 1
fi
done
echo -e "{{GREEN}}Found project dependencies: ${deps[@]}{{NORMAL}}"
echo -e "{{YELLOW}}This quick test does not verify tool versions. If you experience any errors, consider updating the related tool.{{NORMAL}}\n"
just --list
[private]
deps-ts:
pushd "src-ui"; bun install; popd
pushd "build-scripts"; bun install; popd
[private]
dev-ui: deps-ts
#!{{bash}}
cd "src-ui" && bunx --bun svelte-kit sync && bunx vite dev
[private]
download-memos: deps-ts
#!{{bash}}
for i in 1 2 3; do
bun run ./build-scripts/bin/downloadMemos.ts && break || sleep 10
done
# Tauri hooks
[private]
tauri-before-build: download-memos gen-icons gen-bindings build-ui
[private]
tauri-before-bundle: deps-ts
[private]
tauri-before-dev: download-memos gen-icons gen-bindings dev-ui
# /Tauri hooks
[group('test')]
[doc('Run all tests')]
test: test-ts test-crates test-rs test-tauri
[group('test')]
[doc('Run all crate tests')]
test-crates:
cargo test --workspace --exclude memospot --lib -- --nocapture
[group('test')]
[doc('Run all Rust tests')]
test-rs:
#!{{bash}}
export CARGO_PROFILE_TEST_BUILD_OVERRIDE_DEBUG=true
cargo test --workspace --lib -- --nocapture
[group('test')]
[doc('Run all Tauri tests')]
test-tauri:
cargo test --package memospot --lib -- --nocapture
[group('test')]
[doc('Run all TypeScript tests')]
test-ts: deps-ts
#!{{bun}}
import fs from "node:fs";
const dirs = ["./build-scripts", "./src-ui"];
let results = [];
for (const dir of dirs) {
const files = fs.readdirSync(dir, {recursive: true}).filter(fn => fn.endsWith('.test.ts'));
if (files.length === 0) {
continue;
}
console.log(`> Running tests in ${dir}`);
await Bun.spawn({
cmd: ["bun", "test"],
cwd: dir,
onExit(proc, exitCode, signalCode, error) {
results.push(exitCode === 0);
}
}).exited;
}
const allPassed = results.every((result) => result);
allPassed ? console.log("All tests passed.") : console.error("Some tests failed.");
process.exit(allPassed ? 0 : 1);
[doc('Run app in development mode')]
dev: dev-killprocesses
cargo tauri dev
just dev-killprocesses
[private]
[linux]
[macos]
dev-killprocesses:
#!{{bash}}
for process in "memospot" "memos"; do
killall $process > /dev/null 2>&1 || true
done
[private]
[windows]
dev-killprocesses:
#!{{powershell}}
[System.Diagnostics.Process]::GetProcesses() | Where-Object {
$_.ProcessName -in "memospot", "memos"
} | Stop-Process -Force -ErrorAction SilentlyContinue
[group('update')]
[doc('Update project dependencies')]
[confirm('This will update all dependencies. This should be done carefully. Are you sure?')]
update: update-dprint update-rs update-ts
[group('update')]
[doc('Update dprint plugins')]
update-dprint:
dprint config update
[group('update')]
[doc('Update cargo crates')]
update-rs:
cargo update
[group('update')]
[doc('Update npm packages')]
update-ts:
#!{{bash}}
pushd "./src-ui"; bun update; popd
pushd "./build-scripts"; bun update; popd
just fmt
[group('update')]
[doc('Show outdated npm packages')]
outdated-ts:
#!{{bash}}
pushd "./src-ui"; bun outdated; popd
pushd "./build-scripts"; bun outdated; popd
just fmt
[group('upgrade')]
[doc('Upgrade project toolchain')]
upgrade: upgrade-rust upgrade-bun
[group('upgrade')]
[doc('Upgrade Rust toolchain')]
upgrade-rust:
rustup update
rustup self update
rustup component add clippy rust-analyzer
[group('upgrade')]
[doc('Upgrade bun runtime')]
upgrade-bun:
bun upgrade
gen-icons-force:
#!{{bash}}
cargo tauri icon "assets/app-icon-lossless.webp"
cp -f "./crates/memospot/icons/icon.ico" "./src-ui/static/favicon.ico"
git add "assets/app-icon-lossless.webp" "crates/memospot/icons/*"
# git commit -m "chore: regenerate icons"
[doc('Generate app icons, if needed')]
gen-icons:
#!{{bash}}
if [ "$CI" = "true" ]; then exit 0; fi
check_files=(
"assets/app-icon-lossless.webp"
"crates/memospot/icons/**.png"
"crates/memospot/icons/icon.ico"
"src-ui/static/favicon.ico"
)
for file in "${check_files[@]}"; do
if ! git diff --quiet --exit-code HEAD -- "$file"; then
echo "{{YELLOW}}$file was modified since last commit, regenerating icons…{{NORMAL}}"
just gen-icons-force
exit 0
fi
done
echo -e "{{GREEN}}App icons are up to date.{{NORMAL}}"
gen-bindings:
#!{{bash}}
mkdir -p "$TS_RS_EXPORT_DIR"
# Files listed here may affect the frontend bindings.
check_files=(
"crates/config/**/*"
"crates/memospot/src/runtime_config.rs"
)
for file in "${check_files[@]}"; do
if ! git diff --quiet --exit-code HEAD -- "$file"; then
echo -e "{{YELLOW}}${file} was modified since last commit, regenerating TypeScript bindings…{{NORMAL}}"
pushd crates/memospot; cargo test export_bindings; popd
exit 0
fi
done
echo -e "{{CYAN}}Skipping TypeScript bindings regeneration, no changes detected.{{NORMAL}}"
build-ui-force:
cd "src-ui"; bun run build
[doc('Build UI, if needed')]
build-ui:
#!{{bash}}
if ! git diff --quiet --exit-code HEAD -- "src-ui/src/**" || [ ! -d "./src-ui/build/" ] || [ ! -f "./src-ui/build/index.html" ]; then
just build-ui-force
else
echo -e "{{GREEN}}UI is up to date.{{NORMAL}}"
fi
[doc('Build app')]
build TARGET='all':
#!{{bash}}
if [ "{{TARGET}}" = "no-bundle" ]; then
cargo tauri build --no-bundle
just postbuild
exit 0
fi
if [ -z $TAURI_SIGNING_PRIVATE_KEY ] && [ -f $HOME/.tauri/memospot_updater.key ]; then
export TAURI_SIGNING_PRIVATE_KEY=$(cat $HOME/.tauri/memospot_updater.key 2>/dev/null | tr -d '\n' || echo "")
echo -e "{{CYAN}}Setting TAURI_SIGNING_PRIVATE_KEY from $HOME/.tauri/memospot_updater.key{{NORMAL}}"
fi
if [ -z $TAURI_SIGNING_PRIVATE_KEY ] || [ -z $TAURI_SIGNING_PRIVATE_KEY_PASSWORD ]; then
echo -e "{{YELLOW}}Environment not fully configured. Building without updater.{{NORMAL}}"
cargo tauri build -c '{"bundle": {"targets": "{{TARGET}}" }, "plugins": {"updater": {}}}'
else
cargo tauri build -c '{"bundle": {"targets": "{{TARGET}}" }}'
fi
just postbuild
[doc('Actions: prune, lint, test, linux, windows, linux-no-bundle, windows-no-bundle.')]
[group('Docker Bake')]
bake ACTION='':
#!{{bash}}
if [ "{{ACTION}}" = "prune" ]; then
docker builder du
docker builder prune -a
else
docker buildx bake {{ACTION}}
test -d "./build" && sudo chown -R $(id -u):$(id -g) ./build
fi
[linux]
flatpak-lint:
#!{{bash}}
flatpak install -y flathub org.flatpak.Builder
shopt -s expand_aliases
alias flatpak-builder-lint="flatpak run --command=flatpak-builder-lint org.flatpak.Builder"
flatpak-builder-lint appstream ./installer/flatpak/io.github.memospot.Memospot.metainfo.xml
flatpak-builder-lint manifest ./installer/flatpak/io.github.memospot.Memospot.yml
flatpak-builder-lint repo ./target/flatpak-repo
[linux]
flatpak-build:
#!{{bash}}
just build deb
flatpak-builder --force-clean --user --install-deps-from=flathub --repo=./target/flatpak-repo --install ./target/flatpak ./installer/flatpak/io.github.memospot.Memospot.yml
[linux]
flatpak-run:
flatpak run io.github.memospot.Memospot
[linux]
debug-env:
#!{{bash}}
pid="$(pidof memospot)"
test -z $pid && echo -e "{{RED}}Memospot is not running.{{NORMAL}}" && exit 1
tr '\0' '\n' < /proc/$pid/environ | sort
[private]
postbuild:
#!{{bash}}
set +e
echo -e "{{CYAN}}Moving relevant build files to ./build directory…{{NORMAL}}"
! test -d "./build" && mkdir -p "./build"
artifacts=(
"bundle/appimage/*.AppImage"
"bundle/deb/*.deb"
"bundle/msi/*.msi"
"bundle/nsis/*.exe"
"bundle/rpm/*.rpm"
"dist/"
"memos"
"memos.exe"
"memospot"
"memospot.exe"
)
for artifact in "${artifacts[@]}"; do
resolved_path="$(find ./target/release/$artifact -type f 2>&1 | head -n 1)"
test -f "$resolved_path" && mv -f "$resolved_path" ./build/. 2>/dev/null
done
pushd "./build"
appimages=($(find *.AppImage -type f 2>&1))
for appimage in "${appimages[@]}"; do
! test -f "${appimage}" && continue
! test -d "${appimage}.home" && mkdir -p "${appimage}.home"
done
if ls ./memos* 1> /dev/null 2>&1; then
echo -e "{{GREEN}}Done.{{NORMAL}}"
else
echo -e "{{RED}}Failed to move files.{{NORMAL}}"
fi
popd
[doc('Clean project artifacts')]
clean:
#!{{bash}}
set +e
for d in "./src-ui" "./build-scripts"; do
pushd "$d" && bun pm cache rm && popd
done
cargo cache -a || true
dirs=(
"./.dprint"
"./build"
"./build-scripts/node_modules"
"./node_modules"
"./server-dist"
"./src-ui/.vite"
"./src-ui/build"
"./src-ui/node_modules"
"./target"
)
for item in "${dirs[@]}"; do
test -d "$item" && rm -rf "$item"
done
exit 0
[group('lint')]
[doc('Run all code linters')]
lint: lint-dprint lint-ts lint-rs
[group('lint')]
[doc('Check code formatting')]
lint-dprint:
dprint check
[group('lint')]
[doc('Lint Rust code with cargo fmt and clippy')]
lint-rs:
cargo fmt --all --check
cargo clippy --all-features --all-targets --workspace --locked
[group('lint')]
[doc('Lint TypeScript code with BiomeJS')]
lint-ts:
bun x @biomejs/biome ci --css-parse-tailwind-directives=true .
[group('fix')]
[doc('Run all code fixes')]
fix: fix-ts fix-rs
[group('fix')]
[doc('Run cargo fix (requires clean repo)')]
fix-rs:
cargo fix || just fix-rs-dirty
[group('fix')]
[confirm('This will run `cargo fix --allow-dirty`. This can perform destructive changes. Are you sure?')]
fix-rs-dirty:
cargo fix --allow-dirty
[group('fix')]
[doc('Run BiomeJS safe fixes')]
fix-ts:
#!{{bash}}
for d in "./build-scripts" "./src-ui"; do
cd "$REPO_ROOT/$d"
if ls *.ts 1> /dev/null 2>&1; then
bun x @biomejs/biome lint --apply .
fi
done
[group('format')]
[doc('Format code with dprint (json, rust, toml, yaml, html, css, typescript and markdown).')]
fmt:
dprint fmt --diff
[doc('Run all recommended pre-commit checks')]
pre-commit: fmt lint test
[group('maintainer')]
[doc('Delete all GitHub build cache')]
gh-clean-cache:
gh cache delete --all
[group('maintainer')]
repo-status:
#!{{bash}}
if ! git diff-index --quiet HEAD --; then
echo -e "{{MAGENTA}}There are unstaged changes.{{NORMAL}}"
elif ! git diff-files --quiet; then
echo -e "{{MAGENTA}}There are unstaged changes.{{NORMAL}}"
elif ! git status; then
echo -e "{{MAGENTA}}There are untracked files.{{NORMAL}}"
elif ! [ -z "$(git ls-files --deleted)" ]; then
echo -e "{{MAGENTA}}There are deleted files.{{NORMAL}}"
elif ! [ -z "$(git ls-files --modified)" ]; then
echo -e "{{MAGENTA}}There are modified files.{{NORMAL}}"
else
echo -e "{{GREEN}}Repository is clean.{{NORMAL}}"
exit 0
fi
exit 1
[group('maintainer')]
[doc('Bump version in Cargo.toml and crates/memospot/Cargo.toml')]
bumpversion VERSION:
#!{{bash}}
clean="{{trim_start_match(VERSION, "v")}}"
cargo set-version --locked "$clean"
cargo generate-lockfile
for d in "." "./build-scripts" "./src-ui"; do
jq --arg version "$clean" '.version = $version' "$d/package.json" > "$d/package.json.tmp" && mv "$d/package.json.tmp" "$d/package.json"
done
just fmt
bun install --lockfile-only
git add ./crates/memospot/Cargo.toml ./crates/memospot/Tauri.toml ./Cargo.lock ./Cargo.toml \
./build-scripts/package.json ./src-ui/package.json ./package.json ./bun.lock
git commit -m "chore: bump version to v$clean"
[group('maintainer')]
[doc('Push a new tag to the repository')]
pushtag TAG:
#!{{bash}}
clean="{{trim_start_match(TAG, "v")}}"
git tag -a "v$clean" -m "chore: push v$clean"
git push origin --tags
[group('maintainer')]
[doc('Publish a new version (bumpversion + pushtag)')]
publish TAG:
just bumpversion {{TAG}}
just pushtag {{TAG}}