diff --git a/pynecone/pc.py b/pynecone/pc.py index 49c35ba1e..1f3eda3ec 100644 --- a/pynecone/pc.py +++ b/pynecone/pc.py @@ -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] diff --git a/pynecone/utils.py b/pynecone/utils.py index ed160e924..d6d3afe0c 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -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)