# Use `just <recipe>` to run a recipe
# https://just.systems/man/en/
# Updated for VuePress 2 + Vuetify 3

import ".shared/common.just"

# Variables

zellijSession := "qownnote-webpage"

# By default, run the `--list` command
default:
    @just --list

# Open a bash shell in the dev container
[group('dev')]
bash:
    #docker run -it --rm --volume .:/app --user $(id -u) node:12 bash
    #docker-compose run --rm dev bash -c "cd /app && bash"
    docker-compose exec dev bash -c "cd /app && bash"

# Run the development watch build
[group('dev')]
dev:
    npm run dev

# Open a browser to the local dev server
[group('dev')]
open-browser:
    xdg-open http://localhost:8080/

# Open a terminal with the qownnote-webpage session
[group('dev')]
term-run:
    zellij --layout term.kdl attach {{ zellijSession }} -c

# Kill the qownnote-webpage session
[group('dev')]
term-kill:
    -zellij delete-session {{ zellijSession }} -f

# Kill and run a terminal with the qownnote-webpage session
[group('dev')]
term: term-kill term-run

# Build for production
[group('build')]
build:
    npm run build

# Clean build artifacts
[group('build')]
clean:
    rm -rf src/.vuepress/dist src/.vuepress/.cache src/.vuepress/.temp

# Install dependencies
[group('setup')]
install:
    npm install

# Clean install
[group('setup')]
clean-install:
    rm -rf node_modules package-lock.json
    npm install

# Test config loads
[group('test')]
test-config:
    node test-config.mjs

# Show VuePress info
[group('info')]
info:
    npx vuepress info

# Check for outdated packages
[group('info')]
outdated:
    npm outdated

# Open the playwright test UI
[group('dev')]
playwright-test-ui:
    npm run playwright:test:ui

# Run the playwright tests
[group('dev')]
playwright-test test='':
    npm run playwright:test -- tests/{{ test }}

# Run the local playwright tests
[group('dev')]
playwright-test-local test='':
    npm run playwright:test:local -- tests/{{ test }}

# Run the local docker playwright tests
[group('dev')]
playwright-test-local-docker test='':
    npm run playwright:test:local-docker -- tests/{{ test }}

# Run the playwright tests on next.qownnotes.org
[group('dev')]
playwright-test-next test='':
    npm run playwright:test:next -- tests/{{ test }}

# Remove the vuepress cache with elevated permissions (after it was created by docker)
[group('dev')]
remove-vuepress-cache:
    sudo rm ./src/.vuepress/.cache -Rf
