@@ -607,7 +607,33 @@ def check_for_toml_or_setup_file() -> str | None:
607607 curdir = Path .cwd ()
608608 pyproject_toml_path = curdir / "pyproject.toml"
609609 setup_py_path = curdir / "setup.py"
610+ package_json_path = curdir / "package.json"
610611 project_name = None
612+
613+ # Check if this might be a JavaScript/TypeScript project that wasn't detected
614+ if package_json_path .exists () and not pyproject_toml_path .exists () and not setup_py_path .exists ():
615+ js_redirect_panel = Panel (
616+ Text (
617+ f"📦 I found a package.json in { curdir } .\n \n "
618+ "This looks like a JavaScript/TypeScript project!\n "
619+ "Redirecting to JavaScript setup..." ,
620+ style = "cyan" ,
621+ ),
622+ title = "🟨 JavaScript Project Detected" ,
623+ border_style = "bright_yellow" ,
624+ )
625+ console .print (js_redirect_panel )
626+ console .print ()
627+ ph ("cli-js-project-redirect" )
628+
629+ # Redirect to JS init
630+ from codeflash .cli_cmds .init_javascript import ProjectLanguage , detect_project_language , init_js_project
631+
632+ project_language = detect_project_language ()
633+ if project_language in (ProjectLanguage .JAVASCRIPT , ProjectLanguage .TYPESCRIPT ):
634+ init_js_project (project_language )
635+ sys .exit (0 ) # init_js_project handles its own exit, but ensure we don't continue
636+
611637 if pyproject_toml_path .exists ():
612638 try :
613639 pyproject_toml_content = pyproject_toml_path .read_text (encoding = "utf8" )
@@ -617,28 +643,44 @@ def check_for_toml_or_setup_file() -> str | None:
617643 except Exception :
618644 click .echo ("✅ I found a pyproject.toml for your project." )
619645 ph ("cli-pyproject-toml-found" )
646+ elif setup_py_path .exists ():
647+ setup_py_content = setup_py_path .read_text (encoding = "utf8" )
648+ project_name_match = re .search (r"setup\s*\([^)]*?name\s*=\s*['\"](.*?)['\"]" , setup_py_content , re .DOTALL )
649+ if project_name_match :
650+ project_name = project_name_match .group (1 )
651+ click .echo (f"✅ Found setup.py for your project { project_name } " )
652+ ph ("cli-setup-py-found-name" )
653+ else :
654+ click .echo ("✅ Found setup.py." )
655+ ph ("cli-setup-py-found" )
620656 else :
621- if setup_py_path .exists ():
622- setup_py_content = setup_py_path .read_text (encoding = "utf8" )
623- project_name_match = re .search (r"setup\s*\([^)]*?name\s*=\s*['\"](.*?)['\"]" , setup_py_content , re .DOTALL )
624- if project_name_match :
625- project_name = project_name_match .group (1 )
626- click .echo (f"✅ Found setup.py for your project { project_name } " )
627- ph ("cli-setup-py-found-name" )
628- else :
629- click .echo ("✅ Found setup.py." )
630- ph ("cli-setup-py-found" )
631- toml_info_panel = Panel (
632- Text (
633- f"💡 No pyproject.toml found in { curdir } .\n \n "
634- "This file is essential for Codeflash to store its configuration.\n "
635- "Please ensure you are running `codeflash init` from your project's root directory." ,
636- style = "yellow" ,
637- ),
638- title = "📋 pyproject.toml Required" ,
639- border_style = "bright_yellow" ,
640- )
641- console .print (toml_info_panel )
657+ # No Python config files found - show appropriate message
658+ # Check again if this might be a JS project
659+ if package_json_path .exists ():
660+ js_hint_panel = Panel (
661+ Text (
662+ f"📦 I found a package.json but no pyproject.toml in { curdir } .\n \n "
663+ "If this is a JavaScript/TypeScript project, please run:\n "
664+ " codeflash init\n \n "
665+ "from the project root directory." ,
666+ style = "yellow" ,
667+ ),
668+ title = "🤔 Mixed Project?" ,
669+ border_style = "bright_yellow" ,
670+ )
671+ console .print (js_hint_panel )
672+ else :
673+ toml_info_panel = Panel (
674+ Text (
675+ f"💡 No pyproject.toml found in { curdir } .\n \n "
676+ "This file is essential for Codeflash to store its configuration.\n "
677+ "Please ensure you are running `codeflash init` from your project's root directory." ,
678+ style = "yellow" ,
679+ ),
680+ title = "📋 pyproject.toml Required" ,
681+ border_style = "bright_yellow" ,
682+ )
683+ console .print (toml_info_panel )
642684 console .print ()
643685 ph ("cli-no-pyproject-toml-or-setup-py" )
644686
@@ -1474,11 +1516,7 @@ def customize_codeflash_yaml_content(
14741516 return _customize_python_workflow_content (optimize_yml_content , git_root , benchmark_mode )
14751517
14761518
1477- def _customize_python_workflow_content (
1478- optimize_yml_content : str ,
1479- git_root : Path ,
1480- benchmark_mode : bool = False , # noqa: FBT001, FBT002
1481- ) -> str :
1519+ def _customize_python_workflow_content (optimize_yml_content : str , git_root : Path , benchmark_mode : bool = False ) -> str :
14821520 """Customize workflow content for Python projects."""
14831521 # Get dependency installation commands
14841522 toml_path = Path .cwd () / "pyproject.toml"
@@ -1513,11 +1551,7 @@ def _customize_python_workflow_content(
15131551
15141552
15151553# TODO:{claude} Refactor and move to support for language specific
1516- def _customize_js_workflow_content (
1517- optimize_yml_content : str ,
1518- git_root : Path ,
1519- benchmark_mode : bool = False , # noqa: FBT001, FBT002
1520- ) -> str :
1554+ def _customize_js_workflow_content (optimize_yml_content : str , git_root : Path , benchmark_mode : bool = False ) -> str :
15211555 """Customize workflow content for JavaScript/TypeScript projects."""
15221556 from codeflash .cli_cmds .init_javascript import (
15231557 get_js_codeflash_install_step ,
0 commit comments