|
99 | 99 | # ---------------------------------------------------------------------------- |
100 | 100 | # Build Javascript |
101 | 101 | # ---------------------------------------------------------------------------- |
| 102 | +def copy_js_files(source_dir: Path, destination: Path) -> None: |
| 103 | + if destination.exists(): |
| 104 | + shutil.rmtree(destination) |
| 105 | + destination.mkdir() |
| 106 | + |
| 107 | + for file in source_dir.iterdir(): |
| 108 | + if file.is_file(): |
| 109 | + shutil.copy(file, destination / file.name) |
| 110 | + else: |
| 111 | + copy_js_files(file, destination / file.name) |
| 112 | + |
| 113 | + |
102 | 114 | def build_javascript_first(build_cls: type): |
103 | 115 | class Command(build_cls): |
104 | 116 | def run(self): |
@@ -133,18 +145,12 @@ def run(self): |
133 | 145 | log.info("Copying @pyscript/core distribution") |
134 | 146 | pyscript_dist = js_dir / "node_modules" / "@pyscript" / "core" / "dist" |
135 | 147 | pyscript_static_dir = static_dir / "pyscript" |
136 | | - if not pyscript_static_dir.exists(): |
137 | | - pyscript_static_dir.mkdir() |
138 | | - for file in pyscript_dist.iterdir(): |
139 | | - shutil.copy(file, pyscript_static_dir / file.name) |
| 148 | + copy_js_files(pyscript_dist, pyscript_static_dir) |
140 | 149 |
|
141 | 150 | log.info("Copying Morphdom distribution") |
142 | 151 | morphdom_dist = js_dir / "node_modules" / "morphdom" / "dist" |
143 | 152 | morphdom_static_dir = static_dir / "morphdom" |
144 | | - if not morphdom_static_dir.exists(): |
145 | | - morphdom_static_dir.mkdir() |
146 | | - for file in morphdom_dist.iterdir(): |
147 | | - shutil.copy(file, morphdom_static_dir / file.name) |
| 153 | + copy_js_files(morphdom_dist, morphdom_static_dir) |
148 | 154 |
|
149 | 155 | log.info("Successfully built Javascript") |
150 | 156 | super().run() |
|
0 commit comments