xb-init 2.0.5__tar.gz → 2.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xb_init-2.0.5 → xb_init-2.2.2}/.gitignore +38 -38
- {xb_init-2.0.5 → xb_init-2.2.2}/PKG-INFO +51 -12
- {xb_init-2.0.5 → xb_init-2.2.2}/README.md +236 -197
- {xb_init-2.0.5 → xb_init-2.2.2}/pyproject.toml +62 -62
- xb_init-2.2.2/tests/test_cli.py +88 -0
- xb_init-2.2.2/tests/test_update_templates.py +77 -0
- xb_init-2.2.2/uv.lock +445 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/__init__.py +10 -10
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/cli.py +86 -86
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/__init__.py +1 -1
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/build.py +79 -79
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/dev.py +49 -49
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/doctor.py +91 -91
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/init.py +438 -344
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/upgrade.py +27 -27
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/version.py +65 -65
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/__init__.py.j2 +3 -3
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/config.py.j2 +295 -371
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/ports.py.j2 +105 -105
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/terminal/__init__.py.j2 +3 -3
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/terminal/routes.py.j2 +258 -258
- xb_init-2.2.2/xb/templates/backend/api/update/__init__.py.j2 +188 -0
- xb_init-2.2.2/xb/templates/backend/app_version.py.j2 +11 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/backend_build.py.j2 +49 -42
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/main.py.j2 +145 -122
- xb_init-2.2.2/xb/templates/backend/managers/__init__.py.j2 +7 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/managers/logger_manager.py.j2 +53 -48
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/managers/path_manager.py.j2 +352 -256
- xb_init-2.2.2/xb/templates/backend/managers/secret_obfuscator.py.j2 +123 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/managers/sudoers_manager.py.j2 +165 -151
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/requirements.txt.j2 +8 -8
- xb_init-2.2.2/xb/templates/backend/services/__init__.py.j2 +1 -0
- xb_init-2.2.2/xb/templates/backend/services/feishu_client.py.j2 +264 -0
- xb_init-2.2.2/xb/templates/backend/services/updater.py.j2 +712 -0
- xb_init-2.2.2/xb/templates/configs/config_changes.json.j2 +1 -0
- xb_init-2.2.2/xb/templates/configs/global_config.yaml.j2 +3 -0
- xb_init-2.2.2/xb/templates/configs/secrets.yaml.example.j2 +9 -0
- xb_init-2.2.2/xb/templates/configs/secrets.yaml.j2 +9 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/launcher.js.j2 +189 -189
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/main.js.j2 +258 -258
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/package.json.j2 +81 -81
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/port_diagnostics.js.j2 +187 -187
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/preload.js.j2 +11 -11
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/prepare.js.j2 +43 -43
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/resources/postinst.py.j2 +163 -131
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/resources/postrm.py.j2 +34 -34
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/resources/uninstaller.nsh.j2 +44 -44
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/index.html.j2 +12 -12
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/package.json.j2 +21 -21
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/App.vue.j2 +106 -109
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/ConfigSetup.vue.j2 +227 -260
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/DashboardHome.vue.j2 +40 -40
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/FileManager.vue.j2 +428 -617
- xb_init-2.2.2/xb/templates/frontend/src/components/GitVersionBadge.vue.j2 +297 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/RefreshButton.vue.j2 +147 -147
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/TerminalPanel.vue.j2 +248 -236
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/TerminalView.vue.j2 +229 -211
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/ThemeToggle.vue.j2 +49 -49
- xb_init-2.2.2/xb/templates/frontend/src/components/version/CommitHistoryPanel.vue.j2 +286 -0
- xb_init-2.2.2/xb/templates/frontend/src/components/version/UpdatePanel.vue.j2 +766 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/composables/useTerminalSessions.js.j2 +125 -125
- xb_init-2.2.2/xb/templates/frontend/src/composables/useUpdate.js.j2 +295 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/main.js.j2 +5 -5
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/style.css.j2 +596 -594
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/vite.config.js.j2 +74 -74
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/.gitignore.j2 +41 -35
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/AGENTS.md.j2 +519 -455
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/README.md.j2 +449 -371
- xb_init-2.2.2/xb/templates/root/build.py.j2 +448 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/dev.py.j2 +268 -268
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/pyproject.toml.j2 +29 -29
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/scripts/example.py.j2 +4 -4
- xb_init-2.2.2/xb/templates/scripts/feishu_upload.py.j2 +656 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/version/scripts/gui_version_manager.py.j2 +484 -466
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/version/scripts/version_manager.py.j2 +174 -114
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/version/scripts/web_version_manager.py.j2 +302 -284
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/__init__.py +1 -1
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/click_helpers.py +96 -96
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/template_engine.py +405 -338
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/validators.py +8 -8
- {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/version_check.py +183 -183
- xb_init-2.0.5/.claude/settings.local.json +0 -13
- xb_init-2.0.5/.codegraph/.gitignore +0 -5
- xb_init-2.0.5/.codegraph/codegraph.db +0 -0
- xb_init-2.0.5/.tmp_hookpath_test/custom-hooks/pre-commit +0 -5
- xb_init-2.0.5/.tmp_hookpath_test/pyproject.toml +0 -0
- xb_init-2.0.5/.tmp_hookpath_test/version/scripts/version_manager.py +0 -118
- xb_init-2.0.5/.tmp_hookpath_test/version/scripts/web_version_manager.py +0 -285
- xb_init-2.0.5/tests/test_cli.py +0 -14
- xb_init-2.0.5/uv.lock +0 -445
- xb_init-2.0.5/xb/templates/backend/managers/__init__.py.j2 +0 -7
- xb_init-2.0.5/xb/templates/configs/global_config.yaml.j2 +0 -4
- xb_init-2.0.5/xb/templates/configs/secrets.yaml.example.j2 +0 -3
- xb_init-2.0.5/xb/templates/configs/secrets.yaml.j2 +0 -3
- xb_init-2.0.5/xb/templates/electron/.npmrc.j2 +0 -10
- xb_init-2.0.5/xb/templates/frontend/.npmrc.j2 +0 -7
- xb_init-2.0.5/xb/templates/frontend/src/components/GitVersionBadge.vue.j2 +0 -359
- xb_init-2.0.5/xb/templates/root/build.py.j2 +0 -68
- xb_init-2.0.5/xb/templates/version/hooks/pre-commit.py.j2 +0 -43
- xb_init-2.0.5/xb/templates/version/scripts/install_hooks.py.j2 +0 -77
- {xb_init-2.0.5 → xb_init-2.2.2}/docs/screenshot.png +0 -0
- {xb_init-2.0.5 → xb_init-2.2.2}/tests/test_upgrade.py +0 -0
- /xb_init-2.0.5/.tmp_hookpath_test/version/hooks/pre-commit.py → /xb_init-2.2.2/xb/templates/version/hooks/pre-commit.py.j2 +0 -0
- /xb_init-2.0.5/.tmp_hookpath_test/version/scripts/install_hooks.py → /xb_init-2.2.2/xb/templates/version/scripts/install_hooks.py.j2 +0 -0
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
# Python
|
|
2
|
-
__pycache__/
|
|
3
|
-
*.pyc
|
|
4
|
-
*.pyo
|
|
5
|
-
*.pyd
|
|
6
|
-
.Python
|
|
7
|
-
*.so
|
|
8
|
-
*.egg
|
|
9
|
-
*.egg-info/
|
|
10
|
-
dist/
|
|
11
|
-
build/
|
|
12
|
-
.eggs/
|
|
13
|
-
|
|
14
|
-
# Virtual environments
|
|
15
|
-
.venv/
|
|
16
|
-
venv/
|
|
17
|
-
ENV/
|
|
18
|
-
env/
|
|
19
|
-
|
|
20
|
-
# uv
|
|
21
|
-
.uv/
|
|
22
|
-
|
|
23
|
-
# IDE
|
|
24
|
-
.vscode/
|
|
25
|
-
.idea/
|
|
26
|
-
*.swp
|
|
27
|
-
*.swo
|
|
28
|
-
.DS_Store
|
|
29
|
-
|
|
30
|
-
# Testing
|
|
31
|
-
.pytest_cache/
|
|
32
|
-
.coverage
|
|
33
|
-
htmlcov/
|
|
34
|
-
|
|
35
|
-
# Local dev
|
|
36
|
-
*.log
|
|
37
|
-
.env
|
|
38
|
-
.env.local
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
*.pyo
|
|
5
|
+
*.pyd
|
|
6
|
+
.Python
|
|
7
|
+
*.so
|
|
8
|
+
*.egg
|
|
9
|
+
*.egg-info/
|
|
10
|
+
dist/
|
|
11
|
+
build/
|
|
12
|
+
.eggs/
|
|
13
|
+
|
|
14
|
+
# Virtual environments
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
ENV/
|
|
18
|
+
env/
|
|
19
|
+
|
|
20
|
+
# uv
|
|
21
|
+
.uv/
|
|
22
|
+
|
|
23
|
+
# IDE
|
|
24
|
+
.vscode/
|
|
25
|
+
.idea/
|
|
26
|
+
*.swp
|
|
27
|
+
*.swo
|
|
28
|
+
.DS_Store
|
|
29
|
+
|
|
30
|
+
# Testing
|
|
31
|
+
.pytest_cache/
|
|
32
|
+
.coverage
|
|
33
|
+
htmlcov/
|
|
34
|
+
|
|
35
|
+
# Local dev
|
|
36
|
+
*.log
|
|
37
|
+
.env
|
|
38
|
+
.env.local
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: xb-init
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.2
|
|
4
4
|
Summary: Project management tool for UV + FastAPI + Vue3 + Electron desktop applications
|
|
5
|
-
Project-URL: Homepage, https://github.com/
|
|
6
|
-
Project-URL: Documentation, https://github.com/
|
|
7
|
-
Project-URL: Repository, https://github.com/
|
|
8
|
-
Project-URL: Issues, https://github.com/
|
|
9
|
-
Author-email:
|
|
5
|
+
Project-URL: Homepage, https://github.com/xuebli/xb
|
|
6
|
+
Project-URL: Documentation, https://github.com/xuebli/xb#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/xuebli/xb.git
|
|
8
|
+
Project-URL: Issues, https://github.com/xuebli/xb/issues
|
|
9
|
+
Author-email: xuebli <17639393047@163.com>
|
|
10
10
|
License: MIT
|
|
11
11
|
Keywords: cli,electron,fastapi,project-management,vue3
|
|
12
12
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -43,6 +43,7 @@ Description-Content-Type: text/markdown
|
|
|
43
43
|
- 内置全局亮色/暗色主题切换
|
|
44
44
|
- 可选 sudo 免密配置(`--sudoers`)
|
|
45
45
|
- 可选内置终端(`--terminal`)
|
|
46
|
+
- 可选应用内自动更新(`--update`,飞书云盘发布 + 版本检查 + 下载校验 + 自动安装)
|
|
46
47
|
- 可选自定义应用图标(`--icon`)
|
|
47
48
|
- 内置开发、构建、版本管理命令
|
|
48
49
|
- 自动版本检查与一键升级(`xb --upgrade`)
|
|
@@ -83,6 +84,9 @@ xb init demo --terminal
|
|
|
83
84
|
# 同时启用终端和 sudo 免密配置
|
|
84
85
|
xb init demo --terminal --sudoers
|
|
85
86
|
|
|
87
|
+
# 启用应用内自动更新(自动附带 --sudoers 免密,输入 sudo 密码即可)
|
|
88
|
+
xb init demo --update
|
|
89
|
+
|
|
86
90
|
# 带自定义图标
|
|
87
91
|
xb init demo --icon ~/icons/app.png
|
|
88
92
|
|
|
@@ -110,14 +114,18 @@ python .\dev.py stop
|
|
|
110
114
|
使用 `--terminal` 时,Windows 终端使用 PowerShell + ConPTY,支持上下箭头
|
|
111
115
|
命令历史、复制粘贴、Tab 补全和 Ctrl+C;Ubuntu/Debian 使用 bash + Unix PTY。
|
|
112
116
|
|
|
113
|
-
Electron 二进制镜像通过 `ELECTRON_MIRROR`
|
|
114
|
-
|
|
117
|
+
Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
|
|
118
|
+
若安装过程被网络中断,生成项目的
|
|
115
119
|
`electron/prepare.js` 会在 `npm start` 或 `npm run build` 前自动检查并补装
|
|
116
120
|
缺失的 Electron 二进制。
|
|
117
121
|
|
|
118
122
|
> **`xb init` 自动行为**:
|
|
119
123
|
> - 执行 `npm install`(frontend + electron),生成 `package-lock.json`
|
|
120
|
-
> -
|
|
124
|
+
> - 生成的项目用 [nrm](https://github.com/Pana/nrm) 管理 npm 源:`xb init`
|
|
125
|
+
> 安装依赖前与 `build.py` 构建前都会自动 `nrm test` 测速所有内置源并切换
|
|
126
|
+
> 到最快的(未安装 nrm 时自动全局安装);项目不放 `.npmrc`,npm 源完全由
|
|
127
|
+
> nrm 全局管理
|
|
128
|
+
> - electron 约 200MB 二进制走华为云镜像下载
|
|
121
129
|
> - 若安装失败或超时,会打印提示但不中断项目创建,可稍后手动重试
|
|
122
130
|
> - 执行 `git init` 并提交首个 commit(包含所有文件和 lock 文件)
|
|
123
131
|
> - 若检测到 PyPI 有新版 xb,会询问是否先升级再创建项目
|
|
@@ -127,7 +135,7 @@ Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入,不向 `.n
|
|
|
127
135
|
|
|
128
136
|
| 命令 | 说明 |
|
|
129
137
|
|------|------|
|
|
130
|
-
| `xb init <name> [--sudoers] [--terminal] [--icon PATH]` | 初始化项目 |
|
|
138
|
+
| `xb init <name> [--sudoers] [--terminal] [--update] [--icon PATH]` | 初始化项目 |
|
|
131
139
|
| `xb dev [start\|stop\|status]` | 启动/停止/查看开发环境 |
|
|
132
140
|
| `xb build [all\|frontend\|backend\|electron]` | 构建项目 |
|
|
133
141
|
| `xb build -f / -b / -e / -a` | 构建快捷 flag |
|
|
@@ -146,6 +154,39 @@ xb init demo --icon ./my-icon.png
|
|
|
146
154
|
# ./assets/app-icon.png, ./assets/icon.png, ./resources/icon.png
|
|
147
155
|
```
|
|
148
156
|
|
|
157
|
+
## 应用内自动更新(`--update`)
|
|
158
|
+
|
|
159
|
+
`xb init demo --update` 会让生成的项目内置与 [leo_stm32_board_test](../leo_stm32_board_test) 同源的自动更新能力,
|
|
160
|
+
以飞书云盘的一个文件夹作为发布"货架":
|
|
161
|
+
|
|
162
|
+
**生成内容:**
|
|
163
|
+
|
|
164
|
+
| 位置 | 职责 |
|
|
165
|
+
|------|------|
|
|
166
|
+
| `backend/api/update/` | 更新接口(检查 / 信息 / 下载 / 进度 / 安装) |
|
|
167
|
+
| `backend/services/updater.py` | 版本比较、信息拉取、下载校验、配置备份迁移、安装 |
|
|
168
|
+
| `backend/services/feishu_client.py` | 飞书接口封装(文件夹列举、并发下载) |
|
|
169
|
+
| `backend/managers/secret_obfuscator.py` | 敏感值混淆(`obf1:`,防围观级别) |
|
|
170
|
+
| `backend/app_version.py` | 后端版本号(version_manager 提交时自动同步) |
|
|
171
|
+
| `frontend/src/components/UpdateChecker.vue` | 版本号徽章 + 更新弹窗 + 进度条 |
|
|
172
|
+
| `frontend/src/composables/useUpdate.js` | 定时检查 / 下载进度轮询 |
|
|
173
|
+
| `scripts/feishu_upload.py` | 发版端:安装包与版本信息上传飞书 |
|
|
174
|
+
| `configs/config_changes.json` | 配置迁移清单(顶层 key 是版本号) |
|
|
175
|
+
| `build.py` | 增加 `--upload-only` 与构建后发布编排 |
|
|
176
|
+
|
|
177
|
+
**发版流程:** 在 `configs/secrets.yaml` 填 `feishu.app_id` / `app_secret` /
|
|
178
|
+
`update_folder_url` → `./build.py -a` → 确认上传。构建时敏感键自动混淆进
|
|
179
|
+
`secrets.yaml.example` 随包分发,构建结束 example 恢复为留空模板。
|
|
180
|
+
|
|
181
|
+
**客户端:** 启动时 / 每小时 / 点版本号徽章时检查更新;发现新版本后下载
|
|
182
|
+
(4 线程分块 + SHA256 校验 + `.part` 防半截包)→ 备份配置 → 按
|
|
183
|
+
`config_changes.json` 迁移 → Ubuntu 趁应用存活时免密 `sudo dpkg -i`
|
|
184
|
+
(`--update` 默认附带 `--sudoers` 免密),Windows 等退出后静默安装。
|
|
185
|
+
|
|
186
|
+
**飞书侧准备:** 开放平台建自建应用 → 开通 `drive:drive` 权限并发布 →
|
|
187
|
+
建云盘文件夹,完整链接填入 `update_folder_url`。开发模式(源码运行)不支持
|
|
188
|
+
应用内更新,检查接口返回 `packaged: false`。
|
|
189
|
+
|
|
149
190
|
## 生成的项目结构
|
|
150
191
|
|
|
151
192
|
```
|
|
@@ -162,13 +203,11 @@ demo/
|
|
|
162
203
|
├── frontend/ # Vue 3 前端
|
|
163
204
|
│ ├── package.json
|
|
164
205
|
│ ├── package-lock.json
|
|
165
|
-
│ ├── .npmrc # npm 镜像源(华为云)
|
|
166
206
|
│ ├── vite.config.js
|
|
167
207
|
│ └── src/
|
|
168
208
|
├── electron/ # Electron 主进程
|
|
169
209
|
│ ├── package.json
|
|
170
210
|
│ ├── package-lock.json
|
|
171
|
-
│ ├── .npmrc # npm + electron 二进制镜像源
|
|
172
211
|
│ ├── main.js
|
|
173
212
|
│ └── resources/ # icon + Linux DEB hooks
|
|
174
213
|
├── version/ # 版本管理(pre-commit hook)
|
|
@@ -1,197 +1,236 @@
|
|
|
1
|
-
# xb - 前后端打包构建工具
|
|
2
|
-
|
|
3
|
-
**xb**(PyPI: `xb-init`)是一个基于 `uv` 又类似 `uv` 的项目管理工具,专为快速初始化 **UV + FastAPI + Vue3 + Electron** 桌面应用而生。一条命令拉起完整工程脚手架,开发、构建、版本管理一站式搞定。
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
## 核心特性
|
|
8
|
-
|
|
9
|
-
- 一键初始化完整项目结构(`xb init demo`)
|
|
10
|
-
- UV + FastAPI + Vue3 + Electron 开箱即用
|
|
11
|
-
- 自动安装前端和 Electron 依赖(`npm install`,内置国内镜像源)
|
|
12
|
-
- 自动 `git init` 并提交首个 commit(含 lock 文件)
|
|
13
|
-
- 自动生成 `AGENTS.md`(AI 编码助手协作约定)
|
|
14
|
-
- 内置全局亮色/暗色主题切换
|
|
15
|
-
- 可选 sudo 免密配置(`--sudoers`)
|
|
16
|
-
- 可选内置终端(`--terminal`)
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
uv
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
>
|
|
94
|
-
> -
|
|
95
|
-
>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
xb
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
├──
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
│ ├──
|
|
171
|
-
│ ├──
|
|
172
|
-
│ ├──
|
|
173
|
-
│ └──
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
1
|
+
# xb - 前后端打包构建工具
|
|
2
|
+
|
|
3
|
+
**xb**(PyPI: `xb-init`)是一个基于 `uv` 又类似 `uv` 的项目管理工具,专为快速初始化 **UV + FastAPI + Vue3 + Electron** 桌面应用而生。一条命令拉起完整工程脚手架,开发、构建、版本管理一站式搞定。
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## 核心特性
|
|
8
|
+
|
|
9
|
+
- 一键初始化完整项目结构(`xb init demo`)
|
|
10
|
+
- UV + FastAPI + Vue3 + Electron 开箱即用
|
|
11
|
+
- 自动安装前端和 Electron 依赖(`npm install`,内置国内镜像源)
|
|
12
|
+
- 自动 `git init` 并提交首个 commit(含 lock 文件)
|
|
13
|
+
- 自动生成 `AGENTS.md`(AI 编码助手协作约定)
|
|
14
|
+
- 内置全局亮色/暗色主题切换
|
|
15
|
+
- 可选 sudo 免密配置(`--sudoers`)
|
|
16
|
+
- 可选内置终端(`--terminal`)
|
|
17
|
+
- 可选应用内自动更新(`--update`,飞书云盘发布 + 版本检查 + 下载校验 + 自动安装)
|
|
18
|
+
- 可选自定义应用图标(`--icon`)
|
|
19
|
+
- 内置开发、构建、版本管理命令
|
|
20
|
+
- 自动版本检查与一键升级(`xb --upgrade`)
|
|
21
|
+
- 环境诊断(`xb doctor`)
|
|
22
|
+
- Linux DEB 与 Windows NSIS 安装支持
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 安装 uv(若已有可跳过)
|
|
28
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
29
|
+
|
|
30
|
+
# 方式一:从 PyPI 安装(推荐)
|
|
31
|
+
uv tool install xb-init
|
|
32
|
+
|
|
33
|
+
# 方式二:从源码安装
|
|
34
|
+
git clone -b release_v0 https://github.com/xuebli/xb.git
|
|
35
|
+
cd xb
|
|
36
|
+
uv sync
|
|
37
|
+
uv tool install .
|
|
38
|
+
|
|
39
|
+
# 验证
|
|
40
|
+
xb --help
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 快速开始
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 创建项目
|
|
47
|
+
xb init demo
|
|
48
|
+
|
|
49
|
+
# 带 sudo 免密配置
|
|
50
|
+
xb init demo --sudoers
|
|
51
|
+
|
|
52
|
+
# 带内置终端
|
|
53
|
+
xb init demo --terminal
|
|
54
|
+
|
|
55
|
+
# 同时启用终端和 sudo 免密配置
|
|
56
|
+
xb init demo --terminal --sudoers
|
|
57
|
+
|
|
58
|
+
# 启用应用内自动更新(自动附带 --sudoers 免密,输入 sudo 密码即可)
|
|
59
|
+
xb init demo --update
|
|
60
|
+
|
|
61
|
+
# 带自定义图标
|
|
62
|
+
xb init demo --icon ~/icons/app.png
|
|
63
|
+
|
|
64
|
+
cd demo
|
|
65
|
+
|
|
66
|
+
# 启动开发环境
|
|
67
|
+
xb dev
|
|
68
|
+
|
|
69
|
+
# 查看状态
|
|
70
|
+
xb dev status
|
|
71
|
+
|
|
72
|
+
# 停止
|
|
73
|
+
xb dev stop
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Windows PowerShell 也可以直接运行生成项目脚本:
|
|
77
|
+
|
|
78
|
+
```powershell
|
|
79
|
+
Set-Location demo
|
|
80
|
+
python .\dev.py start
|
|
81
|
+
python .\dev.py status
|
|
82
|
+
python .\dev.py stop
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
使用 `--terminal` 时,Windows 终端使用 PowerShell + ConPTY,支持上下箭头
|
|
86
|
+
命令历史、复制粘贴、Tab 补全和 Ctrl+C;Ubuntu/Debian 使用 bash + Unix PTY。
|
|
87
|
+
|
|
88
|
+
Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入。
|
|
89
|
+
若安装过程被网络中断,生成项目的
|
|
90
|
+
`electron/prepare.js` 会在 `npm start` 或 `npm run build` 前自动检查并补装
|
|
91
|
+
缺失的 Electron 二进制。
|
|
92
|
+
|
|
93
|
+
> **`xb init` 自动行为**:
|
|
94
|
+
> - 执行 `npm install`(frontend + electron),生成 `package-lock.json`
|
|
95
|
+
> - 生成的项目用 [nrm](https://github.com/Pana/nrm) 管理 npm 源:`xb init`
|
|
96
|
+
> 安装依赖前与 `build.py` 构建前都会自动 `nrm test` 测速所有内置源并切换
|
|
97
|
+
> 到最快的(未安装 nrm 时自动全局安装);项目不放 `.npmrc`,npm 源完全由
|
|
98
|
+
> nrm 全局管理
|
|
99
|
+
> - electron 约 200MB 二进制走华为云镜像下载
|
|
100
|
+
> - 若安装失败或超时,会打印提示但不中断项目创建,可稍后手动重试
|
|
101
|
+
> - 执行 `git init` 并提交首个 commit(包含所有文件和 lock 文件)
|
|
102
|
+
> - 若检测到 PyPI 有新版 xb,会询问是否先升级再创建项目
|
|
103
|
+
> - 若系统未安装 git 或未配置 `user.name/user.email`,打印警告但不阻塞
|
|
104
|
+
|
|
105
|
+
## 命令一览
|
|
106
|
+
|
|
107
|
+
| 命令 | 说明 |
|
|
108
|
+
|------|------|
|
|
109
|
+
| `xb init <name> [--sudoers] [--terminal] [--update] [--icon PATH]` | 初始化项目 |
|
|
110
|
+
| `xb dev [start\|stop\|status]` | 启动/停止/查看开发环境 |
|
|
111
|
+
| `xb build [all\|frontend\|backend\|electron]` | 构建项目 |
|
|
112
|
+
| `xb build -f / -b / -e / -a` | 构建快捷 flag |
|
|
113
|
+
| `xb version [patch\|minor\|major]` | 读取或更新版本号 |
|
|
114
|
+
| `xb doctor` | 检查开发环境 |
|
|
115
|
+
| `xb --upgrade` | 升级 xb 到 PyPI 最新版本 |
|
|
116
|
+
|
|
117
|
+
## 应用图标
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# 显式指定图标
|
|
121
|
+
xb init demo --icon ./my-icon.png
|
|
122
|
+
|
|
123
|
+
# 不指定时自动查找以下约定路径:
|
|
124
|
+
# ./app-icon.png, ./icon.png, ./<package>.png,
|
|
125
|
+
# ./assets/app-icon.png, ./assets/icon.png, ./resources/icon.png
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 应用内自动更新(`--update`)
|
|
129
|
+
|
|
130
|
+
`xb init demo --update` 会让生成的项目内置与 [leo_stm32_board_test](../leo_stm32_board_test) 同源的自动更新能力,
|
|
131
|
+
以飞书云盘的一个文件夹作为发布"货架":
|
|
132
|
+
|
|
133
|
+
**生成内容:**
|
|
134
|
+
|
|
135
|
+
| 位置 | 职责 |
|
|
136
|
+
|------|------|
|
|
137
|
+
| `backend/api/update/` | 更新接口(检查 / 信息 / 下载 / 进度 / 安装) |
|
|
138
|
+
| `backend/services/updater.py` | 版本比较、信息拉取、下载校验、配置备份迁移、安装 |
|
|
139
|
+
| `backend/services/feishu_client.py` | 飞书接口封装(文件夹列举、并发下载) |
|
|
140
|
+
| `backend/managers/secret_obfuscator.py` | 敏感值混淆(`obf1:`,防围观级别) |
|
|
141
|
+
| `backend/app_version.py` | 后端版本号(version_manager 提交时自动同步) |
|
|
142
|
+
| `frontend/src/components/UpdateChecker.vue` | 版本号徽章 + 更新弹窗 + 进度条 |
|
|
143
|
+
| `frontend/src/composables/useUpdate.js` | 定时检查 / 下载进度轮询 |
|
|
144
|
+
| `scripts/feishu_upload.py` | 发版端:安装包与版本信息上传飞书 |
|
|
145
|
+
| `configs/config_changes.json` | 配置迁移清单(顶层 key 是版本号) |
|
|
146
|
+
| `build.py` | 增加 `--upload-only` 与构建后发布编排 |
|
|
147
|
+
|
|
148
|
+
**发版流程:** 在 `configs/secrets.yaml` 填 `feishu.app_id` / `app_secret` /
|
|
149
|
+
`update_folder_url` → `./build.py -a` → 确认上传。构建时敏感键自动混淆进
|
|
150
|
+
`secrets.yaml.example` 随包分发,构建结束 example 恢复为留空模板。
|
|
151
|
+
|
|
152
|
+
**客户端:** 启动时 / 每小时 / 点版本号徽章时检查更新;发现新版本后下载
|
|
153
|
+
(4 线程分块 + SHA256 校验 + `.part` 防半截包)→ 备份配置 → 按
|
|
154
|
+
`config_changes.json` 迁移 → Ubuntu 趁应用存活时免密 `sudo dpkg -i`
|
|
155
|
+
(`--update` 默认附带 `--sudoers` 免密),Windows 等退出后静默安装。
|
|
156
|
+
|
|
157
|
+
**飞书侧准备:** 开放平台建自建应用 → 开通 `drive:drive` 权限并发布 →
|
|
158
|
+
建云盘文件夹,完整链接填入 `update_folder_url`。开发模式(源码运行)不支持
|
|
159
|
+
应用内更新,检查接口返回 `packaged: false`。
|
|
160
|
+
|
|
161
|
+
## 生成的项目结构
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
demo/
|
|
165
|
+
├── pyproject.toml # Python 依赖(uv 管理)
|
|
166
|
+
├── AGENTS.md # AI 编码助手协作约定
|
|
167
|
+
├── README.md # 项目说明(含三种启动方式详解)
|
|
168
|
+
├── .gitignore
|
|
169
|
+
├── backend/ # FastAPI 后端
|
|
170
|
+
│ ├── main.py # FastAPI 入口(lifespan / CORS / SPA 兜底)
|
|
171
|
+
│ ├── backend_build.py # PyInstaller 打包脚本
|
|
172
|
+
│ ├── api/ # API 路由层
|
|
173
|
+
│ └── managers/ # 基础设施单例
|
|
174
|
+
├── frontend/ # Vue 3 前端
|
|
175
|
+
│ ├── package.json
|
|
176
|
+
│ ├── package-lock.json
|
|
177
|
+
│ ├── vite.config.js
|
|
178
|
+
│ └── src/
|
|
179
|
+
├── electron/ # Electron 主进程
|
|
180
|
+
│ ├── package.json
|
|
181
|
+
│ ├── package-lock.json
|
|
182
|
+
│ ├── main.js
|
|
183
|
+
│ └── resources/ # icon + Linux DEB hooks
|
|
184
|
+
├── version/ # 版本管理(pre-commit hook)
|
|
185
|
+
├── configs/ # 配置文件
|
|
186
|
+
├── datas/ # 运行时数据(gitignore)
|
|
187
|
+
├── dev.py # 开发脚本(Windows/Linux)
|
|
188
|
+
├── build.py # 打包脚本(Windows/Linux)
|
|
189
|
+
└── .venv # Python 虚拟环境
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## xb 工具自身结构
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
xb/
|
|
196
|
+
├── cli.py # CLI 入口(Click + Rich)
|
|
197
|
+
├── __init__.py # 版本号
|
|
198
|
+
├── commands/ # 子命令实现
|
|
199
|
+
│ ├── init.py # 初始化(升级检查、图标、npm install、git init)
|
|
200
|
+
│ ├── dev.py # 开发环境管理
|
|
201
|
+
│ ├── build.py # 构建
|
|
202
|
+
│ ├── version.py # 版本管理
|
|
203
|
+
│ ├── doctor.py # 环境诊断
|
|
204
|
+
│ └── upgrade.py # 升级 xb
|
|
205
|
+
├── templates/ # Jinja2 项目模板
|
|
206
|
+
│ ├── backend/
|
|
207
|
+
│ ├── frontend/
|
|
208
|
+
│ ├── electron/
|
|
209
|
+
│ ├── configs/
|
|
210
|
+
│ ├── scripts/
|
|
211
|
+
│ ├── version/
|
|
212
|
+
│ └── root/
|
|
213
|
+
└── utils/
|
|
214
|
+
├── template_engine.py # 模板渲染引擎
|
|
215
|
+
├── validators.py # 包名校验
|
|
216
|
+
├── click_helpers.py # 中文化 Help 输出
|
|
217
|
+
└── version_check.py # PyPI 版本检查(24h 缓存)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## 环境要求
|
|
221
|
+
|
|
222
|
+
- **Python**: 3.12+
|
|
223
|
+
- **Node.js**: 16+
|
|
224
|
+
- **npm**: 8+
|
|
225
|
+
- **uv**: 已安装
|
|
226
|
+
- **OS**: Windows 10/11 或 Ubuntu/Debian
|
|
227
|
+
- **Windows 终端**: 使用 `--terminal` 时自动安装 Windows 专用 `pywinpty`
|
|
228
|
+
|
|
229
|
+
Windows 可使用 Python、Node.js、npm 和 uv 的官方安装方式或 `winget` 安装。
|
|
230
|
+
Ubuntu/Debian 可使用系统包管理器或官方安装方式。
|
|
231
|
+
|
|
232
|
+
使用 `xb doctor` 可一键检查所有环境依赖。
|
|
233
|
+
|
|
234
|
+
## 许可证
|
|
235
|
+
|
|
236
|
+
MIT
|