From 3ad33655b0d226aff7eaa140d335bb6b69dd9f8b Mon Sep 17 00:00:00 2001 From: Sverre Nystad <89105607+SverreNystad@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:49:42 +0100 Subject: [PATCH 1/5] Feat: Create start_project.py --- start_project.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 start_project.py diff --git a/start_project.py b/start_project.py new file mode 100644 index 0000000..56a1624 --- /dev/null +++ b/start_project.py @@ -0,0 +1,21 @@ +import os +import subprocess +import sys + + +def start_django() -> None: + print("Starting Django backend...") + os.chdir('path/to/django_project') + subprocess.Popen([sys.executable, 'manage.py', 'runserver']) + +def start_react() -> None: + print("Starting React frontend...") + os.chdir('path/to/react_project') + if os.name == 'nt': # If the OS is Windows + subprocess.Popen('start npm start', shell=True) + else: + subprocess.Popen('npm start', shell=True) + +if __name__ == '__main__': + start_django() + start_react() From 638ea37b04275198fe8927d5aa80abfd15448004 Mon Sep 17 00:00:00 2001 From: Sverre Nystad <89105607+SverreNystad@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:51:44 +0100 Subject: [PATCH 2/5] Fix: Correct paths in start_project.py --- start_project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start_project.py b/start_project.py index 56a1624..cf58d6c 100644 --- a/start_project.py +++ b/start_project.py @@ -5,12 +5,12 @@ def start_django() -> None: print("Starting Django backend...") - os.chdir('path/to/django_project') + os.chdir('backend') subprocess.Popen([sys.executable, 'manage.py', 'runserver']) def start_react() -> None: print("Starting React frontend...") - os.chdir('path/to/react_project') + os.chdir('frontend') if os.name == 'nt': # If the OS is Windows subprocess.Popen('start npm start', shell=True) else: From 087e7a251110e239a3952b398abdb89c3083e01c Mon Sep 17 00:00:00 2001 From: Sverre Nystad Date: Wed, 27 Dec 2023 19:25:46 +0100 Subject: [PATCH 3/5] Feat: Create setup script --- start_project.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/start_project.py b/start_project.py index cf58d6c..d8126aa 100644 --- a/start_project.py +++ b/start_project.py @@ -1,20 +1,33 @@ import os import subprocess import sys +import logging + +# Set up logging +logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') +logger = logging.getLogger("start_project.py") def start_django() -> None: - print("Starting Django backend...") - os.chdir('backend') - subprocess.Popen([sys.executable, 'manage.py', 'runserver']) + logger.info("Starting Django backend...") + try: + os.chdir('backend') + subprocess.Popen([sys.executable, 'manage.py', 'runserver']) + except FileNotFoundError: + logger.error("Script manage.py not found. Are you sure you are in the root directory?") + sys.exit(1) + def start_react() -> None: - print("Starting React frontend...") - os.chdir('frontend') - if os.name == 'nt': # If the OS is Windows - subprocess.Popen('start npm start', shell=True) - else: - subprocess.Popen('npm start', shell=True) + logger.info("Starting React frontend...") + try: + os.chdir('frontend') + subprocess.Popen('npm run setup', shell=True) + subprocess.Popen('npm run dev', shell=True) + + except FileNotFoundError: + logger.error("Manifest package.json not found. Are you sure you are in the root directory?") + sys.exit(1) if __name__ == '__main__': start_django() From 612c6882713f3dc0868ff7710c20f55199bed0af Mon Sep 17 00:00:00 2001 From: Sverre Nystad Date: Wed, 27 Dec 2023 19:27:48 +0100 Subject: [PATCH 4/5] Docs: Add file documentation --- start_project.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/start_project.py b/start_project.py index d8126aa..8e1b090 100644 --- a/start_project.py +++ b/start_project.py @@ -1,3 +1,5 @@ +"""A setup script that starts the Django backend and React frontend in separate processes.""" + import os import subprocess import sys From 539906263c481506a86130ed546981e62ef8c62a Mon Sep 17 00:00:00 2001 From: Daniel N Hansen Date: Tue, 2 Jan 2024 10:39:20 +0100 Subject: [PATCH 5/5] Update start_project.py --- start_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start_project.py b/start_project.py index 8e1b090..f63e5e2 100644 --- a/start_project.py +++ b/start_project.py @@ -24,7 +24,7 @@ def start_react() -> None: logger.info("Starting React frontend...") try: os.chdir('frontend') - subprocess.Popen('npm run setup', shell=True) + subprocess.Popen('npm install', shell=True) subprocess.Popen('npm run dev', shell=True) except FileNotFoundError: