Metadata-Version: 2.4
Name: libra-boot-low
Version: 1.2.0
Summary: Low-code generator: YAML + Jinja2 templates producing full-stack Spring Boot + Vue3 scaffolding (backend/frontend/SQL/HTTP tests)
Author: halavah
License: MIT
Keywords: low-code,code-generator,jinja2,spring-boot,vue3,scaffolding
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Code Generators
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyYAML>=5.4
Requires-Dist: Jinja2>=2.11
Dynamic: license-file

# Libra Boot Low

基于 **YAML 配置 + Jinja2 模板**的低代码代码生成器，一键生成 Spring Boot + Vue3 完整业务骨架代码，覆盖后端（Java）、前端（Vue3）、SQL 建表、HTTP 测试脚本全产物链路。

## 快速上手

```bash
# 方式一：直接从源码运行
pip install -r requirements.txt

# 使用示例配置生成
python3 generator.py config/test/t1000.yml

# 或使用交互式菜单
bash run.sh

# 批量生成全部模块
bash run.sh --all
```

## 安装

| 通道 | 命令 | 状态 |
|---|---|---|
| 源码直跑 | `pip install -r requirements.txt` 后 `python3 generator.py` | ✅ 现可用 |
| GitHub Release wheel | `pip install https://github.com/halavah/libra-boot-low/releases/latest/download/libra_boot_low-1.2.0-py3-none-any.whl` | ✅ 现可用 |
| git 直装 | `pip install git+https://github.com/halavah/libra-boot-low.git` | 🔒 内网（需克隆权限） |
| PyPI | `pip install libra-boot-low` | ✅ 已上架（Trusted Publishing 自动发布，推 v* 标签即出新版；最新版见 [PyPI 页面](https://pypi.org/project/libra-boot-low/)） |

## 生成链路

```
YAML 配置  ──►  generator.py  ──►  module/gen_*.py  ──►  templates/{mode}/  ──►  out/{domain}/{code}/
  (yml/)         (主入口)          (模式生成器)         (Jinja2 模板)           (完整产物)
```

## 十二种生成模式

| 模式 | 说明 | 适用场景 |
|------|------|---------|
| `single` | 单表 CRUD | 简单业务表 |
| `single-with-file` | 单表 + 附件上传 | 带文件的业务表 |
| `multi-table` | 多表关联 | 主表带字典/配置表 |
| `multi-table-with-file` | 多表 + 附件 | 带文件的多表 |
| `master-detail` | 主从表（一对多） | 订单-订单明细 |
| `master-detail-with-file` | 主从表 + 附件 | 带文件的主从 |
| `master-detail-modules` | 主从表（模块化） | 子表独立成模块 |
| `master-detail-modules-with-file` | 主从模块化 + 附件 | 带文件的主从模块化 |
| `master-details-tabs` | 主多明细（页签） | 一主多子页签切换 |
| `master-details-tabs-with-file` | 主多明细页签 + 附件 | 带文件的多明细 |
| `master-details-tabs-dialog` | 主多明细（页签弹窗） | 弹窗编辑的复杂主从 |
| `master-details-tabs-dialog-with-file` | 页签弹窗 + 附件 | 带文件的页签弹窗 |

每种模式均有对应的 `templates/{mode}/` 模板目录和 `config/test/` 示例配置。

## 生成产物

每个模块按六段编号生成完整产物链：

```
out/{domain}/{code}/
├── 00-inbox/ 01-design/      # 生成物清单 + 设计说明
├── 02-sql/ 02-sql-scripts/   # 建表 DDL + SQL 执行脚本
├── 03-http/ 03-http-scripts/ # HTTP 接口测试用例 + 运行脚本
├── 04-server/                # Spring Boot 后端
│   ├── controller/ service/ mapper/  # 控制器/业务/MyBatis 数据层
│   └── entity/{param,po,vo}/         # 实体三件套
└── 05-web/                   # Vue3 前端
    ├── views/                # 页面组件
    └── service/              # API 调用
```

## 配置示例

```yaml
# config/test/t1000.yml（节选——完整注释见该文件）
project:
  name: "Libra Boot Low"
  code: "demo"          # 项目编码（英文小写）
  version: "1.0.0"
  group: "com.libra"   # 生成代码包前缀（可配置，默认 com.libra）

modules:
  - name: "单表无附件"   # 模块中文名
    code: "t1000"       # 模块编码（英文小写）
    domain: "test"      # 业务域编码
    mode: "single"      # 生成模式（12 种之一）
    fields:             # 字段清单（type 决定 Java/SQL/Vue 三端类型）
      - { name: "title", label: "标题", type: "input", required: true }
      - { name: "status", label: "状态", type: "select" }
      - { name: "createTime", label: "创建时间", type: "date-year" }
```

## 测试

```bash
pip install pytest
python -m pytest tests/ -q   # 12 用例：配置加载/类型转换/DRY_RUN 零落盘/渲染器/单表产物结构
```

## CLI 参数

**generator.py 参数：**

| 参数 | 说明 |
|------|------|
| `config`（位置参数） | YAML 配置文件路径 |
| `output`（位置参数） | 输出目录（默认 `../../out`） |
| `--module <code>` / `-m` | 仅生成指定 code 的模块 |
| `--mode <mode>` | 覆盖 YAML 中的 mode |
| `--validate` / `-v` | 仅校验配置，不生成 |
| `--list` / `-l` | 列出配置内的模块 |
| `--list-modes` | 列出全部 12 种支持的模式 |
| `--dry-run` | 预览将生成的文件列表，零落盘 |
| `--update-index` / `-u` | 仅重建 config/index.json 索引 |
| `--batch-timestamp <ts>` | 批量模式共享日志时间戳 |
| `--version` | 显示版本号 |

**run.sh / run.ps1 启动器额外提供：** 交互式菜单（无参数运行）、`--all`（批量生成全部模块）、`--domain <name>`（按域过滤）——由启动器循环调用 generator.py 实现。

## 技术栈

| 组件 | 说明 |
|------|------|
| Python 3.9+ | 运行环境 |
| PyYAML | 配置解析 |
| Jinja2 | 模板渲染 |

## 项目结构

```
libra-boot-low/
├── generator.py            # 主入口
├── run.sh                  # Shell 交互式菜单
├── run.ps1                 # PowerShell 交互式菜单
├── module/                 # 核心生成模块
│   ├── config_loader.py    # YAML 配置加载
│   ├── field_builder.py    # 字段构建器
│   ├── template_renderer.py # Jinja2 渲染器
│   └── gen_*.py            # 各模式生成器
├── templates/              # Jinja2 模板（12 种模式）
│   ├── single/
│   ├── single-with-file/
│   ├── multi-table/
│   ├── master-detail/
│   └── ...
├── config/                 # YAML 配置文件
│   ├── README.md           # 配置说明
│   └── test/               # 示例配置
```

## License

MIT
