Add export parameters for Backend/Frontend (#499)

This commit is contained in:
Robert Neumann 2023-02-11 00:21:22 +01:00 committed by GitHub
parent 315987c701
commit 5e0d5b9e2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 5 deletions

View File

@ -151,7 +151,13 @@ def deploy(dry_run: bool = typer.Option(False, help="Whether to run a dry run.")
def export(
zipping: bool = typer.Option(
True, "--no-zip", help="Disable zip for backend and frontend exports."
)
),
frontend: bool = typer.Option(
True, "--backend-only", help="Export only backend.", show_default=False
),
backend: bool = typer.Option(
True, "--frontend-only", help="Export only frontend.", show_default=False
),
):
"""Export the app to a zip file."""
# Get the app config.
@ -161,7 +167,7 @@ def export(
# Compile the app in production mode and export it.
utils.console.rule("[bold]Compiling production app and preparing for export.")
app = utils.get_app().app
utils.export_app(app, zip=zipping)
utils.export_app(app, backend=backend, frontend=frontend, zip=zipping)
if zipping:
utils.console.rule(
"""Backend & Frontend compiled. See [green bold]backend.zip[/green bold]

View File

@ -484,11 +484,15 @@ def is_latest_template() -> bool:
return app_version >= template_version
def export_app(app: App, zip: bool = False):
def export_app(
app: App, backend: bool = True, frontend: bool = True, zip: bool = False
):
"""Zip up the app for deployment.
Args:
app: The app.
backend: Whether to zip up the backend app.
frontend: Whether to zip up the frontend app.
zip: Whether to zip the app.
"""
# Force compile the app.
@ -503,9 +507,40 @@ def export_app(app: App, zip: bool = False):
# Zip up the app.
if zip:
if os.name == "posix":
cmd = r"cd .web/_static && zip -r ../../frontend.zip ./* && cd ../.. && zip -r backend.zip ./* -x .web/\* ./assets\* ./frontend.zip\* ./backend.zip\*"
posix_export(backend, frontend)
if os.name == "nt":
cmd = r'''powershell -Command "Set-Location .web/_static; Compress-Archive -Path .\* -DestinationPath ..\..\frontend.zip -Force;cd ..\..;Get-ChildItem .\* -Directory | where {`$_.Name -notin @('.web', 'assets', 'frontend.zip', 'backend.zip')} | Compress-Archive -DestinationPath backend.zip -Update"'''
nt_export(backend, frontend)
def nt_export(backend: bool = True, frontend: bool = True):
"""Export for nt (Windows) systems.
Args:
backend: Whether to zip up the backend app.
frontend: Whether to zip up the frontend app.
"""
cmd = r""
if frontend:
cmd = r'''powershell -Command "Set-Location .web/_static; Compress-Archive -Path .\* -DestinationPath ..\..\frontend.zip -Force"'''
os.system(cmd)
if backend:
cmd = r'''powershell -Command "Get-ChildItem .\* -Directory | where {`$_.Name -notin @('.web', 'assets', 'frontend.zip', 'backend.zip')} | Compress-Archive -DestinationPath backend.zip -Update"'''
os.system(cmd)
def posix_export(backend: bool = True, frontend: bool = True):
"""Export for posix (Linux, OSX) systems.
Args:
backend: Whether to zip up the backend app.
frontend: Whether to zip up the frontend app.
"""
cmd = r""
if frontend:
cmd = r"cd .web/_static && zip -r ../../frontend.zip ./*"
os.system(cmd)
if backend:
cmd = r"zip -r backend.zip ./* -x .web/\* ./assets\* ./frontend.zip\* ./backend.zip\*"
os.system(cmd)