Created
April 30, 2020 11:13
-
-
Save isevcik/eb04ec69276a056f2fdc03707a921c8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import glob | |
import fileinput | |
from pathlib import Path | |
directory = "src/app/" | |
directory_blacklist = "styles/" | |
if_matches = [ | |
'$', | |
'@include' | |
] | |
blacklist_matches = [ | |
'@import "includes"' | |
] | |
remove_lines = [ | |
'@import "theming";', | |
'@import "layout";', | |
'@import "tables";', | |
'@import "fonts";', | |
'@import "forms";', | |
'@import "validation";', | |
'@import "responsive";', | |
'@import "button";', | |
'@import "dashboard-tabview";', | |
'@import "fixes";', | |
'@import "input";', | |
'@import "mobile-styles";', | |
'@import "sidepanes";', | |
'@import "everglades.includes";', | |
] | |
add = '@import "everglades.includes";' | |
logging = False | |
def log(msg, filename): | |
if not logging: | |
return | |
print(msg, filename) | |
def process_file(filename): | |
contents = Path(filename).read_text() | |
if content_matches(contents, blacklist_matches): | |
log("NOT matches (blacklist match)", filename) | |
return | |
if not content_matches(contents, if_matches): | |
log("NOT matches (not if match)", filename) | |
return | |
for remove in remove_lines: | |
contents = contents.replace(f'{remove}\n', "") | |
contents = f'{add}\n{contents}' | |
Path(filename).write_text(contents) | |
def content_matches(content, patterns): | |
for p in patterns: | |
if content.find(p) >= 0: | |
return True | |
return False | |
for name in glob.glob(f'{directory}**/*.scss', recursive=True): | |
if directory_blacklist in name: | |
continue | |
process_file(name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment