From 0ce6af1d453ffe69fbc46790a73c4226169beeb3 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 30 Oct 2023 00:02:42 +0100 Subject: [PATCH] feat: Purge files before generating them --- README.md | 3 ++- config.example.json | 5 ++++- main.py | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f24057a..05b71b0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ The following configuration generates static files using the `contributors` and } ``` -All static files are generated in the output path specified in the configuration. +All static files are generated in the output path specified in the configuration. +The `purge` array in the configuration specifies which files should be deleted before generating the static files. ## Setup diff --git a/config.example.json b/config.example.json index 50d8000..41192e3 100644 --- a/config.example.json +++ b/config.example.json @@ -36,5 +36,8 @@ } } ], - "output": "static" + "output": "static", + "purge": [ + "static" + ] } \ No newline at end of file diff --git a/main.py b/main.py index 6c2e757..ad0d711 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,24 @@ +from genericpath import isdir, isfile +import os +import shutil from app.config import load_config from app.generator import DefaultGeneratorProvider config = load_config() -output = config["output"] -configs = config["configs"] +output = config["output"] if "output" in config else "static" +purge = config["purge"] if "purge" in config else [] +generator_configs = config["configs"] generator_provider = DefaultGeneratorProvider() -for config in configs: +for path in purge: + if isdir(path): + shutil.rmtree(path) + elif isfile(path): + os.remove(path) + +for config in generator_configs: for generator_name in config["generators"]: generator = generator_provider.get(generator_name) if generator is None: