@uofx/cli 1.0.0

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 (238) hide show
  1. package/LICENSE +40 -0
  2. package/README.md +444 -0
  3. package/THIRD-PARTY-NOTICES.txt +894 -0
  4. package/dist/application/dtos/index.js +24 -0
  5. package/dist/application/dtos/request/delete-instance.request.dto.js +3 -0
  6. package/dist/application/dtos/request/get-config.request.dto.js +3 -0
  7. package/dist/application/dtos/request/get-credentials.request.dto.js +3 -0
  8. package/dist/application/dtos/request/index.js +27 -0
  9. package/dist/application/dtos/request/install-instance.request.dto.js +3 -0
  10. package/dist/application/dtos/request/list-charts.request.dto.js +3 -0
  11. package/dist/application/dtos/request/set-config.request.dto.js +16 -0
  12. package/dist/application/dtos/request/setup-environment.request.dto.js +16 -0
  13. package/dist/application/dtos/request/show-logs.request.dto.js +19 -0
  14. package/dist/application/dtos/request/start-instance.request.dto.js +3 -0
  15. package/dist/application/dtos/request/stop-instance.request.dto.js +3 -0
  16. package/dist/application/dtos/response/credentials.response.dto.js +3 -0
  17. package/dist/application/dtos/response/delete-instance.response.dto.js +3 -0
  18. package/dist/application/dtos/response/index.js +26 -0
  19. package/dist/application/dtos/response/install-instance.response.dto.js +3 -0
  20. package/dist/application/dtos/response/instance-list.response.dto.js +3 -0
  21. package/dist/application/dtos/response/instance-status.response.dto.js +3 -0
  22. package/dist/application/dtos/response/setup-result.response.dto.js +3 -0
  23. package/dist/application/dtos/response/show-logs.response.dto.js +3 -0
  24. package/dist/application/dtos/response/start-instance.response.dto.js +3 -0
  25. package/dist/application/dtos/response/stop-instance.response.dto.js +3 -0
  26. package/dist/application/index.js +25 -0
  27. package/dist/application/interfaces/index.js +24 -0
  28. package/dist/application/interfaces/use-case.interface.js +3 -0
  29. package/dist/application/use-cases/config/get-config.use-case.js +66 -0
  30. package/dist/application/use-cases/config/set-config.use-case.js +49 -0
  31. package/dist/application/use-cases/credentials/get-credentials.use-case.js +57 -0
  32. package/dist/application/use-cases/index.js +28 -0
  33. package/dist/application/use-cases/instance/delete-instance.use-case.js +81 -0
  34. package/dist/application/use-cases/instance/index.js +23 -0
  35. package/dist/application/use-cases/instance/install-instance.use-case.js +424 -0
  36. package/dist/application/use-cases/instance/list-charts.use-case.js +43 -0
  37. package/dist/application/use-cases/instance/list-instances.use-case.js +62 -0
  38. package/dist/application/use-cases/instance/start-instance.use-case.js +154 -0
  39. package/dist/application/use-cases/instance/stop-instance.use-case.js +55 -0
  40. package/dist/application/use-cases/logs/show-logs.use-case.js +66 -0
  41. package/dist/application/use-cases/setup/setup-environment.use-case.js +53 -0
  42. package/dist/cli.js +286 -0
  43. package/dist/constants/config-defaults.js +23 -0
  44. package/dist/constants/defaults.js +89 -0
  45. package/dist/constants/deployment.js +39 -0
  46. package/dist/constants/environments.js +93 -0
  47. package/dist/constants/index.js +53 -0
  48. package/dist/constants/oci-artifacts.js +25 -0
  49. package/dist/constants/paths.js +92 -0
  50. package/dist/constants/timeouts.js +60 -0
  51. package/dist/di/container.js +34 -0
  52. package/dist/di/index.js +22 -0
  53. package/dist/di/modules/application.module.js +54 -0
  54. package/dist/di/modules/infrastructure.module.js +206 -0
  55. package/dist/di/modules/interceptor.module.js +68 -0
  56. package/dist/di/modules/presentation.module.js +31 -0
  57. package/dist/di/tokens.js +149 -0
  58. package/dist/domain/decorators/sensitive.decorator.js +39 -0
  59. package/dist/domain/entities/credentials-resolver.entity.js +127 -0
  60. package/dist/domain/entities/credentials.entity.js +65 -0
  61. package/dist/domain/entities/delete-instance-validation.entity.js +100 -0
  62. package/dist/domain/entities/deployment-parameters.entity.js +120 -0
  63. package/dist/domain/entities/environment-validation.entity.js +125 -0
  64. package/dist/domain/entities/index.js +29 -0
  65. package/dist/domain/entities/instance-lifecycle-state.entity.js +100 -0
  66. package/dist/domain/entities/instance-list-aggregator.entity.js +104 -0
  67. package/dist/domain/entities/instance-metadata.entity.js +86 -0
  68. package/dist/domain/entities/instance-status.entity.js +79 -0
  69. package/dist/domain/entities/instance.entity.js +128 -0
  70. package/dist/domain/entities/log-filter.entity.js +141 -0
  71. package/dist/domain/index.js +29 -0
  72. package/dist/domain/interfaces/safe-loggable.interface.js +3 -0
  73. package/dist/domain/ports/app-config.port.js +3 -0
  74. package/dist/domain/ports/base-image.port.js +3 -0
  75. package/dist/domain/ports/chart-version.port.js +3 -0
  76. package/dist/domain/ports/correlation-id.port.js +3 -0
  77. package/dist/domain/ports/credentials.port.js +3 -0
  78. package/dist/domain/ports/deployment.port.js +3 -0
  79. package/dist/domain/ports/error-handler.port.js +3 -0
  80. package/dist/domain/ports/index.js +46 -0
  81. package/dist/domain/ports/instance-manager.port.js +3 -0
  82. package/dist/domain/ports/instance-metadata.port.js +8 -0
  83. package/dist/domain/ports/instance-storage.port.js +3 -0
  84. package/dist/domain/ports/k8s-deployer.port.js +3 -0
  85. package/dist/domain/ports/logger.port.js +14 -0
  86. package/dist/domain/ports/output.port.js +3 -0
  87. package/dist/domain/ports/runtime-environment.port.js +6 -0
  88. package/dist/domain/ports/user-interaction.port.js +9 -0
  89. package/dist/domain/ports/user-settings.port.js +3 -0
  90. package/dist/domain/types/index.js +22 -0
  91. package/dist/domain/types/logger.types.js +29 -0
  92. package/dist/domain/types/validation.types.js +9 -0
  93. package/dist/domain/value-objects/acr-credentials.value-object.js +92 -0
  94. package/dist/domain/value-objects/chart-version.value-object.js +124 -0
  95. package/dist/domain/value-objects/config-log-level.value-object.js +84 -0
  96. package/dist/domain/value-objects/connection-info.value-object.js +65 -0
  97. package/dist/domain/value-objects/index.js +25 -0
  98. package/dist/domain/value-objects/instance-name.value-object.js +91 -0
  99. package/dist/domain/value-objects/jwt-key.value-object.js +97 -0
  100. package/dist/domain/value-objects/mssql-password.value-object.js +140 -0
  101. package/dist/domain/value-objects/rsa-key-pair.value-object.js +181 -0
  102. package/dist/index.js +6 -0
  103. package/dist/infrastructure/config/app-config.interface.js +3 -0
  104. package/dist/infrastructure/config/app-config.service.js +280 -0
  105. package/dist/infrastructure/config/config-validator.js +31 -0
  106. package/dist/infrastructure/config/crypto.service.js +125 -0
  107. package/dist/infrastructure/deployment/deployment.adapter.js +118 -0
  108. package/dist/infrastructure/deployment/interfaces/acr-credential-manager.interface.js +3 -0
  109. package/dist/infrastructure/deployment/interfaces/app-manager.interface.js +3 -0
  110. package/dist/infrastructure/deployment/interfaces/helm-registry.interface.js +3 -0
  111. package/dist/infrastructure/deployment/interfaces/infra-manager.interface.js +3 -0
  112. package/dist/infrastructure/deployment/interfaces/k8s-job-runner.interface.js +3 -0
  113. package/dist/infrastructure/deployment/interfaces/mssql-database-init.interface.js +3 -0
  114. package/dist/infrastructure/deployment/interfaces/mssql-helm-deployment.interface.js +3 -0
  115. package/dist/infrastructure/deployment/interfaces/mssql-storage.interface.js +3 -0
  116. package/dist/infrastructure/deployment/interfaces/mssql-user-manager.interface.js +3 -0
  117. package/dist/infrastructure/deployment/interfaces/oci-artifact.interface.js +3 -0
  118. package/dist/infrastructure/deployment/interfaces/secret-manager.interface.js +3 -0
  119. package/dist/infrastructure/deployment/interfaces/service-manager.interface.js +3 -0
  120. package/dist/infrastructure/deployment/interfaces/version-compatibility.interface.js +3 -0
  121. package/dist/infrastructure/deployment/services/acr-credential-manager.service.js +144 -0
  122. package/dist/infrastructure/deployment/services/app-manager.service.js +193 -0
  123. package/dist/infrastructure/deployment/services/base-helm-deployment.service.js +163 -0
  124. package/dist/infrastructure/deployment/services/helm-registry.service.js +126 -0
  125. package/dist/infrastructure/deployment/services/infra-manager.service.js +130 -0
  126. package/dist/infrastructure/deployment/services/k8s-job-runner.service.js +194 -0
  127. package/dist/infrastructure/deployment/services/mssql-database-init.service.js +139 -0
  128. package/dist/infrastructure/deployment/services/mssql-helm-deployment.service.js +100 -0
  129. package/dist/infrastructure/deployment/services/mssql-storage.service.js +54 -0
  130. package/dist/infrastructure/deployment/services/mssql-user-manager.service.js +66 -0
  131. package/dist/infrastructure/deployment/services/oci-artifact.service.js +289 -0
  132. package/dist/infrastructure/deployment/services/secret-manager.service.js +179 -0
  133. package/dist/infrastructure/deployment/services/service-manager.service.js +82 -0
  134. package/dist/infrastructure/deployment/services/version-compatibility.service.js +291 -0
  135. package/dist/infrastructure/environment/interfaces/hardware-info.interface.js +3 -0
  136. package/dist/infrastructure/environment/interfaces/network-checker.interface.js +3 -0
  137. package/dist/infrastructure/environment/services/hardware-info.service.js +135 -0
  138. package/dist/infrastructure/environment/services/network-checker.service.js +142 -0
  139. package/dist/infrastructure/environment/windows-environment.adapter.js +162 -0
  140. package/dist/infrastructure/errors/app-error.js +73 -0
  141. package/dist/infrastructure/errors/error-handler.interface.js +3 -0
  142. package/dist/infrastructure/errors/error-handler.js +218 -0
  143. package/dist/infrastructure/errors/exit-codes.js +27 -0
  144. package/dist/infrastructure/errors/index.js +25 -0
  145. package/dist/infrastructure/execution/builders/base-command.builder.js +122 -0
  146. package/dist/infrastructure/execution/builders/host-command.builder.js +58 -0
  147. package/dist/infrastructure/execution/builders/windows-host-command.builder.js +50 -0
  148. package/dist/infrastructure/execution/builders/wsl-command.builder.js +29 -0
  149. package/dist/infrastructure/execution/command-builder.js +252 -0
  150. package/dist/infrastructure/execution/command-executor.service.js +230 -0
  151. package/dist/infrastructure/execution/environments/wsl-execution.environment.js +70 -0
  152. package/dist/infrastructure/execution/execution-environment.factory.js +53 -0
  153. package/dist/infrastructure/execution/index.js +25 -0
  154. package/dist/infrastructure/execution/interfaces/command-builder.interface.js +3 -0
  155. package/dist/infrastructure/execution/interfaces/command-executor.interface.js +3 -0
  156. package/dist/infrastructure/execution/interfaces/execution-environment-factory.interface.js +3 -0
  157. package/dist/infrastructure/execution/interfaces/execution-environment.interface.js +7 -0
  158. package/dist/infrastructure/execution/interfaces/host-command-builder.interface.js +3 -0
  159. package/dist/infrastructure/execution/interfaces/index.js +23 -0
  160. package/dist/infrastructure/execution/interfaces/script-executor.interface.js +3 -0
  161. package/dist/infrastructure/execution/script-executor.service.js +171 -0
  162. package/dist/infrastructure/http/http-client.service.js +176 -0
  163. package/dist/infrastructure/http/index.js +18 -0
  164. package/dist/infrastructure/http/interfaces/http-client.interface.js +3 -0
  165. package/dist/infrastructure/interceptors/index.js +8 -0
  166. package/dist/infrastructure/interceptors/interceptor.factory.js +44 -0
  167. package/dist/infrastructure/interceptors/interceptor.interface.js +3 -0
  168. package/dist/infrastructure/interceptors/logging.interceptor.js +171 -0
  169. package/dist/infrastructure/logger/correlation-id.adapter.js +68 -0
  170. package/dist/infrastructure/logger/index.js +23 -0
  171. package/dist/infrastructure/logger/interfaces/index.js +22 -0
  172. package/dist/infrastructure/logger/interfaces/log-reader.repository.interface.js +7 -0
  173. package/dist/infrastructure/logger/interfaces/log-writer.repository.interface.js +7 -0
  174. package/dist/infrastructure/logger/logger.adapter.js +274 -0
  175. package/dist/infrastructure/logger/services/file-log-reader.repository.js +148 -0
  176. package/dist/infrastructure/logger/services/file-log-writer.repository.js +307 -0
  177. package/dist/infrastructure/logger/services/index.js +22 -0
  178. package/dist/infrastructure/persistence/index.js +25 -0
  179. package/dist/infrastructure/persistence/instance-metadata.adapter.js +100 -0
  180. package/dist/infrastructure/persistence/instance-storage.adapter.js +64 -0
  181. package/dist/infrastructure/persistence/interfaces/config.repository.interface.js +3 -0
  182. package/dist/infrastructure/persistence/interfaces/index.js +22 -0
  183. package/dist/infrastructure/persistence/interfaces/instance.repository.interface.js +3 -0
  184. package/dist/infrastructure/persistence/services/file-system-config.repository.js +168 -0
  185. package/dist/infrastructure/persistence/services/file-system-instance.repository.js +170 -0
  186. package/dist/infrastructure/persistence/services/index.js +22 -0
  187. package/dist/infrastructure/persistence/user-settings.adapter.js +55 -0
  188. package/dist/infrastructure/platform-detector.js +71 -0
  189. package/dist/infrastructure/platforms/windows/interfaces/microk8s.interface.js +3 -0
  190. package/dist/infrastructure/platforms/windows/interfaces/rootfs-manager.interface.js +3 -0
  191. package/dist/infrastructure/platforms/windows/interfaces/windows-features.interface.js +3 -0
  192. package/dist/infrastructure/platforms/windows/interfaces/windows-info.interface.js +3 -0
  193. package/dist/infrastructure/platforms/windows/interfaces/wsl-config.interface.js +3 -0
  194. package/dist/infrastructure/platforms/windows/interfaces/wsl-info.interface.js +3 -0
  195. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-inspection.interface.js +3 -0
  196. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-lifecycle.interface.js +3 -0
  197. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-naming.interface.js +3 -0
  198. package/dist/infrastructure/platforms/windows/interfaces/wsl-manager.interface.js +3 -0
  199. package/dist/infrastructure/platforms/windows/interfaces/wsl-resources.interface.js +8 -0
  200. package/dist/infrastructure/platforms/windows/interfaces/wsl-updater.interface.js +3 -0
  201. package/dist/infrastructure/platforms/windows/interfaces/wslconfig-parser.interface.js +3 -0
  202. package/dist/infrastructure/platforms/windows/parsers/wsl-version.parser.js +133 -0
  203. package/dist/infrastructure/platforms/windows/services/microk8s.service.js +168 -0
  204. package/dist/infrastructure/platforms/windows/services/rootfs-manager.service.js +336 -0
  205. package/dist/infrastructure/platforms/windows/services/windows-features.service.js +191 -0
  206. package/dist/infrastructure/platforms/windows/services/windows-info.service.js +138 -0
  207. package/dist/infrastructure/platforms/windows/services/wsl-config.service.js +171 -0
  208. package/dist/infrastructure/platforms/windows/services/wsl-info.service.js +226 -0
  209. package/dist/infrastructure/platforms/windows/services/wsl-instance-inspection.service.js +325 -0
  210. package/dist/infrastructure/platforms/windows/services/wsl-instance-lifecycle.service.js +442 -0
  211. package/dist/infrastructure/platforms/windows/services/wsl-instance-naming.service.js +93 -0
  212. package/dist/infrastructure/platforms/windows/services/wsl-updater.service.js +273 -0
  213. package/dist/infrastructure/platforms/windows/services/wslconfig-parser.service.js +222 -0
  214. package/dist/infrastructure/platforms/windows/wsl-base-image.adapter.js +41 -0
  215. package/dist/infrastructure/platforms/windows/wsl-instance-manager.adapter.js +150 -0
  216. package/dist/infrastructure/utils/error-formatter.util.js +29 -0
  217. package/dist/infrastructure/utils/file-operations.util.js +201 -0
  218. package/dist/infrastructure/utils/input-validator.util.js +152 -0
  219. package/dist/infrastructure/utils/retry.util.js +98 -0
  220. package/dist/presentation/controllers/config.controller.js +146 -0
  221. package/dist/presentation/controllers/credentials.controller.js +105 -0
  222. package/dist/presentation/controllers/index.js +25 -0
  223. package/dist/presentation/controllers/instance.controller.js +363 -0
  224. package/dist/presentation/controllers/logs.controller.js +103 -0
  225. package/dist/presentation/controllers/setup.controller.js +175 -0
  226. package/dist/presentation/interfaces/cli-options.interface.js +8 -0
  227. package/dist/presentation/prompts/acr-credentials.prompt.js +76 -0
  228. package/dist/presentation/prompts/index.js +21 -0
  229. package/dist/presentation/ui/cli-progress.service.js +193 -0
  230. package/dist/presentation/ui/constants/output-symbols.js +42 -0
  231. package/dist/presentation/ui/index.js +27 -0
  232. package/dist/presentation/ui/interaction.service.js +276 -0
  233. package/dist/presentation/ui/interfaces/cli-progress.interface.js +9 -0
  234. package/dist/presentation/ui/interfaces/output-formatter.interface.js +23 -0
  235. package/dist/presentation/ui/log-level.enum.js +66 -0
  236. package/dist/presentation/ui/output-builder.service.js +378 -0
  237. package/dist/presentation/ui/output-formatter.service.js +393 -0
  238. package/package.json +65 -0
