2024-06-04 10:16:51 +02:00
# Load environment variables from .env file
i f n e q ( , $( wildcard ./.env ) )
include .env
export
e n d i f
2024-06-20 20:29:20 +02:00
i f e q ( $( OS ) , W i n d o w s _ N T )
MAIN_PATH = /tmp/bin/main.exe
2024-06-22 15:53:33 +02:00
SYNC_ASSETS_COMMAND = @go run github.com/makiuchi-d/arelo@v1.13.1 \
2024-06-20 20:29:20 +02:00
--target "./public" \
--pattern "**/*.js" \
--pattern "**/*.css" \
--delay "100ms" \
2024-06-22 15:53:33 +02:00
--templ generate --notify-proxy
2024-06-20 20:29:20 +02:00
e l s e
MAIN_PATH = tmp/bin/main
2024-06-22 15:53:33 +02:00
SYNC_ASSETS_COMMAND = @go run github.com/cosmtrek/air@v1.51.0 \
2024-06-20 20:29:20 +02:00
--build.cmd "templ generate --notify-proxy" \
--build.bin "true" \
--build.delay "100" \
--build.exclude_dir "" \
--build.include_dir "public" \
2024-06-22 15:53:33 +02:00
--build.include_ext "js,css" \
--screen.clear_on_rebuild true \
--log.main_only true
2024-06-20 20:29:20 +02:00
e n d i f
2024-06-04 10:16:51 +02:00
# run templ generation in watch mode to detect all .templ files and
# re-create _templ.txt files on change, then send reload event to browser.
# Default url: http://localhost:7331
2024-06-08 10:49:16 +02:00
templ :
2024-06-16 10:28:09 +02:00
@templ generate --watch --proxy= " http://localhost $( HTTP_LISTEN_ADDR) " --open-browser= false
2024-06-04 10:16:51 +02:00
# run air to detect any go file changes to re-build and re-run the server.
2024-06-08 10:49:16 +02:00
server :
2024-06-04 10:16:51 +02:00
@go run github.com/cosmtrek/air@v1.51.0 \
2024-06-20 20:29:20 +02:00
--build.cmd " go build --tags dev -o ${ MAIN_PATH } ./cmd/app/ " --build.bin " ${ MAIN_PATH } " --build.delay "100" \
2024-06-04 10:16:51 +02:00
--build.exclude_dir "node_modules" \
--build.include_ext "go" \
--build.stop_on_error "false" \
2024-06-22 15:53:33 +02:00
--misc.clean_on_exit true \
--screen.clear_on_rebuild true \
--log.main_only true
2024-06-04 10:16:51 +02:00
# run tailwindcss to generate the styles.css bundle in watch mode.
2024-06-12 18:28:55 +02:00
watch-assets :
2024-06-22 15:53:33 +02:00
@npx tailwindcss -i app/assets/app.css -o ./public/assets/styles.css --watch
2024-06-04 10:16:51 +02:00
# run esbuild to generate the index.js bundle in watch mode.
2024-06-12 20:02:44 +02:00
watch-esbuild :
2024-06-22 15:53:33 +02:00
@npx esbuild app/assets/index.js --bundle --outdir= public/assets --watch
2024-06-04 10:16:51 +02:00
# watch for any js or css change in the assets/ folder, then reload the browser via templ proxy.
2024-06-08 10:49:16 +02:00
sync_assets :
2024-06-20 20:29:20 +02:00
${ SYNC_ASSETS_COMMAND }
2024-06-04 10:16:51 +02:00
# start the application in development
dev :
2024-06-12 18:28:55 +02:00
@make -j5 templ server watch-assets watch-esbuild sync_assets
2024-06-08 10:49:16 +02:00
# build the application for production. This will compile your app
# to a single binary with all its assets embedded.
build :
2024-06-15 19:16:33 +02:00
@npx tailwindcss -i app/assets/app.css -o ./public/assets/styles.css
2024-06-12 20:02:44 +02:00
@npx esbuild app/assets/index.js --bundle --outdir= public/assets
2024-06-11 21:12:12 +02:00
@go build -o bin/app_prod cmd/app/main.go
@echo "compiled you application with all its assets to a single binary => bin/app_prod"
2024-06-04 10:16:51 +02:00
2024-06-06 10:04:51 +02:00
db-status :
2024-06-22 15:53:33 +02:00
@GOOSE_DRIVER= $( DB_DRIVER) GOOSE_DBSTRING = $( DB_NAME) go run github.com/pressly/goose/v3/cmd/goose@latest -dir= $( MIGRATION_DIR) status
2024-06-04 10:16:51 +02:00
2024-06-06 10:04:51 +02:00
db-reset :
2024-06-08 10:05:00 +02:00
@GOOSE_DRIVER= $( DB_DRIVER) GOOSE_DBSTRING = $( DB_NAME) go run github.com/pressly/goose/v3/cmd/goose@latest -dir= $( MIGRATION_DIR) reset
2024-06-04 10:16:51 +02:00
2024-06-07 11:26:58 +02:00
db-down :
2024-06-08 10:05:00 +02:00
@GOOSE_DRIVER= $( DB_DRIVER) GOOSE_DBSTRING = $( DB_NAME) go run github.com/pressly/goose/v3/cmd/goose@latest -dir= $( MIGRATION_DIR) down
2024-06-07 11:26:58 +02:00
2024-06-06 10:04:51 +02:00
db-up :
2024-06-08 10:05:00 +02:00
@GOOSE_DRIVER= $( DB_DRIVER) GOOSE_DBSTRING = $( DB_NAME) go run github.com/pressly/goose/v3/cmd/goose@latest -dir= $( MIGRATION_DIR) up
2024-06-06 10:04:51 +02:00
2024-06-11 21:12:12 +02:00
db-mig-create :
2024-06-08 10:05:00 +02:00
@GOOSE_DRIVER= $( DB_DRIVER) GOOSE_DBSTRING = $( DB_NAME) go run github.com/pressly/goose/v3/cmd/goose@latest -dir= $( MIGRATION_DIR) create $( filter-out $@ ,$( MAKECMDGOALS) ) sql
2024-06-07 09:23:06 +02:00
2024-06-06 10:04:51 +02:00
db-seed :
2024-06-22 15:53:33 +02:00
@go run cmd/scripts/seed/main.go