Forráskód Böngészése

do not delete the .web dir when init-ing (#5319)

Khaleel Al-Adhami 1 hete
szülő
commit
59bbdcdc70
3 módosított fájl, 28 hozzáadás és 8 törlés
  1. 1 1
      reflex/utils/build.py
  2. 26 6
      reflex/utils/path_ops.py
  3. 1 1
      reflex/utils/prerequisites.py

+ 1 - 1
reflex/utils/build.py

@@ -230,7 +230,7 @@ def setup_frontend(
     """
     # Create the assets dir if it doesn't exist.
     path_ops.mkdir(constants.Dirs.APP_ASSETS)
-    path_ops.cp(
+    path_ops.copy_tree(
         src=str(root / constants.Dirs.APP_ASSETS),
         dest=str(root / prerequisites.get_web_dir() / constants.Dirs.PUBLIC),
         ignore=tuple(f"*.{ext}" for ext in constants.Reflex.STYLESHEETS_SUPPORTED),

+ 26 - 6
reflex/utils/path_ops.py

@@ -42,6 +42,31 @@ def rm(path: str | Path):
         path.unlink()
 
 
+def copy_tree(
+    src: str | Path,
+    dest: str | Path,
+    ignore: tuple[str, ...] | None = None,
+):
+    """Copy a directory tree.
+
+    Args:
+        src: The path to the source directory.
+        dest: The path to the destination directory.
+        ignore: Ignoring files and directories that match one of the glob-style patterns provided
+    """
+    src = Path(src)
+    dest = Path(dest)
+    if dest.exists():
+        for item in dest.iterdir():
+            rm(item)
+    shutil.copytree(
+        src,
+        dest,
+        ignore=shutil.ignore_patterns(*ignore) if ignore is not None else ignore,
+        dirs_exist_ok=True,
+    )
+
+
 def cp(
     src: str | Path,
     dest: str | Path,
@@ -65,12 +90,7 @@ def cp(
     if not overwrite and dest.exists():
         return False
     if src.is_dir():
-        rm(dest)
-        shutil.copytree(
-            src,
-            dest,
-            ignore=shutil.ignore_patterns(*ignore) if ignore is not None else ignore,
-        )
+        copy_tree(src, dest, ignore)
     else:
         shutil.copyfile(src, dest)
     return True

+ 1 - 1
reflex/utils/prerequisites.py

@@ -980,7 +980,7 @@ def initialize_web_directory():
     project_hash = get_project_hash()
 
     console.debug(f"Copying {constants.Templates.Dirs.WEB_TEMPLATE} to {get_web_dir()}")
-    path_ops.cp(constants.Templates.Dirs.WEB_TEMPLATE, str(get_web_dir()))
+    path_ops.copy_tree(constants.Templates.Dirs.WEB_TEMPLATE, str(get_web_dir()))
 
     console.debug("Initializing the web directory.")
     initialize_package_json()