浏览代码

Add windows support (#96)

Nikhil Rao 2 年之前
父节点
当前提交
209f490bfc

+ 2 - 1
pynecone/.templates/web/package.json

@@ -6,7 +6,8 @@
     "prod": "next start"
   },
   "dependencies": {
-    "@chakra-ui/icons": "^2.0.10",
+    "@chakra-ui/system": "1.12.1",
+    "@chakra-ui/icons": "1.1.7",
     "@chakra-ui/react": "1.8.8",
     "@emotion/react": "^11.9.0",
     "@emotion/styled": "^11.8.1",

+ 0 - 1
pynecone/compiler/templates.py

@@ -11,7 +11,6 @@ PCCONFIG = f"""import pynecone as pc
 
 config = pc.Config(
     app_name="{{app_name}}",
-    bun_path="{constants.BUN_PATH}",
     db_url="{constants.DB_URL}",
     env=pc.Env.DEV,
 )

+ 2 - 2
pynecone/components/datadisplay/datatable.py

@@ -39,14 +39,14 @@ class DataTable(Gridjs):
 
     @classmethod
     def create(cls, *children, **props):
-        """Create a datable component.
+        """Create a datatable component.
 
         Args:
             *children: The children of the component.
             **props: The props to pass to the component.
 
         Returns:
-            The datable component.
+            The datatable component.
 
         Raises:
             ValueError: If a pandas dataframe is passed in and columns are also provided.

+ 9 - 25
pynecone/pc.py

@@ -6,7 +6,6 @@ import httpx
 import typer
 
 from pynecone import constants, utils
-from pynecone.compiler import templates
 
 # Create the app.
 cli = typer.Typer()
@@ -35,31 +34,16 @@ def init():
         raise typer.Exit()
 
     with utils.console.status(f"[bold]Initializing {app_name}"):
-        # Only create the app directory if it doesn't exist.
+        # Set up the web directory.
+        utils.install_bun()
+        utils.initialize_web_directory()
+
+        # Set up the app directory, only if the config doesn't exist.
         if not os.path.exists(constants.CONFIG_FILE):
-            # Create a configuration file.
-            with open(constants.CONFIG_FILE, "w") as f:
-                f.write(templates.PCCONFIG.format(app_name=app_name))
-                utils.console.log("Initialize the app directory.")
-
-            # Initialize the app directory.
-            utils.cp(constants.APP_TEMPLATE_DIR, app_name)
-            utils.mv(
-                os.path.join(app_name, constants.APP_TEMPLATE_FILE),
-                os.path.join(app_name, app_name + constants.PY_EXT),
-            )
-            utils.cp(constants.ASSETS_TEMPLATE_DIR, constants.APP_ASSETS_DIR)
-
-        # Install bun if it isn't already installed.
-        if not os.path.exists(utils.get_bun_path()):
-            utils.console.log("Installing bun...")
-            os.system(constants.INSTALL_BUN)
-
-        # Initialize the web directory.
-        utils.console.log("Initializing the web directory.")
-        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.create_config(app_name)
+            utils.initialize_app_directory(app_name)
+
+        # Finish initializing the app.
         utils.console.log(f"[bold green]Finished Initializing: {app_name}")
 
 

+ 59 - 6
pynecone/utils.py

@@ -5,6 +5,7 @@ from __future__ import annotations
 import inspect
 import json
 import os
+import platform
 import random
 import re
 import shutil
@@ -291,16 +292,19 @@ def get_config() -> Config:
     sys.path.append(os.getcwd())
     try:
         return __import__(constants.CONFIG_MODULE).config
-    except:
+    except ImportError:
         return Config(app_name="")
 
 
-def get_bun_path():
+def get_bun_path() -> str:
     """Get the path to the bun executable.
 
     Returns:
         The path to the bun executable.
     """
+    # On windows, we use npm instead of bun.
+    if platform.system() == "Windows":
+        return str(which("npm"))
     return os.path.expandvars(get_config().bun_path)
 
 
@@ -316,16 +320,65 @@ def get_app() -> Any:
     return app
 
 
+def create_config(app_name: str):
+    """Create a new pcconfig file.
+
+    Args:
+        app_name: The name of the app.
+    """
+    # Import here to avoid circular imports.
+    from pynecone.compiler import templates
+
+    with open(constants.CONFIG_FILE, "w") as f:
+        f.write(templates.PCCONFIG.format(app_name=app_name))
+
+
+def initialize_app_directory(app_name: str):
+    """Initialize the app directory on pc init.
+
+    Args:
+        app_name: The name of the app.
+    """
+    console.log("Initializing the app directory.")
+    cp(constants.APP_TEMPLATE_DIR, app_name)
+    mv(
+        os.path.join(app_name, constants.APP_TEMPLATE_FILE),
+        os.path.join(app_name, app_name + constants.PY_EXT),
+    )
+    cp(constants.ASSETS_TEMPLATE_DIR, constants.APP_ASSETS_DIR)
+
+
+def initialize_web_directory():
+    """Initialize the web directory on pc init."""
+    console.log("Initializing the web directory.")
+    rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.NODE_MODULES))
+    rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.PACKAGE_LOCK))
+    cp(constants.WEB_TEMPLATE_DIR, constants.WEB_DIR)
+
+
+def install_bun():
+    """Install bun onto the user's system."""
+    # Bun is not supported on Windows.
+    if platform.system() == "Windows":
+        console.log("Skipping bun installation on Windows.")
+        return
+
+    # Only install if bun is not already installed.
+    if not os.path.exists(get_bun_path()):
+        console.log("Installing bun...")
+        os.system(constants.INSTALL_BUN)
+
+
 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
-        )
+    packages = get_config().frontend_packages
+    subprocess.call(
+        [get_bun_path(), "add", *packages], cwd=constants.WEB_DIR, stdout=PIPE
+    )
 
 
 def is_initialized() -> bool: