first commit

This commit is contained in:
2026-02-14 00:46:04 +08:00
commit 7ce1e58a6e
18 changed files with 2014 additions and 0 deletions

97
utils.py Normal file
View File

@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-
"""
工具函数模块
"""
import sys
from pathlib import Path
def print_banner():
"""打印欢迎信息"""
print("=" * 60)
print(" 前后端分离项目初始化工具")
print("=" * 60)
print()
def get_project_name():
"""获取项目名称"""
while True:
project_name = input("请输入项目英文名(如 mengyaping: ").strip()
if project_name and project_name.replace("_", "").replace("-", "").isalnum():
return project_name
print("❌ 项目名称无效,请使用英文字母、数字、下划线或短横线")
def select_frontend():
"""选择前端技术栈"""
print("\n📦 请选择前端技术栈:")
print("1. React")
print("2. Vue")
while True:
choice = input("请输入选项 (1-2): ").strip()
if choice == "1":
return "react"
elif choice == "2":
return "vue"
print("❌ 无效选项,请重新输入")
def select_use_tailwind():
"""选择是否使用 Tailwind CSS"""
print("\n🎨 是否使用 Tailwind CSS?")
print("1. 是 (推荐)")
print("2. 否")
while True:
choice = input("请输入选项 (1-2): ").strip()
if choice == "1":
return True
elif choice == "2":
return False
print("❌ 无效选项,请重新输入")
def select_backend():
"""选择后端技术栈"""
print("\n🔧 请选择后端技术栈:")
print("1. Go (标准库)")
print("2. Go (Gin)")
print("3. Python (Flask)")
print("4. Python (FastAPI)")
print("5. Python (Django)")
print("6. Java (Spring Boot)")
print("7. JavaScript (Express.js)")
print("8. JavaScript (NestJS)")
while True:
choice = input("请输入选项 (1-8): ").strip()
if choice == "1":
return "golang"
elif choice == "2":
return "gin"
elif choice == "3":
return "flask"
elif choice == "4":
return "fastapi"
elif choice == "5":
return "django"
elif choice == "6":
return "spring"
elif choice == "7":
return "express"
elif choice == "8":
return "nestjs"
print("❌ 无效选项,请重新输入")
def get_script_dir():
"""获取脚本所在目录"""
if getattr(sys, 'frozen', False):
# 打包后的exe
return Path(sys.executable).parent
else:
# 直接运行的py文件
return Path(__file__).parent