Browse Source

Add a setup script

adi-git-demo-rebase
Adi Thakral 1 year ago
parent
commit
4e8efcf56f
  1. 23
      README.md
  2. 1
      assets/client-server-interaction.drawio
  3. 3
      assets/client-server-interaction.svg
  4. 30
      common.sh
  5. 33
      dev.sh
  6. 42
      setup.sh

23
README.md

@ -0,0 +1,23 @@
## Architecture
![client-server interaction graph](./assets/client-server-interaction.svg)
## Dependencies
1. Node.js
1. npm
1. Python 3.6+
## Setup
For setting up the frontend, `setup.sh` will run `npm install` in the `frontend` folder.
For setting up the backend, `setup.sh` will initialize a new virtual environment and setup a dummy sqlite file for testing purposes.
## Dev
Run `setup.sh` and then run `dev.sh`
## Production
TODO

1
assets/client-server-interaction.drawio

@ -0,0 +1 @@
<mxfile host="www.draw.io" modified="2021-03-15T04:26:06.589Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36" etag="t9BACponPf5-u58TPj24" version="14.4.8" type="device"><diagram id="nWxgDZutG5X04Ajf33Mw" name="Page-1">7Vxdc5s4FP01mek+xANCQvCYj6Y7u9mms8lMk75hkG0aDC7gON5fv5KRAEnEXwHWdjadacwFCbjn6tyrIzln1tX09UvqzSZ/JQGJzoARvJ5Z12cAmLbj0l/MsiwsLsSFYZyGAb+oMtyH/xBuNLh1HgYkky7MkyTKw5ls9JM4Jn4u2bw0TRbyZaMkku8688ZEM9z7XqRbv4dBPimsDjIq++8kHE/EnU2Dn5l64mJuyCZekCxqJuvzmXWVJklefJq+XpGIOU/4pWh388bZ8sFSEufbNHAW3398dR8unhz88HD7GP78sZifW0UvL1405y98G8bPGTWRIMyTVHioeIN8KdySJvM4IKxn88y6XEzCnNzPPJ+dXdBAoLZJPo346VEYRVdJRHtjba3AI87Ip/YsT5NnUjtj+w4ZjugZ/d34676QNCevNRN/1y8kmZI8XdJL+FnbRUUTHnhYQLaoYDQFNpMahDa3eTxyxmXXlXPpB+7fHXyNNF/73mhEwlh3L42VGfvoz4dks3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qkP+iDXhcMZ5sso8YIDjdM2cp2gUcEmUK9gYJNoBTuLS32BdfdcV077XUdM8/kCBE0//U37DyzXqYUN2jfXOeo8W+2opVyn3gfxQqjbXKdLWYCxtXH35+nyABJNhKcb8lO/Exl9DfLSo+kmDvTE8mm2zCdJrE9JDm5TwGgE/MaFiMAe2qitWkNZ/If2lgsRlP27InVdKNif1GVC33JF+ZzCBMp5EBeV7U2LGC1rYTy1HZkMDNW0oc5s9l1XRqCbtKGsg2MbrX0sWxWNQQ9JRtdpdh8Q+y7NNY6kN4cRbr8u2lYTtv4fB+8ZB4qGDZC99rGUy7Hbg4IMdGWrVJDFfkqhFRifvHlOp6KsTMpJcMIKJLSABIWNgJbBgViR6KUcs/RdM9voyiWEH2EfX+l9jprTpPE01l2doabLdtfL2JsyH0XsycckJikbTGeFtJNVcoyk9p8uaBaUQcMG1EHrVewXY78dAaSsj9cneXn35cAtdktUNYUD99p/sX+JsG2pfGASi1YjqKl93xqhs+UEZbJo4x6qX0vX+LSs/3GyPXBdmYKgTkE9Z/s2d3PRiTdWJt5bbGlZv5vLdZ06rQ1c2/0PZN0jm7+o8q+tavgHx00iF5e5uQ9u0mfm2a+I0oA2Akp1cRmx8ja1WpQYM778iBpERMcnzSLi0EEQtURKplLMogZSatov7nTGSft+KSWj0ZhvR1VMJDSgzFXQcd7DVabEUxvEylZZSgTysZVQpqLHIaSo0tvSFFBXj9SN9m/QVFtMAvXZ185ZVN2KUN8jbQA5Uq337pF2d5kstBurxxmqGMskaaM9MypS2NZ2twvV3RdU5S8zILuHjApbmNBq46Da8mzYMsWacOfArdWqWP7iwYYBtX/EH2kNCZWIx/vWkH1FPFa25SG3h2/DQH1+W21+2ixrCwluPgu4NvfH/d3XFXj+Czscpcm0ubODnCPXBy9oSbbDanmqa63Q6lO2E5Orj71txNVhaGnbCD2s/vJHMVCrv59iff4X</diagram></mxfile>

3
assets/client-server-interaction.svg

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 26 KiB

30
common.sh

@ -0,0 +1,30 @@
#!/usr/bin/env bash
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'
function prefix_stdout_stderr() {
exec > >(trap "" INT TERM; sed "s/^/`printf "$1"`/")
exec 2> >(trap "" INT TERM; sed "s/^/`printf "$1"`/" >&2)
}
function run_frontend_backend() {
$1 &
pid_frontend=$!
$2 &
pid_backend=$!
trap_ctrlc() {
echo ""
kill $pid_frontend
echo "frontend exit code: $?"
kill $pid_backend
echo "backend exit code: $?"
}
trap trap_ctrlc INT
wait
}

33
dev.sh

@ -1,15 +1,10 @@
#!/usr/bin/env bash
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'
set -e
function prefix_stdout_stderr() {
exec > >(trap "" INT TERM; sed "s/^/`printf "$1"`/")
exec 2> >(trap "" INT TERM; sed "s/^/`printf "$1"`/" >&2)
}
source ./common.sh
function start_frontend() {
function dev_frontend() {
prefix_stdout_stderr "${PURPLE}frontend: ${NC}"
cd ./frontend
@ -17,31 +12,13 @@ function start_frontend() {
npm run dev
}
function start_backend() {
function dev_backend() {
prefix_stdout_stderr "${CYAN}backend: ${NC}"
cd ./backend
source venv/bin/activate
echo $(which python)
python main.py
}
start_frontend &
pid_frontend=$!
start_backend &
pid_backend=$!
trap_ctrlc() {
echo ""
kill $pid_frontend
echo "frontend exit code: $?"
kill $pid_backend
echo "backend exit code: $?"
}
trap trap_ctrlc INT
wait
run_frontend_backend "dev_frontend" "dev_backend"

42
setup.sh

@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -e
source ./common.sh
function setup_frontend() {
prefix_stdout_stderr "${PURPLE}frontend: ${NC}"
cd ./frontend
echo "Installing dependencies..."
npm i
echo "Done!"
}
function setup_backend() {
prefix_stdout_stderr "${CYAN}backend: ${NC}"
cd ./backend
echo "Deleting old virtual environment..."
rm -rf ./venv
echo "Deleting sqlite database..."
rm ./links.db
echo "Creating new virtual environment..."
python3 -m venv venv
source venv/bin/activate
echo "Installing dependencies..."
pip install -r requirements.txt
echo "Creating a dummy sqlite database at 'backend/links.db'..."
python setup_db.py
echo "Done!"
}
run_frontend_backend "setup_frontend" "setup_backend"
Loading…
Cancel
Save