package/LICENSE ADDED
@@ -0,0 +1,40 @@
1
+ # LICENSE
2
+
3
+ Copyright (c) 2025 e-Excellence Inc. All rights reserved.
4
+
5
+ This software (the "Software") is provided "as is", without any express or implied warranty, including, without limitation, warranties of merchantability, fitness for a particular purpose, or non-infringement.
6
+
7
+ ## License Grant
8
+
9
+ Permission is hereby granted to any person obtaining a copy of this Software to install and execute it for **development, testing, and evaluation purposes only**.
10
+
11
+ ## Restrictions
12
+
13
+ You may NOT:
14
+
15
+ 1. Modify, decompile, reverse engineer, or disassemble the Software.
16
+ 2. Redistribute, sublicense, or sell copies of the Software without prior written permission.
17
+ 3. Use the Software to deploy, manage, or operate environments intended for production use.
18
+ 4. Use the name of e-Excellence Inc. to endorse, promote, or market any product derived from this Software without specific prior written permission.
19
+
20
+ ## Third-Party Software Notice
21
+
22
+ This Software may facilitate the installation or use of third-party software components, including but not limited to **Microsoft SQL Server Developer Edition**.
23
+
24
+ 1. **Independent Licensing**: Such third-party software is licensed to you directly by its respective licensors (e.g., Microsoft) and is subject to their own license terms (EULA).
25
+ 2. **Compliance**: You are solely responsible for complying with all license terms, restrictions, and usage policies of any third-party software installed by this tool.
26
+ 3. **No Warranty**: e-Excellence Inc. does not grant any rights to, and makes no representations or warranties regarding, any third-party software.
27
+
28
+ ## User Notice Regarding SQL Server
29
+
30
+ **WARNING: Strict Usage Limitations**
31
+
32
+ 1. The Microsoft SQL Server Developer Edition installed by this tool is strictly limited by Microsoft for **development, testing, and demonstration purposes only**.
33
+ 2. **Production Use Prohibited**: It may NOT be used in a production environment. Production use requires a separate, paid license from Microsoft.
34
+ 3. You acknowledge that any violation of Microsoft's licensing terms is your sole responsibility.
35
+
36
+ ## Acknowledgment
37
+
38
+ By using this Software, you agree to comply with the terms stated above. Any violation of this license or restrictions is at your own legal risk.
39
+
40
+ ---
package/README.md ADDED
@@ -0,0 +1,444 @@
1
+ # UOFX CLI
2
+
3
+ > 🚀 在 Windows WSL 環境中快速部署和管理 UOFX 開發環境的命令列工具
4
+
5
+ ---
6
+
7
+ ## ✨ 主要功能
8
+
9
+ - ✅ **環境檢查與自動安裝** - 驗證系統需求,可自動安裝 WSL 環境
10
+ - 🐳 **容器化隔離** - 使用 WSL + Kubernetes 建立完全隔離的開發環境
11
+ - 🎯 **多實例管理** - 建立多個獨立環境,輕鬆切換專案
12
+ - 📊 **即時狀態監控** - 查看實例運行狀態與資源使用
13
+ - 🔐 **憑證管理** - 安全儲存並快速取得登入資訊
14
+ - 📝 **詳細日誌** - 完整的操作記錄,協助除錯
15
+
16
+ ---
17
+
18
+ ## 📋 系統需求
19
+
20
+ | 項目 | 需求 |
21
+ |------|------|
22
+ | 作業系統 | Windows 10/11 |
23
+ | Node.js | 18.20.0 或更高版本 |
24
+ | 記憶體 | 最低 16 GB |
25
+ | 網路 | 需要連線至容器倉庫 |
26
+
27
+ > **注意**:WSL 可透過 CLI 自動安裝(需系統管理員權限)
28
+
29
+ ---
30
+
31
+ ## 🚀 安裝
32
+
33
+ ```bash
34
+ npm install -g @uofx/cli
35
+ ```
36
+
37
+ 驗證安裝:
38
+
39
+ ```bash
40
+ uofx --version
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 快速開始
46
+
47
+ ### 1️⃣ 環境檢查
48
+
49
+ ```bash
50
+ uofx env setup
51
+ ```
52
+
53
+ > 如果 WSL 未安裝,請以**系統管理員身份**執行此指令進行自動安裝
54
+
55
+ ### 2️⃣ 安裝開發環境
56
+
57
+ ```bash
58
+ uofx env install --name dev
59
+ ```
60
+
61
+ > ⏱️ **注意**:安裝過程需要下載容器映像檔,通常需要 **15 分鐘以上**,實際時間依網路速度而定。
62
+
63
+
64
+ ### 3️⃣ 取得連線資訊
65
+
66
+ ```bash
67
+ uofx env list credentials --name dev --reveal
68
+ ```
69
+
70
+ 完成!現在你可以使用顯示的帳號密碼登入開發環境了。
71
+
72
+ ---
73
+
74
+ ## 💡 使用範例
75
+
76
+ ### 查看所有實例
77
+
78
+ ```bash
79
+ uofx env list
80
+ ```
81
+
82
+ 輸出示例:
83
+ ```
84
+ NAME STATUS VERSION CHART VERSION ADMIN URL SQL SERVER
85
+ ───────────────────────────────────────────────────────────────────────────────────
86
+ dev Running 2 2.100.002 http://[ip]:16888 [ip],30022
87
+ test Stopped 2 2.100.001
88
+ ```
89
+
90
+ ### 多專案環境管理
91
+
92
+ ```bash
93
+ # 建立專案 A 的環境
94
+ uofx env install --name project-a
95
+
96
+ # 建立專案 B 的環境
97
+ uofx env install --name project-b
98
+
99
+ # 切換到專案 A(會自動停止其他運行中的實例)
100
+ uofx env start --name project-a
101
+
102
+ # 停止實例
103
+ uofx env stop --name project-a
104
+
105
+ # 不再需要時刪除
106
+ uofx env delete --name project-a
107
+ ```
108
+
109
+ ### 指定版本安裝
110
+
111
+ ```bash
112
+ # 查看可用版本
113
+ uofx env list charts
114
+
115
+ # 安裝特定版本
116
+ uofx env install --name dev --chart-version 1.2.0
117
+ ```
118
+
119
+ ### 除錯模式
120
+
121
+ ```bash
122
+ # 啟用詳細日誌
123
+ uofx config set --log-level debug
124
+
125
+ # 查看日誌
126
+ uofx logs --level DEBUG --since 10m
127
+
128
+ # 過濾特定指令的日誌
129
+ uofx logs --command env.install
130
+ ```
131
+
132
+ ---
133
+
134
+ ## 📖 指令參考
135
+
136
+ ### 環境管理 (env)
137
+
138
+ #### `env setup`
139
+ 檢查並驗證系統環境,若 WSL 未安裝可自動進行安裝。
140
+
141
+ ```bash
142
+ uofx env setup
143
+ ```
144
+
145
+ > **注意**:若需要安裝 WSL,必須以系統管理員身份執行。
146
+
147
+ #### `env install`
148
+ 安裝並部署 UOFX 開發環境。
149
+
150
+ ```bash
151
+ uofx env install [選項]
152
+ ```
153
+
154
+ > ⏱️ **安裝時間**:需要下載容器映像檔,通常需要 15 分鐘以上,實際時間依網路速度而定。
155
+
156
+ **選項:**
157
+ - `--name <name>` - 實例名稱(預設:`dev`)
158
+ - `--chart-version <version>` - 指定 Helm chart(UOFX) 版本(預設:最新版本)
159
+
160
+ **範例:**
161
+ ```bash
162
+ # 使用預設名稱
163
+ uofx env install
164
+
165
+ # 指定名稱和版本
166
+ uofx env install --name my-project --chart-version 1.2.0
167
+ ```
168
+
169
+ #### `env list`
170
+ 顯示實例、憑證或相容版本資訊。
171
+
172
+ ```bash
173
+ uofx env list [type] [選項]
174
+ ```
175
+
176
+ **類型(type):**
177
+ - `instances` - 列出所有實例(預設)
178
+ - `charts` - 列出相容的 chart(UOFX) 版本
179
+ - `credentials` - 顯示實例憑證(需要 `--name`)
180
+
181
+ **選項:**
182
+ - `--name <name>` - 實例名稱(credentials 類型必填)
183
+ - `--reveal` - 顯示完整憑證(搭配 credentials 使用)
184
+
185
+ **範例:**
186
+ ```bash
187
+ uofx env list # 列出所有實例
188
+ uofx env list charts # 列出相容的 UOFX 版本
189
+ uofx env list credentials --name dev --reveal # 查看完整憑證
190
+ ```
191
+
192
+ #### `env start`
193
+ 啟動指定的 UOFX 實例。
194
+
195
+ ```bash
196
+ uofx env start --name <name>
197
+ ```
198
+
199
+ > **提示**:若有其他實例正在運行,CLI 會詢問是否停止該實例。
200
+
201
+ #### `env stop`
202
+ 停止指定的 UOFX 實例。
203
+
204
+ ```bash
205
+ uofx env stop --name <name>
206
+ ```
207
+
208
+ #### `env delete`
209
+ 刪除指定的 UOFX 實例。
210
+
211
+ ```bash
212
+ uofx env delete --name <name> [選項]
213
+ ```
214
+
215
+ **選項:**
216
+ - `-f, --force` - 跳過確認提示
217
+
218
+ > ⚠️ **警告**:請務必使用此指令來刪除實例,**請勿**直接使用 `wsl --unregister` 指令。
219
+
220
+ ---
221
+
222
+ ### 設定管理 (config)
223
+
224
+ #### `config list`
225
+ 列出所有設定值。
226
+
227
+ ```bash
228
+ uofx config list [選項]
229
+ ```
230
+
231
+ #### `config set`
232
+ 設定配置值。
233
+
234
+ ```bash
235
+ uofx config set [選項]
236
+ ```
237
+
238
+ **選項:**
239
+ - `--log-level <level>` - 日誌等級(`debug`、`info`、`error`)
240
+ - `--acr.name <name>` - ACR 名稱
241
+ - `--acr.account <account>` - ACR 帳號
242
+ - `--acr.password <password>` - ACR 密碼
243
+
244
+ **範例:**
245
+ ```bash
246
+ # 設定日誌等級
247
+ uofx config set --log-level debug
248
+
249
+ # 設定 ACR 連線資訊
250
+ uofx config set --acr.name myregistry --acr.account user --acr.password secret
251
+ ```
252
+
253
+ ---
254
+
255
+ ### 日誌查看 (logs)
256
+
257
+ 查看和過濾 CLI 操作日誌。
258
+
259
+ ```bash
260
+ uofx logs [選項]
261
+ ```
262
+
263
+ **選項:**
264
+ - `--lines <number>` - 顯示行數(預設:`50`)
265
+ - `--level <level>` - 過濾日誌等級(`DEBUG`、`INFO`、`ERROR`)
266
+ - `--since <range>` - 時間範圍(例如:`1h`、`2d`、`30m`)
267
+ - `--correlation <id>` - 依關聯 ID 過濾
268
+ - `--command <command>` - 依指令過濾(例如:`env.install`)
269
+ - `--command-group <group>` - 依指令群組過濾(例如:`env`)
270
+
271
+ **範例:**
272
+ ```bash
273
+ uofx logs # 查看最近日誌
274
+ uofx logs --level ERROR # 只看錯誤
275
+ uofx logs --since 1h # 過去一小時的日誌
276
+ uofx logs --command env.install # 特定指令的日誌
277
+ ```
278
+
279
+ ---
280
+
281
+ ## ⚠️ 重要限制
282
+
283
+ ### 實例互斥
284
+
285
+ **由於 WSL 架構限制,所有 WSL 實例共用同一個 IP 位址**,因此:
286
+
287
+ - ⚠️ 同一時間只能有**一個**實例處於「執行中」狀態
288
+ - ⚠️ 以下連接埠會被佔用,請確保沒有其他服務使用
289
+
290
+ | 服務 | 連接埠 |
291
+ |------|--------|
292
+ | 前台網站 (HTTP) | 80 |
293
+ | 前台網站 (HTTPS) | 443 |
294
+ | 後台管理 (HTTP) | 16888 |
295
+ | 後台管理 (HTTPS) | 16890 |
296
+ | 手機入口 | 9000 |
297
+ | SQL Server | 30022 |
298
+
299
+ > 💡 **提示**:當啟動實例時,CLI 會自動檢測衝突並詢問是否停止其他實例
300
+
301
+ ### 與本機服務的連接埠衝突
302
+
303
+ 如果您的 Windows 主機上有其他服務正在使用相同連接埠(如 IIS、Apache、Nginx 等),將會發生衝突。
304
+
305
+ **解決方式:停用 localhost 轉發**
306
+
307
+ 如果您需要同時運行本機服務和 UOFX,可以停用 WSL 的 localhost 轉發功能。
308
+
309
+ **步驟:**
310
+
311
+ 1. 在 Windows 使用者目錄建立 `.wslconfig` 檔案:
312
+ ```powershell
313
+ notepad $env:USERPROFILE\.wslconfig
314
+ ```
315
+
316
+ 2. 加入以下內容:
317
+ ```ini
318
+ [wsl2]
319
+ localhostForwarding=false
320
+ ```
321
+
322
+ 3. 重啟 WSL:
323
+ ```powershell
324
+ wsl --shutdown
325
+ ```
326
+
327
+ 4. 重新啟動 UOFX 實例:
328
+ ```bash
329
+ uofx env start --name dev
330
+ ```
331
+
332
+ **使用 WSL IP 存取:**
333
+
334
+ 停用 localhost 轉發後,您需要使用 WSL 的實際 IP 位址來存取服務:
335
+
336
+ ```bash
337
+ # 查看實例資訊(包含 IP)
338
+ uofx env list
339
+
340
+ # 輸出範例:
341
+ # NAME STATUS VERSION ADMIN URL SQL SERVER
342
+ # dev Running 2 http://[IP]:16888 [IP],30022
343
+ ```
344
+
345
+ **注意事項:**
346
+ - ⚠️ 無法再使用 `localhost` 或 `127.0.0.1` 存取
347
+
348
+ ---
349
+
350
+ ## 🔧 常見問題
351
+
352
+ ### WSL 未安裝
353
+
354
+ **問題**:執行 `uofx env setup` 顯示 Runtime 未安裝
355
+
356
+ **解決方案**:
357
+ 1. 以**系統管理員身份**開啟 PowerShell
358
+ 2. 執行 `uofx env setup`
359
+ 3. 依照提示完成 WSL 安裝
360
+ 4. 重新啟動電腦
361
+
362
+ ### 記憶體不足
363
+
364
+ **問題**:環境檢查顯示記憶體不足
365
+
366
+ **解決方案**:
367
+ - 關閉不必要的應用程式
368
+ - 確保至少有 16 GB 可用記憶體
369
+
370
+ ### 實例無法啟動
371
+
372
+ **問題**:`uofx env start` 執行失敗
373
+
374
+ **解決方案**:
375
+ ```bash
376
+ # 1. 檢查是否有其他實例運行
377
+ uofx env list
378
+
379
+ # 2. 停止衝突的實例
380
+ uofx env stop --name <其他實例>
381
+
382
+ # 3. 查看錯誤日誌
383
+ uofx logs --level ERROR --since 5m
384
+ ```
385
+
386
+ ### 安裝過程中斷
387
+
388
+ **問題**:安裝意外中斷
389
+
390
+ **解決方案**:
391
+ ```bash
392
+ # 刪除失敗的實例
393
+ uofx env delete --name <實例名稱> --force
394
+
395
+ # 重新安裝
396
+ uofx env install --name <實例名稱>
397
+ ```
398
+
399
+ ### 取得詳細協助
400
+
401
+ ```bash
402
+ # 啟用除錯模式
403
+ uofx config set --log-level debug
404
+
405
+ # 查看詳細日誌
406
+ uofx logs --since 1h
407
+ ```
408
+
409
+ ---
410
+
411
+ ## 📚 運作原理
412
+
413
+ 本工具採用「容器化」概念來隔離開發環境:
414
+
415
+ ```mermaid
416
+ flowchart LR
417
+ A[UOFX CLI] --> B[建立 WSL 實例]
418
+ B --> C[安裝 MicroK8s]
419
+ C --> D[部署 UOFX 服務]
420
+ D --> E[開發環境就緒]
421
+
422
+ style A fill:#4CAF50
423
+ style E fill:#2196F3
424
+ ```
425
+
426
+ **兩個主要步驟:**
427
+
428
+ 1. **建立 WSL 實例** - 在 Windows 上建立獨立的 Ubuntu 環境(類似輕量級虛擬機)
429
+ 2. **部署 UOFX 服務** - 在 WSL 內安裝 Kubernetes 並部署所有微服務
430
+
431
+ **優點**:
432
+ - ✅ 完全隔離,不影響本機環境
433
+ - ✅ 可建立多個獨立實例
434
+ - ✅ 刪除實例即可完全清除
435
+
436
+ ---
437
+
438
+ ## 📄 授權
439
+
440
+ 請參閱 [LICENSE](./LICENSE) 檔案
441
+
442
+ ---
443
+
444
+ _UOFX CLI v1.0.0_