Jelajahi Sumber

Add export parameters for Backend/Frontend (#499)

Robert Neumann 2 tahun lalu
induk
melakukan
5e0d5b9e2e
2 mengubah file dengan 46 tambahan dan 5 penghapusan
  1. 8 2
      pynecone/pc.py
  2. 38 3
      pynecone/utils.py

+ 8 - 2
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] 

+ 38 - 3
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)