Add default gitignore on pc init (#206)

This commit is contained in:
Nikhil Rao 2023-01-04 15:05:07 -08:00 committed by GitHub
parent d93e2cec00
commit d7cd792b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View File

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

View File

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

View File

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