|
|
|
|
|
""" |
|
|
Lin - Community Manager Assistant for LinkedIn |
|
|
Universal startup script for development servers |
|
|
""" |
|
|
import os |
|
|
import sys |
|
|
import subprocess |
|
|
import platform |
|
|
from pathlib import Path |
|
|
|
|
|
def is_windows(): |
|
|
"""Check if the current OS is Windows""" |
|
|
return platform.system().lower() == 'windows' |
|
|
|
|
|
def run_command(command, cwd=None, shell=False): |
|
|
"""Run a command and stream output""" |
|
|
try: |
|
|
|
|
|
use_shell = shell or is_windows() |
|
|
|
|
|
process = subprocess.Popen( |
|
|
command, |
|
|
cwd=cwd, |
|
|
shell=use_shell, |
|
|
stdout=subprocess.PIPE, |
|
|
stderr=subprocess.STDOUT, |
|
|
text=True, |
|
|
bufsize=1, |
|
|
universal_newlines=True |
|
|
) |
|
|
|
|
|
|
|
|
for line in process.stdout: |
|
|
print(line, end='') |
|
|
|
|
|
process.wait() |
|
|
return process.returncode == 0 |
|
|
except Exception as e: |
|
|
print(f"Error running command: {e}") |
|
|
return False |
|
|
|
|
|
def start_frontend(): |
|
|
"""Start the React frontend development server""" |
|
|
print("Starting frontend development server...") |
|
|
if is_windows(): |
|
|
cmd = "npm run dev:frontend" |
|
|
else: |
|
|
cmd = ["npm", "run", "dev:frontend"] |
|
|
return run_command(cmd, shell=True) |
|
|
|
|
|
def start_backend(): |
|
|
"""Start the Flask backend server""" |
|
|
print("Starting backend server...") |
|
|
|
|
|
|
|
|
env = os.environ.copy() |
|
|
|
|
|
env["PYTHONPATH"] = str(Path(__file__).parent) |
|
|
|
|
|
try: |
|
|
|
|
|
process = subprocess.Popen( |
|
|
[sys.executable, "app.py"], |
|
|
cwd=Path(__file__).parent, |
|
|
env=env, |
|
|
stdout=subprocess.PIPE, |
|
|
stderr=subprocess.STDOUT, |
|
|
text=True, |
|
|
bufsize=1, |
|
|
universal_newlines=True |
|
|
) |
|
|
|
|
|
|
|
|
for line in process.stdout: |
|
|
print(line, end='') |
|
|
|
|
|
process.wait() |
|
|
return process.returncode == 0 |
|
|
except Exception as e: |
|
|
print(f"Error starting backend: {e}") |
|
|
return False |
|
|
|
|
|
def start_all(): |
|
|
"""Start both frontend and backend using npm concurrently script""" |
|
|
print("Starting both frontend and backend servers...") |
|
|
|
|
|
if is_windows(): |
|
|
cmd = "cd frontend && npx concurrently \"npm run dev:frontend\" \"npm run dev:backend\"" |
|
|
else: |
|
|
cmd = "cd frontend && npx concurrently \"npm run dev:frontend\" \"npm run dev:backend\"" |
|
|
return run_command(cmd, shell=True) |
|
|
|
|
|
def show_help(): |
|
|
"""Display usage information""" |
|
|
help_text = """ |
|
|
Lin Development Launcher |
|
|
|
|
|
Usage: |
|
|
python starty.py [command] |
|
|
|
|
|
Commands: |
|
|
backend Start only the backend server (default) |
|
|
frontend Start only the frontend development server |
|
|
dev:all Start both frontend and backend servers |
|
|
help Show this help message |
|
|
|
|
|
Examples: |
|
|
python starty.py # Start backend server |
|
|
python starty.py backend # Start backend server |
|
|
python starty.py frontend # Start frontend server |
|
|
python starty.py dev:all # Start both servers |
|
|
""" |
|
|
print(help_text) |
|
|
|
|
|
def main(): |
|
|
"""Main entry point""" |
|
|
|
|
|
project_root = Path(__file__).parent |
|
|
os.chdir(project_root) |
|
|
|
|
|
if len(sys.argv) < 2: |
|
|
|
|
|
start_backend() |
|
|
return |
|
|
|
|
|
command = sys.argv[1].lower() |
|
|
|
|
|
if command in ['help', '--help', '-h']: |
|
|
show_help() |
|
|
elif command == 'frontend': |
|
|
start_frontend() |
|
|
elif command == 'backend': |
|
|
start_backend() |
|
|
elif command in ['dev:all', 'all', 'both']: |
|
|
|
|
|
|
|
|
start_all() |
|
|
else: |
|
|
print(f"Unknown command: {command}") |
|
|
show_help() |
|
|
sys.exit(1) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |