简化app模板文件
This commit is contained in:
parent
96c33e0f5e
commit
c424f0ee02
@ -39,7 +39,7 @@ async def create_pagetypes(payload: Dict[str, Any]):
|
|||||||
frontend_path = str(fp)
|
frontend_path = str(fp)
|
||||||
|
|
||||||
if create_backend:
|
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)
|
bp.parent.mkdir(parents=True, exist_ok=True)
|
||||||
if bp.exists():
|
if bp.exists():
|
||||||
backend_exists = True
|
backend_exists = True
|
||||||
@ -127,16 +127,6 @@ app_license = "{license_type.lower()}"
|
|||||||
'''
|
'''
|
||||||
(app_inner_dir / "modules.txt").write_text(modules_content, encoding="utf-8")
|
(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").mkdir(exist_ok=True)
|
||||||
(app_inner_dir / "config" / "__init__.py").write_text("", encoding="utf-8")
|
(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" / "js").mkdir(exist_ok=True)
|
||||||
(app_inner_dir / "public" / ".gitkeep").write_text("", encoding="utf-8")
|
(app_inner_dir / "public" / ".gitkeep").write_text("", encoding="utf-8")
|
||||||
|
|
||||||
(app_inner_dir / "templates").mkdir(exist_ok=True)
|
# 创建module目录(与config、public平级)
|
||||||
(app_inner_dir / "templates" / "pages").mkdir(exist_ok=True)
|
(app_inner_dir / app_name).mkdir(exist_ok=True)
|
||||||
(app_inner_dir / "templates" / "pages" / "__init__.py").write_text("", encoding="utf-8")
|
(app_inner_dir / app_name / "__init__.py").write_text("", encoding="utf-8")
|
||||||
(app_inner_dir / "templates" / "includes").mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
# 创建API模块
|
# 创建README.md(最小化文档)
|
||||||
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_content = f'''# {app_title}
|
readme_content = f'''# {app_title}
|
||||||
|
|
||||||
{description}
|
{description}
|
||||||
|
|
||||||
## 功能特性
|
|
||||||
|
|
||||||
- 基于Jingrow框架的现代化应用
|
|
||||||
- 支持云端和本地部署
|
|
||||||
- 符合最佳实践和未来趋势
|
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
### 本地开发
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 安装依赖
|
pip install -e .
|
||||||
pip install -r requirements.txt
|
|
||||||
|
|
||||||
# 运行开发服务器
|
|
||||||
python -m uvicorn main:app --port 8001
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 云端部署
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 安装到Jingrow Cloud
|
|
||||||
bench --site your-site install-app {app_name}
|
|
||||||
```
|
|
||||||
|
|
||||||
## PageTypes
|
|
||||||
|
|
||||||
*PageTypes will be created through Jingrow Cloud backend after app installation*
|
|
||||||
|
|
||||||
## 开发
|
## 开发
|
||||||
|
|
||||||
### 添加新的PageType
|
```bash
|
||||||
|
pip install -e ".[dev]"
|
||||||
1. 在 `{app_name}/{app_name}/pagetype/` 下创建新的PageType类
|
```
|
||||||
2. 在 `api/` 下添加对应的API处理函数
|
|
||||||
3. 在 `frontend/` 下添加前端组件
|
|
||||||
|
|
||||||
### API接口
|
|
||||||
|
|
||||||
- `/{app_name}/api/` - REST API接口
|
|
||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
{license_type} License
|
{license_type} License
|
||||||
|
|
||||||
## 联系方式
|
|
||||||
|
|
||||||
{publisher} - {email}
|
|
||||||
'''
|
'''
|
||||||
(app_dir / "README.md").write_text(readme_content, encoding="utf-8")
|
(app_dir / "README.md").write_text(readme_content, encoding="utf-8")
|
||||||
|
|
||||||
# 创建requirements.txt
|
pyproject_content = f'''[build-system]
|
||||||
requirements_content = '''# Core dependencies
|
requires = ["setuptools>=61.0", "wheel"]
|
||||||
fastapi>=0.104.0
|
build-backend = "setuptools.build_meta"
|
||||||
uvicorn>=0.24.0
|
|
||||||
pydantic>=2.0.0
|
|
||||||
python-multipart>=0.0.6
|
|
||||||
|
|
||||||
# Database
|
[project]
|
||||||
sqlalchemy>=2.0.0
|
name = "{app_name}"
|
||||||
alembic>=1.12.0
|
version = "0.0.1"
|
||||||
|
description = "{description}"
|
||||||
|
authors = [
|
||||||
|
{{name = "{publisher}", email = "{email}"}}
|
||||||
|
]
|
||||||
|
license = {{text = "{license_type}"}}
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
|
||||||
# Development
|
dependencies = [
|
||||||
pytest>=7.4.0
|
# Add your app-specific dependencies here
|
||||||
pytest-asyncio>=0.21.0
|
]
|
||||||
black>=23.0.0
|
|
||||||
flake8>=6.0.0
|
[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 {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user