mirror of
https://github.com/revanced/revanced-static-api.git
synced 2025-04-29 22:24:37 +02:00
feat: Purge files before generating them
This commit is contained in:
parent
1e515062d5
commit
0ce6af1d45
@ -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
|
||||||
|
|
||||||
|
@ -36,5 +36,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"output": "static"
|
"output": "static",
|
||||||
|
"purge": [
|
||||||
|
"static"
|
||||||
|
]
|
||||||
}
|
}
|
16
main.py
16
main.py
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user