@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.
- package/LICENSE +40 -0
- package/README.md +444 -0
- package/THIRD-PARTY-NOTICES.txt +894 -0
- package/dist/application/dtos/index.js +24 -0
- package/dist/application/dtos/request/delete-instance.request.dto.js +3 -0
- package/dist/application/dtos/request/get-config.request.dto.js +3 -0
- package/dist/application/dtos/request/get-credentials.request.dto.js +3 -0
- package/dist/application/dtos/request/index.js +27 -0
- package/dist/application/dtos/request/install-instance.request.dto.js +3 -0
- package/dist/application/dtos/request/list-charts.request.dto.js +3 -0
- package/dist/application/dtos/request/set-config.request.dto.js +16 -0
- package/dist/application/dtos/request/setup-environment.request.dto.js +16 -0
- package/dist/application/dtos/request/show-logs.request.dto.js +19 -0
- package/dist/application/dtos/request/start-instance.request.dto.js +3 -0
- package/dist/application/dtos/request/stop-instance.request.dto.js +3 -0
- package/dist/application/dtos/response/credentials.response.dto.js +3 -0
- package/dist/application/dtos/response/delete-instance.response.dto.js +3 -0
- package/dist/application/dtos/response/index.js +26 -0
- package/dist/application/dtos/response/install-instance.response.dto.js +3 -0
- package/dist/application/dtos/response/instance-list.response.dto.js +3 -0
- package/dist/application/dtos/response/instance-status.response.dto.js +3 -0
- package/dist/application/dtos/response/setup-result.response.dto.js +3 -0
- package/dist/application/dtos/response/show-logs.response.dto.js +3 -0
- package/dist/application/dtos/response/start-instance.response.dto.js +3 -0
- package/dist/application/dtos/response/stop-instance.response.dto.js +3 -0
- package/dist/application/index.js +25 -0
- package/dist/application/interfaces/index.js +24 -0
- package/dist/application/interfaces/use-case.interface.js +3 -0
- package/dist/application/use-cases/config/get-config.use-case.js +66 -0
- package/dist/application/use-cases/config/set-config.use-case.js +49 -0
- package/dist/application/use-cases/credentials/get-credentials.use-case.js +57 -0
- package/dist/application/use-cases/index.js +28 -0
- package/dist/application/use-cases/instance/delete-instance.use-case.js +81 -0
- package/dist/application/use-cases/instance/index.js +23 -0
- package/dist/application/use-cases/instance/install-instance.use-case.js +424 -0
- package/dist/application/use-cases/instance/list-charts.use-case.js +43 -0
- package/dist/application/use-cases/instance/list-instances.use-case.js +62 -0
- package/dist/application/use-cases/instance/start-instance.use-case.js +154 -0
- package/dist/application/use-cases/instance/stop-instance.use-case.js +55 -0
- package/dist/application/use-cases/logs/show-logs.use-case.js +66 -0
- package/dist/application/use-cases/setup/setup-environment.use-case.js +53 -0
- package/dist/cli.js +286 -0
- package/dist/constants/config-defaults.js +23 -0
- package/dist/constants/defaults.js +89 -0
- package/dist/constants/deployment.js +39 -0
- package/dist/constants/environments.js +93 -0
- package/dist/constants/index.js +53 -0
- package/dist/constants/oci-artifacts.js +25 -0
- package/dist/constants/paths.js +92 -0
- package/dist/constants/timeouts.js +60 -0
- package/dist/di/container.js +34 -0
- package/dist/di/index.js +22 -0
- package/dist/di/modules/application.module.js +54 -0
- package/dist/di/modules/infrastructure.module.js +206 -0
- package/dist/di/modules/interceptor.module.js +68 -0
- package/dist/di/modules/presentation.module.js +31 -0
- package/dist/di/tokens.js +149 -0
- package/dist/domain/decorators/sensitive.decorator.js +39 -0
- package/dist/domain/entities/credentials-resolver.entity.js +127 -0
- package/dist/domain/entities/credentials.entity.js +65 -0
- package/dist/domain/entities/delete-instance-validation.entity.js +100 -0
- package/dist/domain/entities/deployment-parameters.entity.js +120 -0
- package/dist/domain/entities/environment-validation.entity.js +125 -0
- package/dist/domain/entities/index.js +29 -0
- package/dist/domain/entities/instance-lifecycle-state.entity.js +100 -0
- package/dist/domain/entities/instance-list-aggregator.entity.js +104 -0
- package/dist/domain/entities/instance-metadata.entity.js +86 -0
- package/dist/domain/entities/instance-status.entity.js +79 -0
- package/dist/domain/entities/instance.entity.js +128 -0
- package/dist/domain/entities/log-filter.entity.js +141 -0
- package/dist/domain/index.js +29 -0
- package/dist/domain/interfaces/safe-loggable.interface.js +3 -0
- package/dist/domain/ports/app-config.port.js +3 -0
- package/dist/domain/ports/base-image.port.js +3 -0
- package/dist/domain/ports/chart-version.port.js +3 -0
- package/dist/domain/ports/correlation-id.port.js +3 -0
- package/dist/domain/ports/credentials.port.js +3 -0
- package/dist/domain/ports/deployment.port.js +3 -0
- package/dist/domain/ports/error-handler.port.js +3 -0
- package/dist/domain/ports/index.js +46 -0
- package/dist/domain/ports/instance-manager.port.js +3 -0
- package/dist/domain/ports/instance-metadata.port.js +8 -0
- package/dist/domain/ports/instance-storage.port.js +3 -0
- package/dist/domain/ports/k8s-deployer.port.js +3 -0
- package/dist/domain/ports/logger.port.js +14 -0
- package/dist/domain/ports/output.port.js +3 -0
- package/dist/domain/ports/runtime-environment.port.js +6 -0
- package/dist/domain/ports/user-interaction.port.js +9 -0
- package/dist/domain/ports/user-settings.port.js +3 -0
- package/dist/domain/types/index.js +22 -0
- package/dist/domain/types/logger.types.js +29 -0
- package/dist/domain/types/validation.types.js +9 -0
- package/dist/domain/value-objects/acr-credentials.value-object.js +92 -0
- package/dist/domain/value-objects/chart-version.value-object.js +124 -0
- package/dist/domain/value-objects/config-log-level.value-object.js +84 -0
- package/dist/domain/value-objects/connection-info.value-object.js +65 -0
- package/dist/domain/value-objects/index.js +25 -0
- package/dist/domain/value-objects/instance-name.value-object.js +91 -0
- package/dist/domain/value-objects/jwt-key.value-object.js +97 -0
- package/dist/domain/value-objects/mssql-password.value-object.js +140 -0
- package/dist/domain/value-objects/rsa-key-pair.value-object.js +181 -0
- package/dist/index.js +6 -0
- package/dist/infrastructure/config/app-config.interface.js +3 -0
- package/dist/infrastructure/config/app-config.service.js +280 -0
- package/dist/infrastructure/config/config-validator.js +31 -0
- package/dist/infrastructure/config/crypto.service.js +125 -0
- package/dist/infrastructure/deployment/deployment.adapter.js +118 -0
- package/dist/infrastructure/deployment/interfaces/acr-credential-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/app-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/helm-registry.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/infra-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/k8s-job-runner.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-database-init.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-helm-deployment.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-storage.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-user-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/oci-artifact.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/secret-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/service-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/version-compatibility.interface.js +3 -0
- package/dist/infrastructure/deployment/services/acr-credential-manager.service.js +144 -0
- package/dist/infrastructure/deployment/services/app-manager.service.js +193 -0
- package/dist/infrastructure/deployment/services/base-helm-deployment.service.js +163 -0
- package/dist/infrastructure/deployment/services/helm-registry.service.js +126 -0
- package/dist/infrastructure/deployment/services/infra-manager.service.js +130 -0
- package/dist/infrastructure/deployment/services/k8s-job-runner.service.js +194 -0
- package/dist/infrastructure/deployment/services/mssql-database-init.service.js +139 -0
- package/dist/infrastructure/deployment/services/mssql-helm-deployment.service.js +100 -0
- package/dist/infrastructure/deployment/services/mssql-storage.service.js +54 -0
- package/dist/infrastructure/deployment/services/mssql-user-manager.service.js +66 -0
- package/dist/infrastructure/deployment/services/oci-artifact.service.js +289 -0
- package/dist/infrastructure/deployment/services/secret-manager.service.js +179 -0
- package/dist/infrastructure/deployment/services/service-manager.service.js +82 -0
- package/dist/infrastructure/deployment/services/version-compatibility.service.js +291 -0
- package/dist/infrastructure/environment/interfaces/hardware-info.interface.js +3 -0
- package/dist/infrastructure/environment/interfaces/network-checker.interface.js +3 -0
- package/dist/infrastructure/environment/services/hardware-info.service.js +135 -0
- package/dist/infrastructure/environment/services/network-checker.service.js +142 -0
- package/dist/infrastructure/environment/windows-environment.adapter.js +162 -0
- package/dist/infrastructure/errors/app-error.js +73 -0
- package/dist/infrastructure/errors/error-handler.interface.js +3 -0
- package/dist/infrastructure/errors/error-handler.js +218 -0
- package/dist/infrastructure/errors/exit-codes.js +27 -0
- package/dist/infrastructure/errors/index.js +25 -0
- package/dist/infrastructure/execution/builders/base-command.builder.js +122 -0
- package/dist/infrastructure/execution/builders/host-command.builder.js +58 -0
- package/dist/infrastructure/execution/builders/windows-host-command.builder.js +50 -0
- package/dist/infrastructure/execution/builders/wsl-command.builder.js +29 -0
- package/dist/infrastructure/execution/command-builder.js +252 -0
- package/dist/infrastructure/execution/command-executor.service.js +230 -0
- package/dist/infrastructure/execution/environments/wsl-execution.environment.js +70 -0
- package/dist/infrastructure/execution/execution-environment.factory.js +53 -0
- package/dist/infrastructure/execution/index.js +25 -0
- package/dist/infrastructure/execution/interfaces/command-builder.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/command-executor.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/execution-environment-factory.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/execution-environment.interface.js +7 -0
- package/dist/infrastructure/execution/interfaces/host-command-builder.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/index.js +23 -0
- package/dist/infrastructure/execution/interfaces/script-executor.interface.js +3 -0
- package/dist/infrastructure/execution/script-executor.service.js +171 -0
- package/dist/infrastructure/http/http-client.service.js +176 -0
- package/dist/infrastructure/http/index.js +18 -0
- package/dist/infrastructure/http/interfaces/http-client.interface.js +3 -0
- package/dist/infrastructure/interceptors/index.js +8 -0
- package/dist/infrastructure/interceptors/interceptor.factory.js +44 -0
- package/dist/infrastructure/interceptors/interceptor.interface.js +3 -0
- package/dist/infrastructure/interceptors/logging.interceptor.js +171 -0
- package/dist/infrastructure/logger/correlation-id.adapter.js +68 -0
- package/dist/infrastructure/logger/index.js +23 -0
- package/dist/infrastructure/logger/interfaces/index.js +22 -0
- package/dist/infrastructure/logger/interfaces/log-reader.repository.interface.js +7 -0
- package/dist/infrastructure/logger/interfaces/log-writer.repository.interface.js +7 -0
- package/dist/infrastructure/logger/logger.adapter.js +274 -0
- package/dist/infrastructure/logger/services/file-log-reader.repository.js +148 -0
- package/dist/infrastructure/logger/services/file-log-writer.repository.js +307 -0
- package/dist/infrastructure/logger/services/index.js +22 -0
- package/dist/infrastructure/persistence/index.js +25 -0
- package/dist/infrastructure/persistence/instance-metadata.adapter.js +100 -0
- package/dist/infrastructure/persistence/instance-storage.adapter.js +64 -0
- package/dist/infrastructure/persistence/interfaces/config.repository.interface.js +3 -0
- package/dist/infrastructure/persistence/interfaces/index.js +22 -0
- package/dist/infrastructure/persistence/interfaces/instance.repository.interface.js +3 -0
- package/dist/infrastructure/persistence/services/file-system-config.repository.js +168 -0
- package/dist/infrastructure/persistence/services/file-system-instance.repository.js +170 -0
- package/dist/infrastructure/persistence/services/index.js +22 -0
- package/dist/infrastructure/persistence/user-settings.adapter.js +55 -0
- package/dist/infrastructure/platform-detector.js +71 -0
- package/dist/infrastructure/platforms/windows/interfaces/microk8s.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/rootfs-manager.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/windows-features.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/windows-info.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-config.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-info.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-inspection.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-lifecycle.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-naming.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-manager.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-resources.interface.js +8 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-updater.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wslconfig-parser.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/parsers/wsl-version.parser.js +133 -0
- package/dist/infrastructure/platforms/windows/services/microk8s.service.js +168 -0
- package/dist/infrastructure/platforms/windows/services/rootfs-manager.service.js +336 -0
- package/dist/infrastructure/platforms/windows/services/windows-features.service.js +191 -0
- package/dist/infrastructure/platforms/windows/services/windows-info.service.js +138 -0
- package/dist/infrastructure/platforms/windows/services/wsl-config.service.js +171 -0
- package/dist/infrastructure/platforms/windows/services/wsl-info.service.js +226 -0
- package/dist/infrastructure/platforms/windows/services/wsl-instance-inspection.service.js +325 -0
- package/dist/infrastructure/platforms/windows/services/wsl-instance-lifecycle.service.js +442 -0
- package/dist/infrastructure/platforms/windows/services/wsl-instance-naming.service.js +93 -0
- package/dist/infrastructure/platforms/windows/services/wsl-updater.service.js +273 -0
- package/dist/infrastructure/platforms/windows/services/wslconfig-parser.service.js +222 -0
- package/dist/infrastructure/platforms/windows/wsl-base-image.adapter.js +41 -0
- package/dist/infrastructure/platforms/windows/wsl-instance-manager.adapter.js +150 -0
- package/dist/infrastructure/utils/error-formatter.util.js +29 -0
- package/dist/infrastructure/utils/file-operations.util.js +201 -0
- package/dist/infrastructure/utils/input-validator.util.js +152 -0
- package/dist/infrastructure/utils/retry.util.js +98 -0
- package/dist/presentation/controllers/config.controller.js +146 -0
- package/dist/presentation/controllers/credentials.controller.js +105 -0
- package/dist/presentation/controllers/index.js +25 -0
- package/dist/presentation/controllers/instance.controller.js +363 -0
- package/dist/presentation/controllers/logs.controller.js +103 -0
- package/dist/presentation/controllers/setup.controller.js +175 -0
- package/dist/presentation/interfaces/cli-options.interface.js +8 -0
- package/dist/presentation/prompts/acr-credentials.prompt.js +76 -0
- package/dist/presentation/prompts/index.js +21 -0
- package/dist/presentation/ui/cli-progress.service.js +193 -0
- package/dist/presentation/ui/constants/output-symbols.js +42 -0
- package/dist/presentation/ui/index.js +27 -0
- package/dist/presentation/ui/interaction.service.js +276 -0
- package/dist/presentation/ui/interfaces/cli-progress.interface.js +9 -0
- package/dist/presentation/ui/interfaces/output-formatter.interface.js +23 -0
- package/dist/presentation/ui/log-level.enum.js +66 -0
- package/dist/presentation/ui/output-builder.service.js +378 -0
- package/dist/presentation/ui/output-formatter.service.js +393 -0
- package/package.json +65 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 錯誤處理服務
|
|
4
|
+
*
|
|
5
|
+
* 提供統一的錯誤處理、格式化和日誌記錄功能
|
|
6
|
+
*/
|
|
7
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
+
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;
|
|
11
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
+
};
|
|
13
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
17
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.ErrorHandler = void 0;
|
|
21
|
+
const tsyringe_1 = require("tsyringe");
|
|
22
|
+
const tokens_1 = require("../../di/tokens");
|
|
23
|
+
const app_error_1 = require("./app-error");
|
|
24
|
+
const exit_codes_1 = require("./exit-codes");
|
|
25
|
+
const error_formatter_util_1 = require("../utils/error-formatter.util");
|
|
26
|
+
/**
|
|
27
|
+
* 錯誤處理器實作
|
|
28
|
+
*/
|
|
29
|
+
let ErrorHandler = class ErrorHandler {
|
|
30
|
+
constructor(logger, process) {
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.process = process;
|
|
33
|
+
this.cleanupHandler = null;
|
|
34
|
+
this.cleanupOutput = null;
|
|
35
|
+
this.isCleaningUp = false;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 處理錯誤並退出程序
|
|
39
|
+
*/
|
|
40
|
+
handleError(error, context) {
|
|
41
|
+
const appError = this.normalizeError(error, context);
|
|
42
|
+
// 如果正在清理中,不顯示錯誤也不退出 - 讓 SIGINT handler 管理退出
|
|
43
|
+
if (this.isCleaningUp) {
|
|
44
|
+
this.logError(appError);
|
|
45
|
+
// 保持 process 存活,等待 SIGINT handler 完成清理後退出
|
|
46
|
+
setInterval(() => { }, 1000);
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const debug = this.isDebugMode();
|
|
50
|
+
// 顯示錯誤
|
|
51
|
+
console.error(this.formatError(appError, debug));
|
|
52
|
+
// 記錄日誌
|
|
53
|
+
this.logError(appError);
|
|
54
|
+
// 退出
|
|
55
|
+
this.process.exit(appError.exitCode);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 處理非致命錯誤(不退出程序)
|
|
59
|
+
*/
|
|
60
|
+
handleWarning(error, context) {
|
|
61
|
+
const appError = this.normalizeError(error, context);
|
|
62
|
+
const debug = this.isDebugMode();
|
|
63
|
+
console.error(this.formatError(appError, debug));
|
|
64
|
+
this.logError(appError);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 設定全域錯誤處理器
|
|
68
|
+
*/
|
|
69
|
+
setupGlobalHandlers() {
|
|
70
|
+
this.process.on('unhandledRejection', (reason) => {
|
|
71
|
+
const output = this.cleanupOutput;
|
|
72
|
+
// 如果正在清理中,不顯示錯誤訊息
|
|
73
|
+
if (!this.isCleaningUp) {
|
|
74
|
+
output?.newline().error('⚠️ Unhandled Promise Rejection detected').newline().flush();
|
|
75
|
+
}
|
|
76
|
+
const error = reason instanceof Error
|
|
77
|
+
? reason
|
|
78
|
+
: new Error(`Unhandled rejection: ${String(reason)}`);
|
|
79
|
+
this.handleError(error, 'unhandledRejection');
|
|
80
|
+
});
|
|
81
|
+
this.process.on('uncaughtException', (error) => {
|
|
82
|
+
const output = this.cleanupOutput;
|
|
83
|
+
// 如果正在清理中,不顯示錯誤訊息
|
|
84
|
+
if (!this.isCleaningUp) {
|
|
85
|
+
output?.newline().error('⚠️ Uncaught Exception detected').newline().flush();
|
|
86
|
+
}
|
|
87
|
+
this.handleError(error, 'uncaughtException');
|
|
88
|
+
});
|
|
89
|
+
this.process.on('SIGINT', () => {
|
|
90
|
+
// 防止重複處理
|
|
91
|
+
if (this.isCleaningUp)
|
|
92
|
+
return;
|
|
93
|
+
this.isCleaningUp = true;
|
|
94
|
+
const output = this.cleanupOutput;
|
|
95
|
+
output?.newline().warning('Received interrupt signal...').flush();
|
|
96
|
+
// 抑制其他異步輸出,確保 cleanup 訊息清晰
|
|
97
|
+
output?.suppress();
|
|
98
|
+
const doCleanup = async () => {
|
|
99
|
+
if (this.cleanupHandler) {
|
|
100
|
+
try {
|
|
101
|
+
// 恢復輸出以顯示 cleanup 訊息
|
|
102
|
+
output?.resume();
|
|
103
|
+
output?.newline().section('Cleaning up...').flush();
|
|
104
|
+
await this.cleanupHandler();
|
|
105
|
+
output?.success('Cleanup completed').flush();
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
output?.warning(`Cleanup failed: ${(0, error_formatter_util_1.formatErrorMessage)(error)}`).flush();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
output?.newline().success('Exiting...').newline().flush();
|
|
112
|
+
this.process.exit(0);
|
|
113
|
+
};
|
|
114
|
+
// 使用 .then() 確保 Promise 被正確處理
|
|
115
|
+
doCleanup().catch(() => {
|
|
116
|
+
this.process.exit(1);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
this.process.on('SIGTERM', () => {
|
|
120
|
+
const output = this.cleanupOutput;
|
|
121
|
+
output?.newline().success('Received termination signal, exiting...').newline().flush();
|
|
122
|
+
this.process.exit(0);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 註冊中斷清理 handler
|
|
127
|
+
*/
|
|
128
|
+
registerCleanupHandler(handler, output) {
|
|
129
|
+
this.cleanupHandler = handler;
|
|
130
|
+
this.cleanupOutput = output ?? null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 清除已註冊的清理 handler
|
|
134
|
+
*/
|
|
135
|
+
clearCleanupHandler() {
|
|
136
|
+
this.cleanupHandler = null;
|
|
137
|
+
this.cleanupOutput = null;
|
|
138
|
+
}
|
|
139
|
+
// =========================================================================
|
|
140
|
+
// 私有方法
|
|
141
|
+
// =========================================================================
|
|
142
|
+
/**
|
|
143
|
+
* 將未知錯誤轉換為 AppError
|
|
144
|
+
*/
|
|
145
|
+
normalizeError(error, context) {
|
|
146
|
+
if (error instanceof app_error_1.AppError) {
|
|
147
|
+
return error;
|
|
148
|
+
}
|
|
149
|
+
if (error instanceof Error) {
|
|
150
|
+
return new app_error_1.AppError(context ? `[${context}] ${error.message}` : error.message, {
|
|
151
|
+
cause: error,
|
|
152
|
+
exitCode: exit_codes_1.EXIT_CODES.UNKNOWN_ERROR,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return new app_error_1.AppError(context ? `[${context}] ${String(error)}` : String(error), {
|
|
156
|
+
exitCode: exit_codes_1.EXIT_CODES.UNKNOWN_ERROR,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 格式化錯誤訊息
|
|
161
|
+
*/
|
|
162
|
+
formatError(error, debug) {
|
|
163
|
+
const lines = [];
|
|
164
|
+
// 錯誤訊息
|
|
165
|
+
// lines.push(`\n✗ Error: ${error.message}\n`);
|
|
166
|
+
// 解決方案
|
|
167
|
+
if (error.solution) {
|
|
168
|
+
lines.push(`\n ! Solution: ${error.solution}\n`);
|
|
169
|
+
}
|
|
170
|
+
// Debug 資訊
|
|
171
|
+
if (debug) {
|
|
172
|
+
if (error.context) {
|
|
173
|
+
lines.push(`📋 Context: ${JSON.stringify(error.context, null, 2)}`);
|
|
174
|
+
}
|
|
175
|
+
if (error.stack) {
|
|
176
|
+
lines.push(`\nStack Trace:\n${error.stack}`);
|
|
177
|
+
}
|
|
178
|
+
if (error.cause) {
|
|
179
|
+
lines.push(`\nCaused by:\n${error.cause.stack || error.cause.message}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// 日誌位置
|
|
183
|
+
// lines.push(`\n📝 Full logs: ${this.logger.getLogFilePath()}\n`);
|
|
184
|
+
// 確保輸出後終端顏色恢復正常
|
|
185
|
+
return lines.join('\n');
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 記錄錯誤到日誌
|
|
189
|
+
*/
|
|
190
|
+
logError(error) {
|
|
191
|
+
this.logger.error(error, {
|
|
192
|
+
exitCode: error.exitCode,
|
|
193
|
+
solution: error.solution,
|
|
194
|
+
context: error.context,
|
|
195
|
+
system: {
|
|
196
|
+
nodeVersion: process.version,
|
|
197
|
+
platform: process.platform,
|
|
198
|
+
arch: process.arch,
|
|
199
|
+
},
|
|
200
|
+
skipConsole: true,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 判斷是否為 debug 模式
|
|
205
|
+
*/
|
|
206
|
+
isDebugMode() {
|
|
207
|
+
return (process.env.LOG_LEVEL === 'debug' ||
|
|
208
|
+
process.env.UOFX_LOG_LEVEL === 'debug');
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
exports.ErrorHandler = ErrorHandler;
|
|
212
|
+
exports.ErrorHandler = ErrorHandler = __decorate([
|
|
213
|
+
(0, tsyringe_1.injectable)(),
|
|
214
|
+
__param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.ILoggerPort)),
|
|
215
|
+
__param(1, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.Process)),
|
|
216
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
217
|
+
], ErrorHandler);
|
|
218
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EXIT_CODES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 標準退出碼定義
|
|
6
|
+
*
|
|
7
|
+
* 用於定義不同類型錯誤對應的程式退出碼
|
|
8
|
+
*/
|
|
9
|
+
exports.EXIT_CODES = {
|
|
10
|
+
/** 成功執行 */
|
|
11
|
+
SUCCESS: 0,
|
|
12
|
+
/** 一般錯誤 */
|
|
13
|
+
GENERAL_ERROR: 1,
|
|
14
|
+
/** 驗證錯誤(使用者輸入不符合規範) */
|
|
15
|
+
VALIDATION_ERROR: 2,
|
|
16
|
+
/** 環境錯誤 */
|
|
17
|
+
ENVIRONMENT_ERROR: 3,
|
|
18
|
+
/** 網路錯誤 */
|
|
19
|
+
NETWORK_ERROR: 4,
|
|
20
|
+
/** 業務邏輯錯誤 */
|
|
21
|
+
BUSINESS_ERROR: 5,
|
|
22
|
+
/** 系統錯誤(WSL、K8s 等系統層級問題) */
|
|
23
|
+
SYSTEM_ERROR: 6,
|
|
24
|
+
/** 未知錯誤 */
|
|
25
|
+
UNKNOWN_ERROR: 99,
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=exit-codes.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 統一錯誤系統匯出
|
|
4
|
+
*
|
|
5
|
+
* 這是整個應用程式錯誤處理的單一匯出點
|
|
6
|
+
* 使用方式:
|
|
7
|
+
*
|
|
8
|
+
* import {
|
|
9
|
+
* ErrorHandler,
|
|
10
|
+
* AppError,
|
|
11
|
+
* EXIT_CODES
|
|
12
|
+
* } from '@/infrastructure/errors';
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.EXIT_CODES = exports.ErrorHandler = exports.AppError = void 0;
|
|
16
|
+
// 錯誤類別
|
|
17
|
+
var app_error_1 = require("./app-error");
|
|
18
|
+
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return app_error_1.AppError; } });
|
|
19
|
+
// 錯誤處理器
|
|
20
|
+
var error_handler_1 = require("./error-handler");
|
|
21
|
+
Object.defineProperty(exports, "ErrorHandler", { enumerable: true, get: function () { return error_handler_1.ErrorHandler; } });
|
|
22
|
+
// 退出碼
|
|
23
|
+
var exit_codes_1 = require("./exit-codes");
|
|
24
|
+
Object.defineProperty(exports, "EXIT_CODES", { enumerable: true, get: function () { return exit_codes_1.EXIT_CODES; } });
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseCommandBuilder = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 基礎命令建構器
|
|
6
|
+
*
|
|
7
|
+
* 提供共用的 Fluent API 實作,子類別只需實作 buildActual() 方法
|
|
8
|
+
*/
|
|
9
|
+
class BaseCommandBuilder {
|
|
10
|
+
constructor(commandExecutor) {
|
|
11
|
+
this.commandExecutor = commandExecutor;
|
|
12
|
+
this.executable = '';
|
|
13
|
+
this.commandArgs = [];
|
|
14
|
+
this.isSensitiveInput = false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 設定可執行檔名稱
|
|
18
|
+
*/
|
|
19
|
+
setExecutable(executable) {
|
|
20
|
+
this.executable = executable;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
arg(flag, value) {
|
|
24
|
+
if (value !== undefined) {
|
|
25
|
+
this.commandArgs.push({ type: 'safe', flag, value });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.commandArgs.push({ type: 'safe', value: flag });
|
|
29
|
+
}
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
sensitiveArg(flag, value) {
|
|
33
|
+
this.commandArgs.push({ type: 'sensitive', flag, value });
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
argIf(condition, flag, value) {
|
|
37
|
+
if (condition) {
|
|
38
|
+
this.arg(flag, value);
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
args(...values) {
|
|
43
|
+
values.forEach(v => this.arg(v));
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
stdin(input) {
|
|
47
|
+
this.stdinInput = input;
|
|
48
|
+
this.isSensitiveInput = false;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
sensitiveStdin(input) {
|
|
52
|
+
this.stdinInput = input;
|
|
53
|
+
this.isSensitiveInput = true;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 建構用於記錄的安全命令字串
|
|
58
|
+
*/
|
|
59
|
+
buildSafe() {
|
|
60
|
+
let cmd = this.buildCommandString(true);
|
|
61
|
+
// 子類別可能會覆寫此方法來加入額外的包裝
|
|
62
|
+
cmd = this.wrapCommand(cmd, true);
|
|
63
|
+
if (this.isSensitiveInput) {
|
|
64
|
+
cmd += ' < [STDIN: ***REDACTED***]';
|
|
65
|
+
}
|
|
66
|
+
return cmd;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 包裝命令(子類別可覆寫)
|
|
70
|
+
*/
|
|
71
|
+
wrapCommand(command, _maskSensitive) {
|
|
72
|
+
return command;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 建構命令字串
|
|
76
|
+
*/
|
|
77
|
+
buildCommandString(maskSensitive) {
|
|
78
|
+
const parts = [this.executable];
|
|
79
|
+
for (const arg of this.commandArgs) {
|
|
80
|
+
if (arg.type === 'sensitive' && maskSensitive) {
|
|
81
|
+
if (arg.flag) {
|
|
82
|
+
parts.push(`${arg.flag} ***REDACTED***`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
parts.push('***REDACTED***');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (arg.flag && arg.value !== undefined) {
|
|
90
|
+
parts.push(`${arg.flag} ${arg.value}`);
|
|
91
|
+
}
|
|
92
|
+
else if (arg.value !== undefined) {
|
|
93
|
+
parts.push(arg.value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return parts.join(' ');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 取得執行選項
|
|
101
|
+
*/
|
|
102
|
+
getExecutionOptions() {
|
|
103
|
+
return {
|
|
104
|
+
command: this.buildActual(),
|
|
105
|
+
options: {
|
|
106
|
+
shell: true,
|
|
107
|
+
...(this.stdinInput && { input: this.stdinInput }),
|
|
108
|
+
},
|
|
109
|
+
safeCommand: this.buildSafe(),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
execSync(showOutput = false, suppressStderr = false) {
|
|
113
|
+
const { command, options, safeCommand } = this.getExecutionOptions();
|
|
114
|
+
return this.commandExecutor.execSync(command, options, showOutput, suppressStderr, safeCommand);
|
|
115
|
+
}
|
|
116
|
+
async exec(onStdout, onStderr) {
|
|
117
|
+
const { command, options, safeCommand } = this.getExecutionOptions();
|
|
118
|
+
return this.commandExecutor.exec(command, onStdout, onStderr, options, safeCommand);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.BaseCommandBuilder = BaseCommandBuilder;
|
|
122
|
+
//# sourceMappingURL=base-command.builder.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HostCommandBuilder = exports.HostCommand = void 0;
|
|
16
|
+
const tsyringe_1 = require("tsyringe");
|
|
17
|
+
const tokens_1 = require("../../../di/tokens");
|
|
18
|
+
const base_command_builder_1 = require("./base-command.builder");
|
|
19
|
+
/**
|
|
20
|
+
* 主機命令實作
|
|
21
|
+
*
|
|
22
|
+
* 在主機上直接執行命令(不透過 WSL/SSH)
|
|
23
|
+
*/
|
|
24
|
+
class HostCommand extends base_command_builder_1.BaseCommandBuilder {
|
|
25
|
+
buildActual() {
|
|
26
|
+
return this.buildCommandString(false);
|
|
27
|
+
}
|
|
28
|
+
buildSafe() {
|
|
29
|
+
let cmd = this.buildCommandString(true);
|
|
30
|
+
if (this.isSensitiveInput) {
|
|
31
|
+
cmd += ' < [STDIN: ***REDACTED***]';
|
|
32
|
+
}
|
|
33
|
+
return cmd;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.HostCommand = HostCommand;
|
|
37
|
+
/**
|
|
38
|
+
* 主機命令建構器
|
|
39
|
+
*
|
|
40
|
+
* 提供建立主機命令的基礎實作(跨平台)
|
|
41
|
+
*/
|
|
42
|
+
let HostCommandBuilder = class HostCommandBuilder {
|
|
43
|
+
constructor(commandExecutor) {
|
|
44
|
+
this.commandExecutor = commandExecutor;
|
|
45
|
+
}
|
|
46
|
+
create(executable) {
|
|
47
|
+
const builder = new HostCommand(this.commandExecutor);
|
|
48
|
+
builder.setExecutable(executable);
|
|
49
|
+
return builder;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.HostCommandBuilder = HostCommandBuilder;
|
|
53
|
+
exports.HostCommandBuilder = HostCommandBuilder = __decorate([
|
|
54
|
+
(0, tsyringe_1.injectable)(),
|
|
55
|
+
__param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.ICommandExecutor)),
|
|
56
|
+
__metadata("design:paramtypes", [Object])
|
|
57
|
+
], HostCommandBuilder);
|
|
58
|
+
//# sourceMappingURL=host-command.builder.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WindowsHostCommandBuilder = void 0;
|
|
16
|
+
const tsyringe_1 = require("tsyringe");
|
|
17
|
+
const tokens_1 = require("../../../di/tokens");
|
|
18
|
+
const host_command_builder_1 = require("./host-command.builder");
|
|
19
|
+
/**
|
|
20
|
+
* Windows 主機命令建構器
|
|
21
|
+
*
|
|
22
|
+
* 繼承 HostCommandBuilder,添加 Windows 平台特定的命令建構方法
|
|
23
|
+
*/
|
|
24
|
+
let WindowsHostCommandBuilder = class WindowsHostCommandBuilder extends host_command_builder_1.HostCommandBuilder {
|
|
25
|
+
constructor(commandExecutor) {
|
|
26
|
+
super(commandExecutor);
|
|
27
|
+
}
|
|
28
|
+
powershell(command) {
|
|
29
|
+
const builder = new host_command_builder_1.HostCommand(this.commandExecutor);
|
|
30
|
+
builder.setExecutable('powershell');
|
|
31
|
+
builder.arg('-NoProfile');
|
|
32
|
+
builder.arg('-NoLogo');
|
|
33
|
+
builder.arg('-Command');
|
|
34
|
+
builder.arg(command);
|
|
35
|
+
return builder;
|
|
36
|
+
}
|
|
37
|
+
wslCmd(subcommand) {
|
|
38
|
+
const builder = new host_command_builder_1.HostCommand(this.commandExecutor);
|
|
39
|
+
builder.setExecutable('wsl');
|
|
40
|
+
builder.arg(subcommand);
|
|
41
|
+
return builder;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.WindowsHostCommandBuilder = WindowsHostCommandBuilder;
|
|
45
|
+
exports.WindowsHostCommandBuilder = WindowsHostCommandBuilder = __decorate([
|
|
46
|
+
(0, tsyringe_1.injectable)(),
|
|
47
|
+
__param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.ICommandExecutor)),
|
|
48
|
+
__metadata("design:paramtypes", [Object])
|
|
49
|
+
], WindowsHostCommandBuilder);
|
|
50
|
+
//# sourceMappingURL=windows-host-command.builder.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WslCommandBuilder = void 0;
|
|
4
|
+
const base_command_builder_1 = require("./base-command.builder");
|
|
5
|
+
/**
|
|
6
|
+
* WSL 命令建構器
|
|
7
|
+
*
|
|
8
|
+
* 自動將命令包裝為 `wsl -d <instanceName> -- <command>` 格式
|
|
9
|
+
*/
|
|
10
|
+
class WslCommandBuilder extends base_command_builder_1.BaseCommandBuilder {
|
|
11
|
+
constructor(instanceName, commandExecutor) {
|
|
12
|
+
super(commandExecutor);
|
|
13
|
+
this.instanceName = instanceName;
|
|
14
|
+
}
|
|
15
|
+
buildActual() {
|
|
16
|
+
const innerCmd = this.buildCommandString(false);
|
|
17
|
+
return `wsl -d ${this.instanceName} -- ${innerCmd}`;
|
|
18
|
+
}
|
|
19
|
+
buildSafe() {
|
|
20
|
+
const innerCmd = this.buildCommandString(true);
|
|
21
|
+
let cmd = `wsl -d ${this.instanceName} -- ${innerCmd}`;
|
|
22
|
+
if (this.isSensitiveInput) {
|
|
23
|
+
cmd += ' < [STDIN: ***REDACTED***]';
|
|
24
|
+
}
|
|
25
|
+
return cmd;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.WslCommandBuilder = WslCommandBuilder;
|
|
29
|
+
//# sourceMappingURL=wsl-command.builder.js.map
|