66import sys
77import subprocess
88from pathlib import Path
9+ import yaml
910
1011# Add utils to path
1112sys .path .insert (0 , str (Path (__file__ ).parent .parent ))
1415from utils .system import ProjectDetector , BuildSystem
1516from utils .config import config
1617
18+ def load_project_config (project_root ):
19+ """Load project configuration from fern.yaml"""
20+ config_file = project_root / "fern.yaml"
21+ if not config_file .exists ():
22+ return None
23+
24+ try :
25+ with open (config_file , 'r' ) as f :
26+ return yaml .safe_load (f )
27+ except Exception as e :
28+ print_warning (f"Failed to load fern.yaml: { e } " )
29+ return None
30+
1731class FireCommand :
1832 """Run Fern code - single file or project"""
1933
@@ -88,6 +102,13 @@ def _run_project(self, platform="linux"):
88102
89103 print_info (f"Found Fern project at: { project_root } " )
90104
105+ # Load project configuration
106+ project_config = load_project_config (project_root )
107+ if project_config :
108+ print_info ("Loaded project configuration from fern.yaml" )
109+ else :
110+ print_warning ("No fern.yaml configuration found, using defaults" )
111+
91112 # Get project structure
92113 structure = ProjectDetector .get_project_structure (project_root )
93114
@@ -243,10 +264,12 @@ def _build_project_web(self, build_system, main_file):
243264
244265 potential_sources = [
245266 cli_dir , # The Fern repository root where the CLI is located
267+ Path ("/home/rishi/git/test/fern" ), # Hardcoded development path
246268 Path (os .getcwd ()), # Current working directory (if run from Fern repo)
247269 Path (os .environ .get ('ORIGINAL_CWD' , os .getcwd ())).parent , # Parent of original working dir
248270 Path ("/usr/local/src/fern" ), # System-wide source location
249- Path .home () / ".fern" / "src" # User source backup
271+ Path .home () / ".fern" / "src" , # User source backup
272+ Path .home () / ".fern" # Alternative user location
250273 ]
251274
252275 for src_path in potential_sources :
@@ -416,6 +439,7 @@ def _build_single_file_web(self, file_path):
416439
417440 potential_sources = [
418441 cli_dir , # The Fern repository root where the CLI is located
442+ Path ("/home/rishi/git/test/fern" ), # Hardcoded development path
419443 Path (os .getcwd ()), # Current working directory (if run from Fern repo)
420444 Path (os .environ .get ('ORIGINAL_CWD' , os .getcwd ())).parent , # Parent of original working dir
421445 Path ("/usr/local/src/fern" ), # System-wide source location
@@ -488,24 +512,30 @@ def _build_single_file_web(self, file_path):
488512 except Exception as e :
489513 print_error (f"Web build error: { str (e )} " )
490514 return False
491-
515+
492516 def _run_web_project (self , project_root ):
493517 """Run web project by starting a local server"""
494518 try :
495519 build_dir = project_root / "build"
496520 html_file = build_dir / "main.html"
497-
521+
498522 if not html_file .exists ():
499523 print_error (f"Web build not found: { html_file } " )
500524 return
501-
525+
526+ # Load project configuration to get port
527+ project_config = load_project_config (project_root )
528+ port = 8000 # default port
529+ if project_config and 'platforms' in project_config and 'web' in project_config ['platforms' ]:
530+ port = project_config ['platforms' ]['web' ].get ('port' , 8000 )
531+
502532 print_info ("Starting local web server..." )
503533 print_success ("🔥 Fern Fire started (web)!" )
504534 print ()
505- print_info (f"Open your browser to: http://localhost:8000 /main.html" )
535+ print_info (f"Open your browser to: http://localhost:{ port } /main.html" )
506536 print_info ("Press Ctrl+C to stop the server" )
507537 print ()
508-
538+
509539 # Start simple HTTP server
510540 import http .server
511541 import socketserver
@@ -516,15 +546,15 @@ def _run_web_project(self, project_root):
516546 os .chdir (build_dir )
517547
518548 def start_server ():
519- with socketserver .TCPServer (("" , 8000 ), http .server .SimpleHTTPRequestHandler ) as httpd :
549+ with socketserver .TCPServer (("" , port ), http .server .SimpleHTTPRequestHandler ) as httpd :
520550 httpd .serve_forever ()
521-
551+
522552 server_thread = threading .Thread (target = start_server , daemon = True )
523553 server_thread .start ()
524-
554+
525555 # Wait a moment then open browser
526556 time .sleep (1 )
527- webbrowser .open ("http://localhost:8000 /main.html" )
557+ webbrowser .open (f "http://localhost:{ port } /main.html" )
528558
529559 # Keep running until interrupted
530560 try :
@@ -535,23 +565,31 @@ def start_server():
535565
536566 except Exception as e :
537567 print_error (f"Error running web project: { str (e )} " )
538-
568+
539569 def _run_web_file (self , file_path ):
540570 """Run web file by starting a local server"""
541571 try :
542572 # Get original working directory for build location
543573 original_cwd = os .environ .get ('ORIGINAL_CWD' , os .getcwd ())
544574 build_dir = Path (original_cwd ) / "build"
545575 html_file = build_dir / (file_path .stem + "_temp.html" )
546-
576+
547577 if not html_file .exists ():
548578 print_error (f"Web build not found: { html_file } " )
549579 return
550-
580+
581+ # Try to load project config for port, fallback to default
582+ project_root = ProjectDetector .find_project_root ()
583+ port = 8000 # default port
584+ if project_root :
585+ project_config = load_project_config (project_root )
586+ if project_config and 'platforms' in project_config and 'web' in project_config ['platforms' ]:
587+ port = project_config ['platforms' ]['web' ].get ('port' , 8000 )
588+
551589 print_info ("Starting local web server..." )
552590 print_success ("🔥 Fern Fire started (web)!" )
553591 print ()
554- print_info (f"Open your browser to: http://localhost:8000 /{ html_file .name } " )
592+ print_info (f"Open your browser to: http://localhost:{ port } /{ html_file .name } " )
555593 print_info ("Press Ctrl+C to stop the server" )
556594 print ()
557595
@@ -565,15 +603,15 @@ def _run_web_file(self, file_path):
565603 os .chdir (build_dir )
566604
567605 def start_server ():
568- with socketserver .TCPServer (("" , 8000 ), http .server .SimpleHTTPRequestHandler ) as httpd :
606+ with socketserver .TCPServer (("" , port ), http .server .SimpleHTTPRequestHandler ) as httpd :
569607 httpd .serve_forever ()
570-
608+
571609 server_thread = threading .Thread (target = start_server , daemon = True )
572610 server_thread .start ()
573-
611+
574612 # Wait a moment then open browser
575613 time .sleep (1 )
576- webbrowser .open (f"http://localhost:8000 /{ html_file .name } " )
614+ webbrowser .open (f"http://localhost:{ port } /{ html_file .name } " )
577615
578616 # Keep running until interrupted
579617 try :
0 commit comments