Add frontend packages to pcconfig (#91)

* Fix pc init print

* Specify frontend packages to pcconfig
This commit is contained in:
Nikhil Rao 2022-12-13 21:32:24 -08:00 committed by GitHub
parent 20286062d6
commit 30b482666c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -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] = []

View File

@ -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()

View File

@ -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)