diff --git a/package.json b/package.json index dcff7e8e..c9196c33 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "dev:worker:feeds:inner": "dotenv -e .env.local -- concurrently -k -n WORKER -c green \"tsup --watch --onSuccess='node dist/workers/feed-worker.js'\"", "dev:mock": "USE_MOCK_REPOS=true USE_FAKE_PUBLISHERS=true USE_MOCK_AUTH=true npm run dev:inner", "dev:mock:pub:auth": "USE_FAKE_PUBLISHERS=true USE_MOCK_AUTH=true npm run dev", - "dev": "concurrently -k -n APP,WORKER -c blue,green \"bash ./scripts/dev-feed-worker.sh\" \"bash ./scripts/dev.sh\"", + "dev": "bash ./scripts/dev-combined.sh", "migrate": "node dist/scripts/migrate.js", "lexgen": "lex gen-server ./src/modules/atproto/infrastructure/lexicon ./src/modules/atproto/infrastructure/lexicons/*", "db:start": "docker run --name annos-postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=annotations -p 5432:5432 -d postgres:14", diff --git a/scripts/dev-combined.sh b/scripts/dev-combined.sh new file mode 100644 index 00000000..232aaef6 --- /dev/null +++ b/scripts/dev-combined.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Source both setup scripts +source ./scripts/setup-postgres.sh +source ./scripts/setup-redis.sh + +# Function to handle cleanup for both services +cleanup_and_exit() { + echo "Cleaning up services..." + cleanup_postgres + cleanup_redis + exit 0 +} + +# Trap SIGINT and SIGTERM to cleanup on exit +trap cleanup_and_exit SIGINT SIGTERM + +# Run both services with concurrently +concurrently -k -n APP,WORKER -c blue,green \ + "dotenv -e .env.local -- concurrently -k -n TYPE,APP -c red,blue \"tsc --noEmit --watch\" \"tsup --watch --onSuccess='node dist/index.js'\"" \ + "dotenv -e .env.local -- concurrently -k -n WORKER -c green \"tsup --watch --onSuccess='node dist/workers/feed-worker.js'\"" + +# Cleanup after concurrently exits +cleanup_postgres +cleanup_redis diff --git a/scripts/dev-feed-worker.sh b/scripts/dev-feed-worker.sh index 6afae5f5..ef5374a9 100644 --- a/scripts/dev-feed-worker.sh +++ b/scripts/dev-feed-worker.sh @@ -3,18 +3,23 @@ # Source the Redis setup script source ./scripts/setup-redis.sh -# Function to handle cleanup -cleanup_and_exit() { - echo "Cleaning up Redis..." - cleanup_redis - exit 0 -} +# Only setup cleanup if not running from combined script +if [ -z "$COMBINED_SCRIPT" ]; then + # Function to handle cleanup + cleanup_and_exit() { + echo "Cleaning up Redis..." + cleanup_redis + exit 0 + } -# Trap SIGINT and SIGTERM to cleanup on exit -trap cleanup_and_exit SIGINT SIGTERM + # Trap SIGINT and SIGTERM to cleanup on exit + trap cleanup_and_exit SIGINT SIGTERM +fi # Run the feed worker dev command npm run dev:worker:feeds:inner -# Cleanup after dev command exits -cleanup_redis +# Only cleanup if not running from combined script +if [ -z "$COMBINED_SCRIPT" ]; then + cleanup_redis +fi diff --git a/scripts/dev.sh b/scripts/dev.sh index 75ab0343..966ec6ec 100644 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -3,18 +3,23 @@ # Source the Postgres setup script source ./scripts/setup-postgres.sh -# Function to handle cleanup -cleanup_and_exit() { - echo "Cleaning up Postgres..." - cleanup_postgres - exit 0 -} +# Only setup cleanup if not running from combined script +if [ -z "$COMBINED_SCRIPT" ]; then + # Function to handle cleanup + cleanup_and_exit() { + echo "Cleaning up Postgres..." + cleanup_postgres + exit 0 + } -# Trap SIGINT and SIGTERM to cleanup on exit -trap cleanup_and_exit SIGINT SIGTERM + # Trap SIGINT and SIGTERM to cleanup on exit + trap cleanup_and_exit SIGINT SIGTERM +fi # Run the dev command npm run dev:app:inner -# Cleanup after dev command exits -cleanup_postgres +# Only cleanup if not running from combined script +if [ -z "$COMBINED_SCRIPT" ]; then + cleanup_postgres +fi