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.
Files changed (104) hide show
  1. {xb_init-2.0.5 → xb_init-2.2.2}/.gitignore +38 -38
  2. {xb_init-2.0.5 → xb_init-2.2.2}/PKG-INFO +51 -12
  3. {xb_init-2.0.5 → xb_init-2.2.2}/README.md +236 -197
  4. {xb_init-2.0.5 → xb_init-2.2.2}/pyproject.toml +62 -62
  5. xb_init-2.2.2/tests/test_cli.py +88 -0
  6. xb_init-2.2.2/tests/test_update_templates.py +77 -0
  7. xb_init-2.2.2/uv.lock +445 -0
  8. {xb_init-2.0.5 → xb_init-2.2.2}/xb/__init__.py +10 -10
  9. {xb_init-2.0.5 → xb_init-2.2.2}/xb/cli.py +86 -86
  10. {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/__init__.py +1 -1
  11. {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/build.py +79 -79
  12. {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/dev.py +49 -49
  13. {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/doctor.py +91 -91
  14. {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/init.py +438 -344
  15. {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/upgrade.py +27 -27
  16. {xb_init-2.0.5 → xb_init-2.2.2}/xb/commands/version.py +65 -65
  17. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/__init__.py.j2 +3 -3
  18. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/config.py.j2 +295 -371
  19. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/ports.py.j2 +105 -105
  20. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/terminal/__init__.py.j2 +3 -3
  21. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/api/terminal/routes.py.j2 +258 -258
  22. xb_init-2.2.2/xb/templates/backend/api/update/__init__.py.j2 +188 -0
  23. xb_init-2.2.2/xb/templates/backend/app_version.py.j2 +11 -0
  24. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/backend_build.py.j2 +49 -42
  25. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/main.py.j2 +145 -122
  26. xb_init-2.2.2/xb/templates/backend/managers/__init__.py.j2 +7 -0
  27. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/managers/logger_manager.py.j2 +53 -48
  28. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/managers/path_manager.py.j2 +352 -256
  29. xb_init-2.2.2/xb/templates/backend/managers/secret_obfuscator.py.j2 +123 -0
  30. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/managers/sudoers_manager.py.j2 +165 -151
  31. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/backend/requirements.txt.j2 +8 -8
  32. xb_init-2.2.2/xb/templates/backend/services/__init__.py.j2 +1 -0
  33. xb_init-2.2.2/xb/templates/backend/services/feishu_client.py.j2 +264 -0
  34. xb_init-2.2.2/xb/templates/backend/services/updater.py.j2 +712 -0
  35. xb_init-2.2.2/xb/templates/configs/config_changes.json.j2 +1 -0
  36. xb_init-2.2.2/xb/templates/configs/global_config.yaml.j2 +3 -0
  37. xb_init-2.2.2/xb/templates/configs/secrets.yaml.example.j2 +9 -0
  38. xb_init-2.2.2/xb/templates/configs/secrets.yaml.j2 +9 -0
  39. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/launcher.js.j2 +189 -189
  40. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/main.js.j2 +258 -258
  41. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/package.json.j2 +81 -81
  42. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/port_diagnostics.js.j2 +187 -187
  43. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/preload.js.j2 +11 -11
  44. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/prepare.js.j2 +43 -43
  45. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/resources/postinst.py.j2 +163 -131
  46. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/resources/postrm.py.j2 +34 -34
  47. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/electron/resources/uninstaller.nsh.j2 +44 -44
  48. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/index.html.j2 +12 -12
  49. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/package.json.j2 +21 -21
  50. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/App.vue.j2 +106 -109
  51. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/ConfigSetup.vue.j2 +227 -260
  52. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/DashboardHome.vue.j2 +40 -40
  53. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/FileManager.vue.j2 +428 -617
  54. xb_init-2.2.2/xb/templates/frontend/src/components/GitVersionBadge.vue.j2 +297 -0
  55. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/RefreshButton.vue.j2 +147 -147
  56. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/TerminalPanel.vue.j2 +248 -236
  57. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/TerminalView.vue.j2 +229 -211
  58. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/components/ThemeToggle.vue.j2 +49 -49
  59. xb_init-2.2.2/xb/templates/frontend/src/components/version/CommitHistoryPanel.vue.j2 +286 -0
  60. xb_init-2.2.2/xb/templates/frontend/src/components/version/UpdatePanel.vue.j2 +766 -0
  61. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/composables/useTerminalSessions.js.j2 +125 -125
  62. xb_init-2.2.2/xb/templates/frontend/src/composables/useUpdate.js.j2 +295 -0
  63. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/main.js.j2 +5 -5
  64. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/src/style.css.j2 +596 -594
  65. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/frontend/vite.config.js.j2 +74 -74
  66. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/.gitignore.j2 +41 -35
  67. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/AGENTS.md.j2 +519 -455
  68. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/README.md.j2 +449 -371
  69. xb_init-2.2.2/xb/templates/root/build.py.j2 +448 -0
  70. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/dev.py.j2 +268 -268
  71. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/root/pyproject.toml.j2 +29 -29
  72. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/scripts/example.py.j2 +4 -4
  73. xb_init-2.2.2/xb/templates/scripts/feishu_upload.py.j2 +656 -0
  74. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/version/scripts/gui_version_manager.py.j2 +484 -466
  75. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/version/scripts/version_manager.py.j2 +174 -114
  76. {xb_init-2.0.5 → xb_init-2.2.2}/xb/templates/version/scripts/web_version_manager.py.j2 +302 -284
  77. {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/__init__.py +1 -1
  78. {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/click_helpers.py +96 -96
  79. {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/template_engine.py +405 -338
  80. {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/validators.py +8 -8
  81. {xb_init-2.0.5 → xb_init-2.2.2}/xb/utils/version_check.py +183 -183
  82. xb_init-2.0.5/.claude/settings.local.json +0 -13
  83. xb_init-2.0.5/.codegraph/.gitignore +0 -5
  84. xb_init-2.0.5/.codegraph/codegraph.db +0 -0
  85. xb_init-2.0.5/.tmp_hookpath_test/custom-hooks/pre-commit +0 -5
  86. xb_init-2.0.5/.tmp_hookpath_test/pyproject.toml +0 -0
  87. xb_init-2.0.5/.tmp_hookpath_test/version/scripts/version_manager.py +0 -118
  88. xb_init-2.0.5/.tmp_hookpath_test/version/scripts/web_version_manager.py +0 -285
  89. xb_init-2.0.5/tests/test_cli.py +0 -14
  90. xb_init-2.0.5/uv.lock +0 -445
  91. xb_init-2.0.5/xb/templates/backend/managers/__init__.py.j2 +0 -7
  92. xb_init-2.0.5/xb/templates/configs/global_config.yaml.j2 +0 -4
  93. xb_init-2.0.5/xb/templates/configs/secrets.yaml.example.j2 +0 -3
  94. xb_init-2.0.5/xb/templates/configs/secrets.yaml.j2 +0 -3
  95. xb_init-2.0.5/xb/templates/electron/.npmrc.j2 +0 -10
  96. xb_init-2.0.5/xb/templates/frontend/.npmrc.j2 +0 -7
  97. xb_init-2.0.5/xb/templates/frontend/src/components/GitVersionBadge.vue.j2 +0 -359
  98. xb_init-2.0.5/xb/templates/root/build.py.j2 +0 -68
  99. xb_init-2.0.5/xb/templates/version/hooks/pre-commit.py.j2 +0 -43
  100. xb_init-2.0.5/xb/templates/version/scripts/install_hooks.py.j2 +0 -77
  101. {xb_init-2.0.5 → xb_init-2.2.2}/docs/screenshot.png +0 -0
  102. {xb_init-2.0.5 → xb_init-2.2.2}/tests/test_upgrade.py +0 -0
  103. /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
  104. /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.0.5
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/yourusername/xb
6
- Project-URL: Documentation, https://github.com/yourusername/xb#readme
7
- Project-URL: Repository, https://github.com/yourusername/xb.git
8
- Project-URL: Issues, https://github.com/yourusername/xb/issues
9
- Author-email: XB Team <xb@example.com>
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` 环境变量注入,不向 `.npmrc`
114
- 写 npm 不识别的自定义键。若安装过程被网络中断,生成项目的
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
- > - 生成的 `.npmrc` 已配好华为云镜像;electron 约 200MB 二进制也走镜像下载
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
- ![首页截图](docs/screenshot.png)
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
- - 可选自定义应用图标(`--icon`)
18
- - 内置开发、构建、版本管理命令
19
- - 自动版本检查与一键升级(`xb --upgrade`)
20
- - 环境诊断(`xb doctor`)
21
- - Linux DEB 与 Windows NSIS 安装支持
22
-
23
- ## 安装
24
-
25
- ```bash
26
- # 安装 uv(若已有可跳过)
27
- curl -LsSf https://astral.sh/uv/install.sh | sh
28
-
29
- # 方式一:从 PyPI 安装(推荐)
30
- uv tool install xb-init
31
-
32
- # 方式二:从源码安装
33
- git clone -b release_v0 https://github.com/xuebli/xb.git
34
- cd xb
35
- uv sync
36
- uv tool install .
37
-
38
- # 验证
39
- xb --help
40
- ```
41
-
42
- ## 快速开始
43
-
44
- ```bash
45
- # 创建项目
46
- xb init demo
47
-
48
- # 带 sudo 免密配置
49
- xb init demo --sudoers
50
-
51
- # 带内置终端
52
- xb init demo --terminal
53
-
54
- # 同时启用终端和 sudo 免密配置
55
- xb init demo --terminal --sudoers
56
-
57
- # 带自定义图标
58
- xb init demo --icon ~/icons/app.png
59
-
60
- cd demo
61
-
62
- # 启动开发环境
63
- xb dev
64
-
65
- # 查看状态
66
- xb dev status
67
-
68
- # 停止
69
- xb dev stop
70
- ```
71
-
72
- Windows PowerShell 也可以直接运行生成项目脚本:
73
-
74
- ```powershell
75
- Set-Location demo
76
- python .\dev.py start
77
- python .\dev.py status
78
- python .\dev.py stop
79
- ```
80
-
81
- 使用 `--terminal` 时,Windows 终端使用 PowerShell + ConPTY,支持上下箭头
82
- 命令历史、复制粘贴、Tab 补全和 Ctrl+C;Ubuntu/Debian 使用 bash + Unix PTY。
83
-
84
- Electron 二进制镜像通过 `ELECTRON_MIRROR` 环境变量注入,不向 `.npmrc`
85
- 写 npm 不识别的自定义键。若安装过程被网络中断,生成项目的
86
- `electron/prepare.js` 会在 `npm start` 或 `npm run build` 前自动检查并补装
87
- 缺失的 Electron 二进制。
88
-
89
- > **`xb init` 自动行为**:
90
- > - 执行 `npm install`(frontend + electron),生成 `package-lock.json`
91
- > - 生成的 `.npmrc` 已配好华为云镜像;electron 约 200MB 二进制也走镜像下载
92
- > - 若安装失败或超时,会打印提示但不中断项目创建,可稍后手动重试
93
- > - 执行 `git init` 并提交首个 commit(包含所有文件和 lock 文件)
94
- > - 若检测到 PyPI 有新版 xb,会询问是否先升级再创建项目
95
- > - 若系统未安装 git 或未配置 `user.name/user.email`,打印警告但不阻塞
96
-
97
- ## 命令一览
98
-
99
- | 命令 | 说明 |
100
- |------|------|
101
- | `xb init <name> [--sudoers] [--terminal] [--icon PATH]` | 初始化项目 |
102
- | `xb dev [start\|stop\|status]` | 启动/停止/查看开发环境 |
103
- | `xb build [all\|frontend\|backend\|electron]` | 构建项目 |
104
- | `xb build -f / -b / -e / -a` | 构建快捷 flag |
105
- | `xb version [patch\|minor\|major]` | 读取或更新版本号 |
106
- | `xb doctor` | 检查开发环境 |
107
- | `xb --upgrade` | 升级 xb 到 PyPI 最新版本 |
108
-
109
- ## 应用图标
110
-
111
- ```bash
112
- # 显式指定图标
113
- xb init demo --icon ./my-icon.png
114
-
115
- # 不指定时自动查找以下约定路径:
116
- # ./app-icon.png, ./icon.png, ./<package>.png,
117
- # ./assets/app-icon.png, ./assets/icon.png, ./resources/icon.png
118
- ```
119
-
120
- ## 生成的项目结构
121
-
122
- ```
123
- demo/
124
- ├── pyproject.toml # Python 依赖(uv 管理)
125
- ├── AGENTS.md # AI 编码助手协作约定
126
- ├── README.md # 项目说明(含三种启动方式详解)
127
- ├── .gitignore
128
- ├── backend/ # FastAPI 后端
129
- │ ├── main.py # FastAPI 入口(lifespan / CORS / SPA 兜底)
130
- │ ├── backend_build.py # PyInstaller 打包脚本
131
- │ ├── api/ # API 路由层
132
- │ └── managers/ # 基础设施单例
133
- ├── frontend/ # Vue 3 前端
134
- │ ├── package.json
135
- │ ├── package-lock.json
136
- │ ├── .npmrc # npm 镜像源(华为云)
137
- │ ├── vite.config.js
138
- │ └── src/
139
- ├── electron/ # Electron 主进程
140
- │ ├── package.json
141
- │ ├── package-lock.json
142
- │ ├── .npmrc # npm + electron 二进制镜像源
143
- │ ├── main.js
144
- │ └── resources/ # icon + Linux DEB hooks
145
- ├── version/ # 版本管理(pre-commit hook)
146
- ├── configs/ # 配置文件
147
- ├── datas/ # 运行时数据(gitignore)
148
- ├── dev.py # 开发脚本(Windows/Linux)
149
- ├── build.py # 打包脚本(Windows/Linux)
150
- └── .venv # Python 虚拟环境
151
- ```
152
-
153
- ## xb 工具自身结构
154
-
155
- ```
156
- xb/
157
- ├── cli.py # CLI 入口(Click + Rich)
158
- ├── __init__.py # 版本号
159
- ├── commands/ # 子命令实现
160
- │ ├── init.py # 初始化(升级检查、图标、npm install、git init)
161
- │ ├── dev.py # 开发环境管理
162
- │ ├── build.py # 构建
163
- │ ├── version.py # 版本管理
164
- │ ├── doctor.py # 环境诊断
165
- │ └── upgrade.py # 升级 xb
166
- ├── templates/ # Jinja2 项目模板
167
- │ ├── backend/
168
- │ ├── frontend/
169
- │ ├── electron/
170
- │ ├── configs/
171
- │ ├── scripts/
172
- │ ├── version/
173
- │ └── root/
174
- └── utils/
175
- ├── template_engine.py # 模板渲染引擎
176
- ├── validators.py # 包名校验
177
- ├── click_helpers.py # 中文化 Help 输出
178
- └── version_check.py # PyPI 版本检查(24h 缓存)
179
- ```
180
-
181
- ## 环境要求
182
-
183
- - **Python**: 3.12+
184
- - **Node.js**: 16+
185
- - **npm**: 8+
186
- - **uv**: 已安装
187
- - **OS**: Windows 10/11 或 Ubuntu/Debian
188
- - **Windows 终端**: 使用 `--terminal` 时自动安装 Windows 专用 `pywinpty`
189
-
190
- Windows 可使用 Python、Node.js、npm 和 uv 的官方安装方式或 `winget` 安装。
191
- Ubuntu/Debian 可使用系统包管理器或官方安装方式。
192
-
193
- 使用 `xb doctor` 可一键检查所有环境依赖。
194
-
195
- ## 许可证
196
-
197
- MIT
1
+ # xb - 前后端打包构建工具
2
+
3
+ **xb**(PyPI: `xb-init`)是一个基于 `uv` 又类似 `uv` 的项目管理工具,专为快速初始化 **UV + FastAPI + Vue3 + Electron** 桌面应用而生。一条命令拉起完整工程脚手架,开发、构建、版本管理一站式搞定。
4
+
5
+ ![首页截图](docs/screenshot.png)
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