forked from reactive-python/reactpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_js_dir.py
More file actions
50 lines (41 loc) · 1.66 KB
/
clean_js_dir.py
File metadata and controls
50 lines (41 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
# Deletes `dist`, `node_modules`, and `tsconfig.tsbuildinfo` from all JS packages in the JS source directory.
import contextlib
import glob
import os
import pathlib
import shutil
print("Cleaning JS source directory...") # noqa: T201
# Get the path to the JS source directory
js_src_dir = pathlib.Path(__file__).parent.parent / "js"
static_output_dir = pathlib.Path(__file__).parent.parent / "reactpy" / "static"
# Delete all `dist` folders
dist_dirs = glob.glob(str(js_src_dir / "**/dist"), recursive=True)
for dist_dir in dist_dirs:
with contextlib.suppress(FileNotFoundError):
shutil.rmtree(dist_dir)
# Delete all `*.tgz` files in `packages/**`
dist_tgz_files = glob.glob(str(js_src_dir / "**/*.tgz"), recursive=True)
for dist_tgz_file in dist_tgz_files:
with contextlib.suppress(FileNotFoundError):
os.remove(dist_tgz_file)
# Delete all `node_modules` folders
node_modules_dirs = glob.glob(str(js_src_dir / "**/node_modules"), recursive=True)
for node_modules_dir in node_modules_dirs:
with contextlib.suppress(FileNotFoundError):
shutil.rmtree(node_modules_dir)
# Delete all `tsconfig.tsbuildinfo` files
tsconfig_tsbuildinfo_files = glob.glob(
str(js_src_dir / "**/tsconfig.tsbuildinfo"), recursive=True
)
for tsconfig_tsbuildinfo_file in tsconfig_tsbuildinfo_files:
with contextlib.suppress(FileNotFoundError):
os.remove(tsconfig_tsbuildinfo_file)
# Delete all `index-*.js` files
index_js_files = glob.glob(str(static_output_dir / "index-*.js*"))
for index_js_file in index_js_files:
with contextlib.suppress(FileNotFoundError):
os.remove(index_js_file)