From 934ba77ae447a779c8608c89da2aaeb68eaae0f3 Mon Sep 17 00:00:00 2001 From: alicia yu Date: Mon, 12 Aug 2024 12:38:07 -0700 Subject: [PATCH] Add scripts to run locally --- README.md | 11 +++- .../{run_all_tasks.sh => run_all_deploy.sh} | 0 scripts/run_all_local.sh | 54 +++++++++++++++++++ scripts/start_local.sh | 26 +++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) rename scripts/{run_all_tasks.sh => run_all_deploy.sh} (100%) create mode 100755 scripts/run_all_local.sh create mode 100755 scripts/start_local.sh diff --git a/README.md b/README.md index 264dfa5..4120080 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ The scripts cover: > [!WARNING] > Always make sure you `git fetch` the latest changes.\ > NPM Install must be executed in `both frontend and server` directories to be able to deploy on fly.io successfully. +> In the server directory, make sure you create an `.env` file and set the variable `OPENAI_API_KEY` to your OpenAI API key. ## Scripts @@ -23,10 +24,18 @@ This script installs NPM dependencies for both the `frontend` and `server` compo This script deploys both the `frontend` and `server` components to `Fly.io.` -### 3. `run_all_tasks.sh` +### 3. `run_all_deploy.sh` This script performs both the `NPM installation` and `Fly.io deployment` tasks sequentially. It installs dependencies for both frontend and server, then deploys them. +### 4. `start_local.sh` + +This script starts both the `frontend` and `server` components on a local machine using two different ports. + +### 4. `run_all_local.sh` + +This script performs both the `NPM installation` and `start locally` tasks sequentially. It installs dependencies for both frontend and server, then starts both components locally. + ### **Usage**: 1. Open your terminal. 2. Navigate to the `scripts` directory: diff --git a/scripts/run_all_tasks.sh b/scripts/run_all_deploy.sh similarity index 100% rename from scripts/run_all_tasks.sh rename to scripts/run_all_deploy.sh diff --git a/scripts/run_all_local.sh b/scripts/run_all_local.sh new file mode 100755 index 0000000..ab98fe5 --- /dev/null +++ b/scripts/run_all_local.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +#define the server and client directories +SERVER="../server" +FRONTEND="../frontend" + +#check if a port is available +check_port() { + PORT=$1 + nc -z localhost $PORT + if [ $? -eq 0 ]; then + echo "Port $PORT is in use" + exit 1 + fi +} + +#install dependencies and start the server +start_server() { + echo "Navigating to server directory: $SERVER" + cd $SERVER || { echo "Server directory not found!"; exit 1;} + + echo "Installing dependencies..." + npm install + + #check if port 3000 is available + check_port 3000 + + + + echo "Starting server..." + node server.js +} + +#install dependencies and start the frontend +start_frontend() { + echo "Navigating to client directory: $FRONTEND" + cd $FRONTEND || { echo "Frontend directory not found!"; exit 1; } + + echo "Installing dependencies..." + npm install + + echo "Starting frontend..." + + TEST_PORT=3001 + check_port TEST_PORT + while [ $? -eq 1 ]; do + TEST_PORT=$((TEST_PORT+1)) + check_port TEST_PORT + done + PORT=TEST_PORT npm start +} + +#run the server and frontend +start_server & start_frontend \ No newline at end of file diff --git a/scripts/start_local.sh b/scripts/start_local.sh new file mode 100755 index 0000000..b47f855 --- /dev/null +++ b/scripts/start_local.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +#define frontend and server directories +SERVER="../server" +FRONTEND="../frontend" + +#start the server +start_server() { + echo "Navigating to server directory: $SERVER" + cd $SERVER || { echo "Server directory not found!"; exit 1;} + + echo "Starting server..." + node server.js +} + +#start the frontend +start_frontend() { + echo "Navigating to client directory: $FRONTEND" + cd $FRONTEND || { echo "Frontend directory not found!"; exit 1; } + + echo "Starting frontend..." + PORT=3001 npm start +} + +#run the server and frontend +start_server & start_frontend