feat: Purge files before generating them

This commit is contained in:
oSumAtrIX 2023-10-30 00:02:42 +01:00
parent 1e515062d5
commit 0ce6af1d45
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 19 additions and 5 deletions

View File

@ -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 ## Setup

View File

@ -36,5 +36,8 @@
} }
} }
], ],
"output": "static" "output": "static",
"purge": [
"static"
]
} }

16
main.py
View File

@ -1,14 +1,24 @@
from genericpath import isdir, isfile
import os
import shutil
from app.config import load_config from app.config import load_config
from app.generator import DefaultGeneratorProvider from app.generator import DefaultGeneratorProvider
config = load_config() config = load_config()
output = config["output"] output = config["output"] if "output" in config else "static"
configs = config["configs"] purge = config["purge"] if "purge" in config else []
generator_configs = config["configs"]
generator_provider = DefaultGeneratorProvider() 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"]: for generator_name in config["generators"]:
generator = generator_provider.get(generator_name) generator = generator_provider.get(generator_name)
if generator is None: if generator is None: