Files
oslstats/justfile
2026-02-15 12:27:36 +11:00

125 lines
2.6 KiB
Makefile

entrypoint := 'oslstats'
cwd := justfile_directory()
cmd := cwd / 'cmd'
bin := cwd / 'bin'
css_dir := cwd / 'internal/embedfs/web/css'
set quiet := true
[private]
default:
@just --list --unsorted
# BUILD RECIPES
# Build the target binary
[group('build')]
build target=entrypoint: tailwind (_build target)
_build target=entrypoint: tidy (generate target)
go build -ldflags="-w -s" -o {{bin}}/{{target}} {{cmd}}/{{target}}
# Generate tailwind output file
[group('build')]
[arg('watch', pattern='--watch|')]
tailwind watch='':
tailwindcss -i {{css_dir}}/input.css -o {{css_dir}}/output.css {{watch}}
# Generate go source files
[group('build')]
generate target=entrypoint:
go generate {{cmd}}/{{target}}
# Generate templ files
[group('build')]
[arg('watch', pattern='--watch|')]
templ watch='':
templ generate {{watch}}
# RUN RECIPES
# Run the target binary
[group('run')]
run target=entrypoint: (build target)
./bin/{{target}}
[private]
_air:
air
# Run the main program in development mode (with air & hot reloading)
[group('run')]
[parallel]
dev: (templ '--watch') (tailwind '--watch') _air
# GO RECIPES
# Tidy go mod file
[group('go')]
tidy:
go mod tidy
# Get or update h/golib packages
[group('go')]
[arg('update', pattern='-u|')]
golib package update='': && tidy
go get {{update}} git.haelnorr.com/h/golib/{{package}}
# ENV RECIPES
# Generate a new env file
[group('env')]
genenv out='.env': _build
{{bin}}/{{entrypoint}} --genenv {{out}}
# Show env file documentation
[group('env')]
envdoc: _build
{{bin}}/{{entrypoint}} --envdoc
# Show current env file values
[group('env')]
showenv: _build
{{bin}}/{{entrypoint}} --showenv
# DB RECIPES
# Migrate the database
[group('db')]
[arg('command', pattern='up|down|new|status', help="up|down|new|status")]
[script]
migrate command subcommand='' env='.env': _build
env={{env}}
subcommand={{subcommand}}
if [[ "{{command}}" = "status" ]]; then
env=$subcommand
subcommand=''
fi
if [[ $env = "" ]]; then
env=.env
fi
ENVFILE=$env just _migrate-{{command}} $subcommand
[private]
_migrate-up steps='1': && _migrate-status
{{bin}}/{{entrypoint}} --migrate-up {{steps}} --envfile $ENVFILE
[private]
_migrate-down steps='1': && _migrate-status
{{bin}}/{{entrypoint}} --migrate-rollback {{steps}} --envfile $ENVFILE
[private]
_migrate-status:
{{bin}}/{{entrypoint}} --migrate-status --envfile $ENVFILE
[private]
_migrate-new name: && _build _migrate-status
{{bin}}/{{entrypoint}} --migrate-create {{name}}
# Hard reset the database
[group('db')]
reset-db env='.env': _build
echo "⚠️ WARNING - This will DELETE ALL DATA!"
{{bin}}/{{entrypoint}} --reset-db --envfile {{env}}