Changed --clean-style into --clean-css, added --clean-js

This commit is contained in:
Leonardo Cavaletti 2020-05-27 10:15:13 +01:00
parent 7c0dfbc9b6
commit fce23497e9
2 changed files with 23 additions and 10 deletions

View File

@ -40,9 +40,14 @@ def main():
help="Delete all previously cached files for the site before generating it",
)
argparser.add_argument(
"--clean-style",
"--clean-css",
action="store_true",
help="Delete only previously cached .css files for the site before generating it",
help="Delete previously cached .css files for the site before generating it",
)
argparser.add_argument(
"--clean-js",
action="store_true",
help="Delete previously cached .js files for the site before generating it",
)
argparser.add_argument(
"--non-headless",

View File

@ -58,16 +58,24 @@ class Parser:
if self.args.get("clean", False):
try:
shutil.rmtree(self.dist_folder)
log.info(f"Removing previously cached files in '{self.dist_folder}'")
log.info(f"Removing cached files in '{self.dist_folder}'")
except OSError as e:
log.error(f"Cannot remove '{self.dist_folder}': {e}")
elif self.args.get("clean_style", False):
try:
log.info(f"Removing previously cached style files in '{self.dist_folder}'")
for style_file in glob.glob(str(self.dist_folder / "*.css")):
os.remove(style_file)
except OSError as e:
log.error(f"Cannot remove syle files in '{self.dist_folder}': {e}")
else:
if self.args.get("clean_css", False):
try:
log.info(f"Removing cached .css files in '{self.dist_folder}'")
for style_file in glob.glob(str(self.dist_folder / "*.css")):
os.remove(style_file)
except OSError as e:
log.error(f"Cannot remove .css files in '{self.dist_folder}': {e}")
if self.args.get("clean_js", False):
try:
log.info(f"Removing cached .js files in '{self.dist_folder}'")
for style_file in glob.glob(str(self.dist_folder / "*.css")):
os.remove(style_file)
except OSError as e:
log.error(f"Cannot remove .js files in '{self.dist_folder}': {e}")
# create the output folder if necessary
self.dist_folder.mkdir(parents=True, exist_ok=True)