Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/justfile

Raw
default:
  @just --list

# lint/typecheck/verify all Nuguland source; zero warnings
lint:
  #!/usr/bin/env bash
  set -euo pipefail
  tmp=$(mktemp -d)
  qs_pid=""
  cleanup() {
    [[ -z "$qs_pid" ]] || kill "$qs_pid" 2>/dev/null || true
    rm -rf "$tmp"
  }
  trap cleanup EXIT

  mapfile -t qml < <({ find . -maxdepth 1 -name '*.qml' -print; find test-fixtures -name '*.qml' -print; } | sort)
  mapfile -t sh < <(find . -path './vault-native/target' -prune -o -name '*.sh' -print | sort)
  mapfile -t mjs < <(find . -name '*.mjs' -print | sort)
  mapfile -t frag < <(find shaders -name '*.frag' -print 2>/dev/null | sort)
  for file in "${qml[@]}"; do
    /usr/lib/qt6/bin/qmllint --max-warnings 0 -I /usr/lib/qt6/qml "$file" || { echo "qmllint failed: $file" >&2; exit 1; }
  done
  ((${#sh[@]} == 0)) || shellcheck "${sh[@]}"
  for file in "${mjs[@]}"; do
    node --check "$file"
  done
  cargo fmt --manifest-path vault-native/Cargo.toml --check
  cargo clippy --manifest-path vault-native/Cargo.toml --all-targets --locked -- -D warnings
  cargo test --manifest-path vault-native/Cargo.toml --locked
  cargo build --manifest-path vault-native/Cargo.toml --locked
  just test
  ((${#frag[@]} == 0)) || glslangValidator "${frag[@]}"

  for file in "${qml[@]}"; do
    out="$tmp/${file#./}"
    mkdir -p "$(dirname "$out")"
    /usr/lib/qt6/bin/qmlformat "$file" > "$out" || { echo "qmlformat failed: $file" >&2; exit 1; }
    cmp -s "$file" "$out" || { echo "qmlformat changed: $file" >&2; diff -u "$file" "$out"; exit 1; }
  done

  for file in "${sh[@]}"; do
    out="$tmp/${file#./}"
    mkdir -p "$(dirname "$out")"
    shfmt "$file" > "$out"
    cmp -s "$file" "$out" || { diff -u "$file" "$out"; exit 1; }
  done

  shopt -s nullglob
  for shader in shaders/*.frag; do
    out="$tmp/${shader//\//__}.qsb"
    /usr/lib/qt6/bin/qsb --glsl 330 --hlsl 50 --msl 12 -o "$out" "$shader"
    cmp -s "$shader.qsb" "$out" || { echo "stale shader blob: $shader.qsb" >&2; exit 1; }
  done
  for blob in shaders/*.qsb; do
    [[ -f "${blob%.qsb}" ]] || { echo "orphan shader blob: $blob" >&2; exit 1; }
  done
  if qs ipc -c nuguland call nuguland ping >/tmp/nuguland-lint.qs.out 2>/tmp/nuguland-lint.qs.err; then
    : > /tmp/nuguland-lint.qs.err
  else
    [[ "${NUGULAND_UI_SANDBOX:-}" == "1" ]] || { echo "runtime check unavailable; refusing to launch shell.qml on the parent desktop" >&2; exit 1; }
    QT_NO_XDG_DESKTOP_PORTAL=1 qs -p shell.qml >/tmp/nuguland-lint.qs.out 2>/tmp/nuguland-lint.qs.err &
    qs_pid=$!
    sleep 3
    kill -0 "$qs_pid"
  fi
  if grep -E "WARN|ERROR|Error parsing|deprecated|Could not|failed" /tmp/nuguland-lint.qs.out /tmp/nuguland-lint.qs.err; then
    echo "runtime warnings during lint" >&2
    exit 1
  fi

# run JS tests; pass a file, basename, stem, or vault-native for all Rust tests
# examples: just test, just test network, just test vault-native
test name="":
  #!/usr/bin/env bash
  set -euo pipefail
  target={{quote(name)}}
  if [[ "$target" == vault-native ]]; then
    exec cargo test --manifest-path vault-native/Cargo.toml --locked
  fi
  if [[ -n "$target" ]]; then
    case "$target" in
      /*|*..*|*$'\n'*|*$'\r'*) echo "unsafe test: $target" >&2; exit 2 ;;
    esac
    if [[ "$target" != *.js && "$target" != *.mjs ]]; then
      if [[ -f "$target.test.js" ]]; then
        target="$target.test.js"
      elif [[ -f "$target.test.mjs" ]]; then
        target="$target.test.mjs"
      else
        target="$target.test.js"
      fi
    fi
    [[ -f "$target" ]] || { echo "missing test: $target" >&2; exit 2; }
    node "$target"
    exit
  fi

  mapfile -t tests < <(find . -maxdepth 1 \( -name '*.test.js' -o -name '*.test.mjs' \) -print | sort)
  ((${#tests[@]} > 0)) || { echo "no tests" >&2; exit 1; }
  for file in "${tests[@]}"; do
    node "$file"
  done

# exercise shared controls in niri inside headless Weston; retain screenshots and logs
ui-test fixture="all" size="":
  node ui-test.mjs {{quote(fixture)}} {{if size == "" { "" } else { quote(size) }}}

# format Nuguland QML and shell scripts in place
fmt:
  #!/usr/bin/env bash
  set -euo pipefail
  mapfile -t qml < <({ find . -maxdepth 1 -name '*.qml' -print; find test-fixtures -name '*.qml' -print; } | sort)
  mapfile -t sh < <(find . -path './vault-native/target' -prune -o -name '*.sh' -print | sort)
  for file in "${qml[@]}"; do
    /usr/lib/qt6/bin/qmlformat -i "$file" || { echo "qmlformat failed: $file" >&2; exit 1; }
  done
  ((${#sh[@]} == 0)) || shfmt -w "${sh[@]}"
  cargo fmt --manifest-path vault-native/Cargo.toml

# compile checked-in shaders
build:
  #!/usr/bin/env bash
  set -euo pipefail
  cargo build --manifest-path vault-native/Cargo.toml --release --locked
  shopt -s nullglob
  for shader in shaders/*.frag; do
    /usr/lib/qt6/bin/qsb --glsl 330 --hlsl 50 --msl 12 -o "$shader.qsb" "$shader"
  done