diff --git a/src/generator.py b/src/generator.py new file mode 100644 index 0000000..56174fd --- /dev/null +++ b/src/generator.py @@ -0,0 +1,19 @@ +import os + +def create_project(project_name): + """Creates a new project folder with starter files (README.md and main.py). + If the folder already exists, prints a massage instead of crashing.""" + try: + os.makedirs(project_name) + print(f"Created project folder: {project_name}") + + with open(os.path.join(project_name, "README.md"), "w") as f: + f.write(f"# {project_name}\n") + + with open(os.path.join(project_name, "main.py"), "w") as f: + f.write("print('Hello from your new project!')\n") + + print("Starter files generated.") + + except FileExistsError: + print(f"A project named '{project_name}' already exists. Choose a different name.") \ No newline at end of file diff --git a/src/main.py b/src/main.py index 6085a40..13d5eca 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from templates import list_templates +from generator import create_project def main(): print("🚀 Welcome to Create Forge App")