Empty pages directory on recompile (#269)
This commit is contained in:
parent
40801186ad
commit
b93c7a8cbf
@ -284,6 +284,9 @@ class App(Base):
|
||||
# Create the database models.
|
||||
Model.create_all()
|
||||
|
||||
# Empty the .web pages directory
|
||||
compiler.purge_web_pages_dir()
|
||||
|
||||
# Compile the root document with base styles and fonts.
|
||||
compiler.compile_document_root(self.stylesheets)
|
||||
|
||||
|
@ -208,3 +208,9 @@ def compile_components(components: Set[CustomComponent]):
|
||||
# Compile the components.
|
||||
code = _compile_components(components)
|
||||
return output_path, code
|
||||
|
||||
|
||||
def purge_web_pages_dir():
|
||||
"""Empty out .web directory."""
|
||||
template_files = ["_app.js", "404.js"]
|
||||
utils.empty_dir(constants.WEB_PAGES_DIR, keep_files=template_files)
|
||||
|
@ -304,3 +304,16 @@ def write_page(path: str, code: str):
|
||||
utils.mkdir(os.path.dirname(path))
|
||||
with open(path, "w") as f:
|
||||
f.write(code)
|
||||
|
||||
|
||||
def empty_dir(path, keep_files=[]):
|
||||
"""Remove all files and folders in a directory except for the kept file- or foldernames.
|
||||
|
||||
Args:
|
||||
path (str): The path to the directory that will be emptied
|
||||
keep_files (list, optional): List of filenames or foldernames that will not be deleted. Defaults to [].
|
||||
"""
|
||||
directory_contents = os.listdir(path)
|
||||
for element in directory_contents:
|
||||
if element not in keep_files:
|
||||
utils.rm(os.path.join(path, element))
|
||||
|
Loading…
Reference in New Issue
Block a user