Browse Source

Add default gitignore on pc init (#206)

Nikhil Rao 2 years ago
parent
commit
d7cd792b57
3 changed files with 22 additions and 0 deletions
  1. 4 0
      pynecone/constants.py
  2. 3 0
      pynecone/pc.py
  3. 15 0
      pynecone/utils.py

+ 4 - 0
pynecone/constants.py

@@ -121,6 +121,10 @@ DEFAULT_DESCRIPTION = "A Pynecone app."
 DEFAULT_IMAGE = "favicon.ico"
 
 
+# The gitignore file.
+GITIGNORE_FILE = ".gitignore"
+# Files to gitignore.
+DEFAULT_GITIGNORE = {".web", DB_NAME}
 # The name of the pynecone config module.
 CONFIG_MODULE = "pcconfig"
 # The python config file.

+ 3 - 0
pynecone/pc.py

@@ -39,6 +39,9 @@ def init():
             utils.create_config(app_name)
             utils.initialize_app_directory(app_name)
 
+        # Initialize the .gitignore.
+        utils.initialize_gitignore()
+
         # Finish initializing the app.
         utils.console.log(f"[bold green]Finished Initializing: {app_name}")
 

+ 15 - 0
pynecone/utils.py

@@ -377,6 +377,21 @@ def create_config(app_name: str):
         f.write(templates.PCCONFIG.format(app_name=app_name))
 
 
+def initialize_gitignore():
+    """Initialize the template .gitignore file."""
+    # The files to add to the .gitignore file.
+    files = constants.DEFAULT_GITIGNORE
+
+    # Subtract current ignored files.
+    if os.path.exists(constants.GITIGNORE_FILE):
+        with open(constants.GITIGNORE_FILE, "r") as f:
+            files -= set(f.read().splitlines())
+
+    # Add the new files to the .gitignore file.
+    with open(constants.GITIGNORE_FILE, "a") as f:
+        f.write(join(files))
+
+
 def initialize_app_directory(app_name: str):
     """Initialize the app directory on pc init.