@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
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ /**
3
+ * Interaction Service
4
+ *
5
+ * 提供統一的 UI 互動抽象層,整合 prompts 和原生 readline 功能
6
+ * 隱藏底層庫的實作細節,提供一致的互動介面
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
25
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
26
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
27
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
28
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
29
+ };
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.UserInteraction = void 0;
52
+ const tsyringe_1 = require("tsyringe");
53
+ const prompts_1 = __importDefault(require("prompts"));
54
+ const readline = __importStar(require("readline"));
55
+ /**
56
+ * 簡單的進度指示器實作
57
+ */
58
+ class SimpleProgressIndicator {
59
+ constructor(message, options) {
60
+ this.spinnerIndex = 0;
61
+ this.currentMessage = message;
62
+ this.prefix = options?.prefix || '';
63
+ this.useSpinner = options?.spinner ?? true;
64
+ this.render();
65
+ if (this.useSpinner) {
66
+ this.startSpinner();
67
+ }
68
+ }
69
+ startSpinner() {
70
+ if (!process.stdout.isTTY)
71
+ return;
72
+ this.spinnerInterval = setInterval(() => {
73
+ this.spinnerIndex = (this.spinnerIndex + 1) % SimpleProgressIndicator.SPINNER_CHARS.length;
74
+ this.render();
75
+ }, 80);
76
+ }
77
+ render() {
78
+ if (!process.stdout.isTTY) {
79
+ console.log(`${this.prefix}${this.currentMessage}`);
80
+ return;
81
+ }
82
+ const spinner = this.useSpinner
83
+ ? SimpleProgressIndicator.SPINNER_CHARS[this.spinnerIndex] + ' '
84
+ : '';
85
+ readline.clearLine(process.stdout, 0);
86
+ readline.cursorTo(process.stdout, 0);
87
+ process.stdout.write(`${this.prefix}${spinner}${this.currentMessage}`);
88
+ }
89
+ update(message) {
90
+ this.currentMessage = message;
91
+ this.render();
92
+ }
93
+ done() {
94
+ if (this.spinnerInterval) {
95
+ clearInterval(this.spinnerInterval);
96
+ this.spinnerInterval = undefined;
97
+ }
98
+ if (process.stdout.isTTY) {
99
+ readline.clearLine(process.stdout, 0);
100
+ readline.cursorTo(process.stdout, 0);
101
+ }
102
+ }
103
+ }
104
+ SimpleProgressIndicator.SPINNER_CHARS = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
105
+ /**
106
+ * 建立驗證函式
107
+ */
108
+ function createValidator(options) {
109
+ if (!options)
110
+ return undefined;
111
+ return (value) => {
112
+ // 必填驗證
113
+ if (options.required && !value.trim()) {
114
+ return 'This field is required';
115
+ }
116
+ // 最小長度驗證
117
+ if (options.minLength !== undefined && value.length < options.minLength) {
118
+ return `Minimum length is ${options.minLength} characters`;
119
+ }
120
+ // 最大長度驗證
121
+ if (options.maxLength !== undefined && value.length > options.maxLength) {
122
+ return `Maximum length is ${options.maxLength} characters`;
123
+ }
124
+ // 正則表達式驗證
125
+ if (options.pattern && !options.pattern.test(value)) {
126
+ return 'Invalid format';
127
+ }
128
+ // 自訂驗證器
129
+ if (options.validator) {
130
+ return options.validator(value);
131
+ }
132
+ return true;
133
+ };
134
+ }
135
+ /**
136
+ * UserInteraction 實作
137
+ * 統一 UI 互動的抽象層
138
+ */
139
+ let UserInteraction = class UserInteraction {
140
+ /**
141
+ * 顯示確認提示
142
+ */
143
+ async confirm(message, defaultValue = false) {
144
+ const response = await (0, prompts_1.default)({
145
+ type: 'confirm',
146
+ name: 'value',
147
+ message,
148
+ initial: defaultValue,
149
+ });
150
+ // 如果使用者按 Ctrl+C 中斷,response.value 會是 undefined
151
+ return response.value ?? false;
152
+ }
153
+ /**
154
+ * 顯示選擇提示
155
+ */
156
+ async promptChoice(message, choices, options) {
157
+ const response = await (0, prompts_1.default)({
158
+ type: 'select',
159
+ name: 'value',
160
+ message,
161
+ choices: choices.map((c) => ({
162
+ title: c.title,
163
+ value: c.value,
164
+ description: c.description,
165
+ disabled: c.disabled,
166
+ })),
167
+ initial: options?.initial ?? 0,
168
+ hint: options?.hint,
169
+ });
170
+ return response.value;
171
+ }
172
+ /**
173
+ * 顯示文字輸入提示
174
+ */
175
+ async promptText(message, options) {
176
+ // 合併驗證選項
177
+ let validateFn;
178
+ if (options?.validate) {
179
+ validateFn = options.validate;
180
+ }
181
+ else if (options?.validation) {
182
+ validateFn = createValidator(options.validation);
183
+ }
184
+ const response = await (0, prompts_1.default)({
185
+ type: 'text',
186
+ name: 'value',
187
+ message,
188
+ initial: options?.initial,
189
+ validate: validateFn
190
+ ? (value) => {
191
+ const result = validateFn(value);
192
+ if (typeof result === 'boolean') {
193
+ return result ? true : 'Invalid input';
194
+ }
195
+ return result;
196
+ }
197
+ : undefined,
198
+ });
199
+ return response.value;
200
+ }
201
+ /**
202
+ * 顯示密碼輸入提示
203
+ */
204
+ async promptPassword(message, options) {
205
+ const validateFn = createValidator(options?.validation);
206
+ const response = await (0, prompts_1.default)({
207
+ type: 'password',
208
+ name: 'value',
209
+ message,
210
+ validate: validateFn
211
+ ? (value) => {
212
+ const result = validateFn(value);
213
+ if (typeof result === 'boolean') {
214
+ return result ? true : 'Invalid input';
215
+ }
216
+ return result;
217
+ }
218
+ : undefined,
219
+ });
220
+ // 如果使用者中斷
221
+ if (response.value === undefined) {
222
+ return undefined;
223
+ }
224
+ // 如果需要確認密碼
225
+ if (options?.confirm) {
226
+ const confirmMessage = options.confirmMessage || 'Confirm password';
227
+ const confirmResponse = await (0, prompts_1.default)({
228
+ type: 'password',
229
+ name: 'value',
230
+ message: confirmMessage,
231
+ });
232
+ // 如果使用者中斷確認
233
+ if (confirmResponse.value === undefined) {
234
+ return undefined;
235
+ }
236
+ // 如果密碼不匹配
237
+ if (response.value !== confirmResponse.value) {
238
+ console.log('Passwords do not match');
239
+ return undefined;
240
+ }
241
+ }
242
+ return response.value;
243
+ }
244
+ /**
245
+ * 顯示進度指示器
246
+ */
247
+ showProgress(message, options) {
248
+ return new SimpleProgressIndicator(message, options);
249
+ }
250
+ /**
251
+ * 顯示一般訊息
252
+ */
253
+ log(message) {
254
+ console.log(message);
255
+ }
256
+ /**
257
+ * 顯示空白行
258
+ */
259
+ newLine() {
260
+ console.log('');
261
+ }
262
+ /**
263
+ * 清除當前行
264
+ */
265
+ clearLine() {
266
+ if (process.stdout.isTTY) {
267
+ readline.clearLine(process.stdout, 0);
268
+ readline.cursorTo(process.stdout, 0);
269
+ }
270
+ }
271
+ };
272
+ exports.UserInteraction = UserInteraction;
273
+ exports.UserInteraction = UserInteraction = __decorate([
274
+ (0, tsyringe_1.injectable)()
275
+ ], UserInteraction);
276
+ //# sourceMappingURL=interaction.service.js.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Progress Service Interface
4
+ *
5
+ * 定義 Progress Bar(進度條)進度指示器的介面
6
+ * 用於可預估進度的長時間操作
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=cli-progress.interface.js.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Output Formatter Service Interface
4
+ *
5
+ * 提供統一的輸出格式化抽象層
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.DEFAULT_STATUS_COLORS = void 0;
9
+ /**
10
+ * 預設狀態顏色
11
+ */
12
+ exports.DEFAULT_STATUS_COLORS = {
13
+ Running: 'green',
14
+ Stopped: 'yellow',
15
+ Error: 'red',
16
+ Pending: 'cyan',
17
+ Success: 'green',
18
+ Failed: 'red',
19
+ Warning: 'yellow',
20
+ Active: 'green',
21
+ Inactive: 'yellow',
22
+ };
23
+ //# sourceMappingURL=output-formatter.interface.js.map
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /**
3
+ * Log Level Enum
4
+ *
5
+ * 定義 CLI 輸出的日誌等級
6
+ * 用於控制訊息的顯示與過濾
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OutputLogLevelNames = exports.OutputLogLevel = void 0;
10
+ exports.parseOutputLogLevel = parseOutputLogLevel;
11
+ exports.shouldOutputLevel = shouldOutputLevel;
12
+ /**
13
+ * 日誌等級枚舉
14
+ * 數值越低越詳細,越高越精簡
15
+ */
16
+ var OutputLogLevel;
17
+ (function (OutputLogLevel) {
18
+ /** 除錯等級 - 顯示所有訊息 */
19
+ OutputLogLevel[OutputLogLevel["DEBUG"] = 0] = "DEBUG";
20
+ /** 資訊等級 - 顯示 INFO, WARN, ERROR (預設) */
21
+ OutputLogLevel[OutputLogLevel["INFO"] = 1] = "INFO";
22
+ /** 警告等級 - 顯示 WARN, ERROR */
23
+ OutputLogLevel[OutputLogLevel["WARN"] = 2] = "WARN";
24
+ /** 錯誤等級 - 僅顯示 ERROR */
25
+ OutputLogLevel[OutputLogLevel["ERROR"] = 3] = "ERROR";
26
+ })(OutputLogLevel || (exports.OutputLogLevel = OutputLogLevel = {}));
27
+ /**
28
+ * 日誌等級名稱對應
29
+ */
30
+ exports.OutputLogLevelNames = {
31
+ [OutputLogLevel.DEBUG]: 'DEBUG',
32
+ [OutputLogLevel.INFO]: 'INFO',
33
+ [OutputLogLevel.WARN]: 'WARN',
34
+ [OutputLogLevel.ERROR]: 'ERROR',
35
+ };
36
+ /**
37
+ * 字串轉換為日誌等級
38
+ * @param level - 日誌等級字串 (debug | info | warn | error)
39
+ * @returns 對應的 OutputLogLevel,無效時返回 undefined
40
+ */
41
+ function parseOutputLogLevel(level) {
42
+ const normalized = level.toLowerCase().trim();
43
+ switch (normalized) {
44
+ case 'debug':
45
+ return OutputLogLevel.DEBUG;
46
+ case 'info':
47
+ return OutputLogLevel.INFO;
48
+ case 'warn':
49
+ case 'warning':
50
+ return OutputLogLevel.WARN;
51
+ case 'error':
52
+ return OutputLogLevel.ERROR;
53
+ default:
54
+ return undefined;
55
+ }
56
+ }
57
+ /**
58
+ * 檢查指定等級是否應該被輸出
59
+ * @param messageLevel - 訊息的日誌等級
60
+ * @param currentLevel - 目前設定的日誌等級
61
+ * @returns 是否應該輸出該訊息
62
+ */
63
+ function shouldOutputLevel(messageLevel, currentLevel) {
64
+ return messageLevel >= currentLevel;
65
+ }
66
+ //# sourceMappingURL=log-level.enum.js.map