Skip to content

Commit

Permalink
feat: Add prodrun.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
romshark committed Nov 20, 2024
1 parent ec24a7c commit 8624f3d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
31 changes: 19 additions & 12 deletions buildall.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
echo "\n--- Bun Install"
bun i
#!/bin/bash

echo "\n--- Build Components"
bun run build:components
run() {
echo -e "\n--- $1"
$2
if [ $? -ne 0 ]; then
echo "$1 failed."
exit 1
fi
}

echo "\n--- Build TypeScript"
bun run build:ts

echo "\n--- Build CSS"
bun run build:css

echo "\n--- Generate Templ Templates"
templ generate
run "Bun Install"\
"bun i"
run "Build Components"\
"bun run build:components"
run "Build TypeScript"\
"bun run build:ts"
run "Build CSS"\
"bun run build:css"
run "Generate Templ Templates"\
"templ generate"
16 changes: 6 additions & 10 deletions dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ if [ ! -d "node_modules" ]; then
bun i
fi

echo "\n--- Build Components"
bun run build:components

echo "\n--- Build TypeScript"
bun run build:ts

echo "\n--- Build CSS"
bun run build:css
./buildall.sh
if [ $? -ne 0 ]; then
echo "building generated files failed"
exit 1
fi

echo "\n--- Generate Templ Templates"
templ generate
clear

# DEV="true" sets the env var to enable development mode in the app server.
DEV="true" go run github.com/romshark/templier
40 changes: 40 additions & 0 deletions prodrun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

# This helper script runs the server in production mode.

if ! grep -q "^127\.0\.0\.1[[:space:]]\+islands\.demo" /etc/hosts; then
echo 'Please add "127.0.0.1 islands.demo" to your hosts file (usually /etc/hosts)'
exit 1
fi

./buildall.sh
if [ $? -ne 0 ]; then
echo "building generated files failed"
exit 1
fi

mkcert -install
mkcert islands.demo

# Create a temporary executable file
TEMP_BIN=$(mktemp)

# Compile the server
go build -o "$TEMP_BIN" ./cmd/server
if [ $? -ne 0 ]; then
echo "Compilation failed."
exit 1
fi

clear

# Run the server
TLS_CERT="islands.demo.pem" TLS_KEY="islands.demo-key.pem" \
$TEMP_BIN -compress -host islands.demo:443
RUN_EXIT_CODE=$?

# Clean up the temp executable
rm -f "$TEMP_BIN"

# Exit with the same status code as the server
exit $RUN_EXIT_CODE

0 comments on commit 8624f3d

Please sign in to comment.