-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove_invalids.py
66 lines (54 loc) · 2.37 KB
/
remove_invalids.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import re
import os
# File paths (adjust these paths as necessary)
selector_file_path = r"../lib/selectors/selectorPlaceholders.scss"
scss_directory = r"../src/"
# List of files to ignore
ignore_files = {
r"..\ClearVision-v6\src\defaultSettings.scss",
r"..\ClearVision-v6\src\defaultSettings.scss",
r"..\ClearVision-v6\src\fixespt2.scss",
r"..\ClearVision-v6\src\functions.scss",
r"..\ClearVision-v6\src\keyframes.scss",
r"..\ClearVision-v6\src\mixins.scss",
r"..\ClearVision-v6\src\variables.scss"
}
# Step 1: Extract all placeholders from selectorPlaceholders.scss
valid_placeholders = set()
with open(selector_file_path, 'r', encoding='utf-8') as file:
content = file.read()
placeholder_pattern = re.compile(r"(%[\w-]+)")
valid_placeholders.update(placeholder_pattern.findall(content))
# Define a function to remove invalid placeholders
def remove_invalid_placeholders(content, valid_placeholders):
placeholder_pattern = re.compile(r"(%[\w-]+)")
def placeholder_replacement(match):
placeholder = match.group(1)
# Only keep placeholders that exist in the valid list
return placeholder if placeholder in valid_placeholders else ""
return placeholder_pattern.sub(placeholder_replacement, content)
# Track changed files
changed_files = []
# Step 2: Recursively read all .scss files in the specified directory
for root, dirs, files in os.walk(scss_directory):
for file_name in files:
if file_name.endswith('.scss'):
file_path = os.path.join(root, file_name)
# Skip ignored files
if file_path.replace("\\", "/") in ignore_files:
continue
with open(file_path, 'r', encoding='utf-8') as file:
original_content = file.read()
# Remove invalid placeholders and check if the file has changed
cleaned_content = remove_invalid_placeholders(original_content, valid_placeholders)
if cleaned_content != original_content:
changed_files.append(file_path)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(cleaned_content)
# Step 3: Output results
if changed_files:
print("Clean-up complete! Files Changed:")
for changed_file in changed_files:
print(changed_file)
else:
print("No changes made.")