简化app模板文件

This commit is contained in:
jingrow 2025-10-24 23:45:23 +08:00
parent 96c33e0f5e
commit c424f0ee02

View File

@ -39,7 +39,7 @@ async def create_pagetypes(payload: Dict[str, Any]):
frontend_path = str(fp)
if create_backend:
bp = root / "apps" / app / app / module / "pagetype" / slug / f"{slug}.py"
bp = root / "apps" / app / app / app / module / "pagetype" / slug / f"{slug}.py"
bp.parent.mkdir(parents=True, exist_ok=True)
if bp.exists():
backend_exists = True
@ -127,16 +127,6 @@ app_license = "{license_type.lower()}"
'''
(app_inner_dir / "modules.txt").write_text(modules_content, encoding="utf-8")
# 创建patches.txt
patches_content = '''[pre_model_sync]
# Patches added in this section will be executed before pagetypes are migrated
# Read docs to understand patches: https://framework.jingrow.com/docs/v14/user/en/database-migrations
[post_model_sync]
# Patches added in this section will be executed after pagetypes are migrated
'''
(app_inner_dir / "patches.txt").write_text(patches_content, encoding="utf-8")
# 创建目录结构
(app_inner_dir / "config").mkdir(exist_ok=True)
(app_inner_dir / "config" / "__init__.py").write_text("", encoding="utf-8")
@ -146,135 +136,58 @@ app_license = "{license_type.lower()}"
(app_inner_dir / "public" / "js").mkdir(exist_ok=True)
(app_inner_dir / "public" / ".gitkeep").write_text("", encoding="utf-8")
(app_inner_dir / "templates").mkdir(exist_ok=True)
(app_inner_dir / "templates" / "pages").mkdir(exist_ok=True)
(app_inner_dir / "templates" / "pages" / "__init__.py").write_text("", encoding="utf-8")
(app_inner_dir / "templates" / "includes").mkdir(exist_ok=True)
# 创建module目录与config、public平级
(app_inner_dir / app_name).mkdir(exist_ok=True)
(app_inner_dir / app_name / "__init__.py").write_text("", encoding="utf-8")
# 创建API模块
if include_api:
api_dir = app_inner_dir / "api"
api_dir.mkdir(parents=True, exist_ok=True)
(api_dir / "__init__.py").write_text("", encoding="utf-8")
# 创建权限模块
permission_content = f'''# coding: utf-8
import jingrow
def has_app_permission():
"""检查应用权限"""
return True
def has_permission(pagetype, name=None):
"""检查页面类型权限"""
return True
'''
(api_dir / "permission.py").write_text(permission_content, encoding="utf-8")
# 创建前端组件
if include_frontend:
# 前端目录已经在上面创建了,这里不需要重复创建
pass
# 创建测试文件
if include_tests:
tests_dir = app_inner_dir / "tests"
tests_dir.mkdir(parents=True, exist_ok=True)
(tests_dir / "__init__.py").write_text("", encoding="utf-8")
test_content = f'''# coding: utf-8
import pytest
class Test{app_title.replace(' ', '')}:
"""{{app_title}} 测试类"""
def test_app_creation(self):
"""测试应用创建"""
assert True
def test_pagetype_creation(self):
"""测试PageType创建"""
# 测试PageType是否正确创建
pass
'''
(tests_dir / f"test_{app_name}.py").write_text(test_content, encoding="utf-8")
# 创建README.md
# 创建README.md最小化文档
readme_content = f'''# {app_title}
{description}
## 功能特性
- 基于Jingrow框架的现代化应用
- 支持云端和本地部署
- 符合最佳实践和未来趋势
## 安装
### 本地开发
```bash
# 安装依赖
pip install -r requirements.txt
# 运行开发服务器
python -m uvicorn main:app --port 8001
pip install -e .
```
### 云端部署
```bash
# 安装到Jingrow Cloud
bench --site your-site install-app {app_name}
```
## PageTypes
*PageTypes will be created through Jingrow Cloud backend after app installation*
## 开发
### 添加新的PageType
1. `{app_name}/{app_name}/pagetype/` 下创建新的PageType类
2. `api/` 下添加对应的API处理函数
3. `frontend/` 下添加前端组件
### API接口
- `/{app_name}/api/` - REST API接口
```bash
pip install -e ".[dev]"
```
## 许可证
{license_type} License
## 联系方式
{publisher} - {email}
'''
(app_dir / "README.md").write_text(readme_content, encoding="utf-8")
# 创建requirements.txt
requirements_content = '''# Core dependencies
fastapi>=0.104.0
uvicorn>=0.24.0
pydantic>=2.0.0
python-multipart>=0.0.6
pyproject_content = f'''[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
# Database
sqlalchemy>=2.0.0
alembic>=1.12.0
[project]
name = "{app_name}"
version = "0.0.1"
description = "{description}"
authors = [
{{name = "{publisher}", email = "{email}"}}
]
license = {{text = "{license_type}"}}
requires-python = ">=3.8"
# Development
pytest>=7.4.0
pytest-asyncio>=0.21.0
black>=23.0.0
flake8>=6.0.0
dependencies = [
# Add your app-specific dependencies here
]
[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"black>=23.0.0",
]
'''
(app_dir / "requirements.txt").write_text(requirements_content, encoding="utf-8")
(app_dir / "pyproject.toml").write_text(pyproject_content, encoding="utf-8")
return {
"success": True,