From 30b482666c6f5d43cf73a87343f2a5ae7733f231 Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Tue, 13 Dec 2022 21:32:24 -0800 Subject: [PATCH] Add frontend packages to pcconfig (#91) * Fix pc init print * Specify frontend packages to pcconfig --- pynecone/config.py | 5 ++++- pynecone/pc.py | 2 +- pynecone/utils.py | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pynecone/config.py b/pynecone/config.py index a6f45e54c..203e13f9c 100644 --- a/pynecone/config.py +++ b/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] = [] diff --git a/pynecone/pc.py b/pynecone/pc.py index e8679474c..e83efb139 100644 --- a/pynecone/pc.py +++ b/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() diff --git a/pynecone/utils.py b/pynecone/utils.py index 33f7be24c..36522055b 100644 --- a/pynecone/utils.py +++ b/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)