Bladeren bron

Add frontend packages to pcconfig (#91)

* Fix pc init print

* Specify frontend packages to pcconfig
Nikhil Rao 2 jaren geleden
bovenliggende
commit
30b482666c
3 gewijzigde bestanden met toevoegingen van 17 en 7 verwijderingen
  1. 4 1
      pynecone/config.py
  2. 1 1
      pynecone/pc.py
  3. 12 5
      pynecone/utils.py

+ 4 - 1
pynecone/config.py

@@ -1,6 +1,6 @@
 """The Pynecone config."""
 
-from typing import Optional
+from typing import List, Optional
 
 from pynecone import constants
 from pynecone.base import Base
@@ -32,3 +32,6 @@ class Config(Base):
 
     # The path to the bun executable.
     bun_path: str = constants.BUN_PATH
+
+    # Additional frontend packages to install.
+    frontend_packages: List[str] = []

+ 1 - 1
pynecone/pc.py

@@ -60,7 +60,7 @@ def init():
         utils.rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.NODE_MODULES))
         utils.rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.PACKAGE_LOCK))
         utils.cp(constants.WEB_TEMPLATE_DIR, constants.WEB_DIR)
-        utils.console.log("[bold green]Finished Initializing: {app_name}")
+        utils.console.log(f"[bold green]Finished Initializing: {app_name}")
 
 
 @cli.command()

+ 12 - 5
pynecone/utils.py

@@ -316,10 +316,17 @@ def get_app() -> Any:
     return app
 
 
-def install_dependencies():
-    """Install the dependencies."""
+def install_frontend_packages():
+    """Install the frontend packages."""
+    # Install the base packages.
     subprocess.call([get_bun_path(), "install"], cwd=constants.WEB_DIR, stdout=PIPE)
 
+    # Install the app packages.
+    for package in get_config().frontend_packages:
+        subprocess.call(
+            [get_bun_path(), "add", package], cwd=constants.WEB_DIR, stdout=PIPE
+        )
+
 
 def is_initialized() -> bool:
     """Check whether the app is initialized.
@@ -350,9 +357,9 @@ def setup_frontend(app):
     # Initialize the web directory if it doesn't exist.
     cp(constants.WEB_TEMPLATE_DIR, constants.WEB_DIR, overwrite=False)
 
-    # Install the frontend dependencies.
-    console.rule("[bold]Installing Dependencies")
-    install_dependencies()
+    # Install the frontend packages.
+    console.rule("[bold]Installing frontend packages")
+    install_frontend_packages()
 
     # Link the assets folder.
     ln(src=os.path.join("..", constants.APP_ASSETS_DIR), dest=constants.WEB_ASSETS_DIR)