@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,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandBuilder = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 命令建構器 - 支援安全的命令建構與執行
|
|
6
|
+
*
|
|
7
|
+
* 特性:
|
|
8
|
+
* - 自動區分安全參數與敏感參數
|
|
9
|
+
* - 生成兩個版本: 實際執行命令 & 安全記錄命令
|
|
10
|
+
* - Fluent API 設計
|
|
11
|
+
*
|
|
12
|
+
* 注意:此類別用於非 DI 場景(如環境檢查服務)。
|
|
13
|
+
* 對於 WSL 實例內的命令執行,請使用 IExecutionEnvironmentFactory。
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // 基本使用
|
|
17
|
+
* const result = await CommandBuilder
|
|
18
|
+
* .create('wsl')
|
|
19
|
+
* .arg('--list')
|
|
20
|
+
* .arg('--verbose')
|
|
21
|
+
* .exec(commandExecutor);
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // PowerShell 命令
|
|
25
|
+
* const result = await CommandBuilder
|
|
26
|
+
* .create('powershell')
|
|
27
|
+
* .arg('-NoProfile')
|
|
28
|
+
* .arg('-Command')
|
|
29
|
+
* .arg('Get-Process')
|
|
30
|
+
* .exec(commandExecutor);
|
|
31
|
+
*/
|
|
32
|
+
class CommandBuilder {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.executable = '';
|
|
35
|
+
this.commandArgs = [];
|
|
36
|
+
this.isSensitiveInput = false;
|
|
37
|
+
this._inheritStdio = false;
|
|
38
|
+
}
|
|
39
|
+
// ========== 工廠方法 (Factory Methods) ==========
|
|
40
|
+
/**
|
|
41
|
+
* 建立一般命令
|
|
42
|
+
* @param executable 可執行檔名稱或路徑
|
|
43
|
+
* @returns CommandBuilder 實例
|
|
44
|
+
* @example CommandBuilder.create('wsl').arg('--list').arg('--verbose')
|
|
45
|
+
*/
|
|
46
|
+
static create(executable) {
|
|
47
|
+
const builder = new CommandBuilder();
|
|
48
|
+
builder.executable = executable;
|
|
49
|
+
return builder;
|
|
50
|
+
}
|
|
51
|
+
// ========== 命令輔助方法 (Command Helper Methods) ==========
|
|
52
|
+
/**
|
|
53
|
+
* PowerShell 命令 (Windows 專用)
|
|
54
|
+
* @param command PowerShell 命令字串
|
|
55
|
+
* @returns this (支援方法鏈)
|
|
56
|
+
* @example CommandBuilder.create('powershell').powershell('Get-Process')
|
|
57
|
+
*/
|
|
58
|
+
powershell(command) {
|
|
59
|
+
this.executable = 'powershell';
|
|
60
|
+
this.arg('-NoProfile');
|
|
61
|
+
this.arg('-NoLogo');
|
|
62
|
+
this.arg('-Command');
|
|
63
|
+
this.arg(command);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* WSL 管理命令 (不包裝實例)
|
|
68
|
+
* @param subcommand WSL 子命令
|
|
69
|
+
* @returns this (支援方法鏈)
|
|
70
|
+
* @example CommandBuilder.create('wsl.exe').wslCmd('--list').arg('--verbose')
|
|
71
|
+
*/
|
|
72
|
+
wslCmd(subcommand) {
|
|
73
|
+
// 使用 wsl.exe 而非 wsl,因為當 WSL 未安裝時 wsl 只是 stub
|
|
74
|
+
this.executable = 'wsl.exe';
|
|
75
|
+
this.arg(subcommand);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
// ========== 參數方法 (Argument Methods) ==========
|
|
79
|
+
/**
|
|
80
|
+
* 新增一般參數 (安全,會被記錄)
|
|
81
|
+
* @param flag 參數名稱或值
|
|
82
|
+
* @param value 參數值 (可選)
|
|
83
|
+
* @returns this (支援方法鏈)
|
|
84
|
+
* @example .arg('--wait')
|
|
85
|
+
* @example .arg('--namespace', 'mssql')
|
|
86
|
+
*/
|
|
87
|
+
arg(flag, value) {
|
|
88
|
+
if (value !== undefined) {
|
|
89
|
+
this.commandArgs.push({ type: 'safe', flag, value });
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.commandArgs.push({ type: 'safe', value: flag });
|
|
93
|
+
}
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 新增敏感參數 (會被遮罩)
|
|
98
|
+
* @param flag 參數名稱
|
|
99
|
+
* @param value 參數值 (含敏感資料)
|
|
100
|
+
* @returns this (支援方法鏈)
|
|
101
|
+
* @example .sensitiveArg('--set', `sa_password='${password}'`)
|
|
102
|
+
* @example .sensitiveArg('-P', password)
|
|
103
|
+
*/
|
|
104
|
+
sensitiveArg(flag, value) {
|
|
105
|
+
this.commandArgs.push({ type: 'sensitive', flag, value });
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 新增條件參數
|
|
110
|
+
* @param condition 條件判斷
|
|
111
|
+
* @param flag 參數名稱
|
|
112
|
+
* @param value 參數值 (可選)
|
|
113
|
+
* @returns this (支援方法鏈)
|
|
114
|
+
* @example .argIf(enableDebug, '--debug')
|
|
115
|
+
*/
|
|
116
|
+
argIf(condition, flag, value) {
|
|
117
|
+
if (condition) {
|
|
118
|
+
this.arg(flag, value);
|
|
119
|
+
}
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 新增多個參數
|
|
124
|
+
* @param values 參數值陣列
|
|
125
|
+
* @returns this (支援方法鏈)
|
|
126
|
+
* @example .args('--wait', '--timeout', '300s')
|
|
127
|
+
*/
|
|
128
|
+
args(...values) {
|
|
129
|
+
values.forEach(v => this.arg(v));
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
// ========== 標準輸入方法 (Stdin Methods) ==========
|
|
133
|
+
/**
|
|
134
|
+
* 透過 stdin 傳入一般資料
|
|
135
|
+
* @param input stdin 輸入內容
|
|
136
|
+
* @returns this (支援方法鏈)
|
|
137
|
+
* @example .stdin(jsonContent)
|
|
138
|
+
*/
|
|
139
|
+
stdin(input) {
|
|
140
|
+
this.stdinInput = input;
|
|
141
|
+
this.isSensitiveInput = false;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 透過 stdin 傳入敏感資料 (如密碼、keys)
|
|
146
|
+
* @param input stdin 輸入內容 (含敏感資料)
|
|
147
|
+
* @returns this (支援方法鏈)
|
|
148
|
+
* @example .sensitiveStdin(password)
|
|
149
|
+
*/
|
|
150
|
+
sensitiveStdin(input) {
|
|
151
|
+
this.stdinInput = input;
|
|
152
|
+
this.isSensitiveInput = true;
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 設定直接繼承終端的 stdio
|
|
157
|
+
* 用於需要終端訪問的命令(如 WSL 安裝)
|
|
158
|
+
* @returns this (支援方法鏈)
|
|
159
|
+
*/
|
|
160
|
+
inheritStdio() {
|
|
161
|
+
this._inheritStdio = true;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
// ========== 建構方法 (Build Methods) ==========
|
|
165
|
+
/**
|
|
166
|
+
* 建構實際執行的命令字串
|
|
167
|
+
* @returns 完整命令字串 (含敏感資料)
|
|
168
|
+
*/
|
|
169
|
+
buildActual() {
|
|
170
|
+
return this.buildCommand(false);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 建構用於記錄的安全命令字串 (敏感參數已遮罩)
|
|
174
|
+
* @returns 安全命令字串 (敏感資料已遮罩為 ***REDACTED***)
|
|
175
|
+
*/
|
|
176
|
+
buildSafe() {
|
|
177
|
+
let cmd = this.buildCommand(true);
|
|
178
|
+
if (this.isSensitiveInput) {
|
|
179
|
+
cmd += ' < [STDIN: ***REDACTED***]';
|
|
180
|
+
}
|
|
181
|
+
return cmd;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 內部方法:建構命令字串
|
|
185
|
+
* @param maskSensitive 是否遮罩敏感參數
|
|
186
|
+
* @returns 命令字串
|
|
187
|
+
*/
|
|
188
|
+
buildCommand(maskSensitive) {
|
|
189
|
+
const parts = [this.executable];
|
|
190
|
+
for (const arg of this.commandArgs) {
|
|
191
|
+
if (arg.type === 'sensitive' && maskSensitive) {
|
|
192
|
+
// 遮罩敏感參數
|
|
193
|
+
if (arg.flag) {
|
|
194
|
+
parts.push(`${arg.flag} ***REDACTED***`);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
parts.push('***REDACTED***');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// 正常輸出
|
|
202
|
+
if (arg.flag && arg.value !== undefined) {
|
|
203
|
+
parts.push(`${arg.flag} ${arg.value}`);
|
|
204
|
+
}
|
|
205
|
+
else if (arg.value !== undefined) {
|
|
206
|
+
parts.push(arg.value);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return parts.join(' ');
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* 取得 CommandExecutor 的執行選項
|
|
214
|
+
* @returns 包含 command, options, safeCommand 的物件
|
|
215
|
+
*/
|
|
216
|
+
getExecutionOptions() {
|
|
217
|
+
return {
|
|
218
|
+
command: this.buildActual(),
|
|
219
|
+
options: {
|
|
220
|
+
shell: true,
|
|
221
|
+
...(this.stdinInput && { input: this.stdinInput }),
|
|
222
|
+
...(this._inheritStdio && { inheritStdio: true }),
|
|
223
|
+
},
|
|
224
|
+
safeCommand: this.buildSafe(),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// ========== 執行方法 (Execute Methods) ==========
|
|
228
|
+
/**
|
|
229
|
+
* 執行命令 (同步)
|
|
230
|
+
* @param executor CommandExecutor 實例
|
|
231
|
+
* @param showOutput 是否顯示輸出
|
|
232
|
+
* @param suppressStderr 是否隱藏 stderr
|
|
233
|
+
* @returns 命令執行結果
|
|
234
|
+
*/
|
|
235
|
+
execSync(executor, showOutput = false, suppressStderr = false) {
|
|
236
|
+
const { command, options, safeCommand } = this.getExecutionOptions();
|
|
237
|
+
return executor.execSync(command, options, showOutput, suppressStderr, safeCommand);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* 執行命令 (異步)
|
|
241
|
+
* @param executor CommandExecutor 實例
|
|
242
|
+
* @param onStdout stdout 回調函式
|
|
243
|
+
* @param onStderr stderr 回調函式
|
|
244
|
+
* @returns Promise<命令執行結果>
|
|
245
|
+
*/
|
|
246
|
+
async exec(executor, onStdout, onStderr) {
|
|
247
|
+
const { command, options, safeCommand } = this.getExecutionOptions();
|
|
248
|
+
return executor.exec(command, onStdout, onStderr, options, safeCommand);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.CommandBuilder = CommandBuilder;
|
|
252
|
+
//# sourceMappingURL=command-builder.js.map
|
|
@@ -0,0 +1,230 @@
|
|
|
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.CommandExecutorService = void 0;
|
|
16
|
+
const tsyringe_1 = require("tsyringe");
|
|
17
|
+
const child_process_1 = require("child_process");
|
|
18
|
+
const defaults_1 = require("../../constants/defaults");
|
|
19
|
+
const sensitive_decorator_1 = require("../../domain/decorators/sensitive.decorator");
|
|
20
|
+
/**
|
|
21
|
+
* 命令執行器服務
|
|
22
|
+
*
|
|
23
|
+
* 使用 Node.js child_process 模組實作 ICommandExecutor 介面,
|
|
24
|
+
* 提供真實的命令執行功能。支援同步和非同步執行、串流輸出、timeout 機制。
|
|
25
|
+
*/
|
|
26
|
+
let CommandExecutorService = class CommandExecutorService {
|
|
27
|
+
/**
|
|
28
|
+
* 同步執行命令
|
|
29
|
+
* @param command - 要執行的命令字串
|
|
30
|
+
* @param options - 執行選項(如 cwd, env, timeout)
|
|
31
|
+
* @param showOutput - 是否在 stdout 顯示輸出(預設:true)
|
|
32
|
+
* @param suppressStderr - 是否隱藏 stderr 輸出(預設:false)
|
|
33
|
+
* @param _safeCommandForLogging - 用於日誌記錄的安全命令字串(隱藏敏感資料)
|
|
34
|
+
* @returns 命令執行結果,包含 stdout, stderr 和 exitCode
|
|
35
|
+
* @throws 當命令執行嚴重失敗且無法捕捉時拋出 Error
|
|
36
|
+
*/
|
|
37
|
+
execSync(command, options, _showOutput = true, suppressStderr = false, _safeCommandForLogging) {
|
|
38
|
+
// 處理 shell 選項
|
|
39
|
+
let shell;
|
|
40
|
+
if (options?.shell === true) {
|
|
41
|
+
shell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
|
|
42
|
+
}
|
|
43
|
+
else if (typeof options?.shell === 'string') {
|
|
44
|
+
shell = options.shell;
|
|
45
|
+
}
|
|
46
|
+
const execOptions = {
|
|
47
|
+
// encoding: 'buffer' 会導致 ERR_UNKNOWN_ENCODING,設為 undefined 則會返回 Buffer
|
|
48
|
+
encoding: undefined,
|
|
49
|
+
cwd: options?.cwd,
|
|
50
|
+
env: options?.env,
|
|
51
|
+
timeout: options?.timeout,
|
|
52
|
+
shell,
|
|
53
|
+
maxBuffer: defaults_1.FILE_SIZE.MAX_COMMAND_BUFFER,
|
|
54
|
+
input: options?.input,
|
|
55
|
+
// 總是 pipe stderr 以便正確解碼 UTF-16LE
|
|
56
|
+
stdio: suppressStderr ? ['pipe', 'pipe', 'ignore'] : ['pipe', 'pipe', 'pipe'],
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
const stdoutBuffer = (0, child_process_1.execSync)(command, execOptions);
|
|
60
|
+
const stdout = this.decodeBuffer(stdoutBuffer);
|
|
61
|
+
return {
|
|
62
|
+
stdout,
|
|
63
|
+
stderr: '',
|
|
64
|
+
exitCode: 0,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error && typeof error === 'object' && 'status' in error) {
|
|
69
|
+
const execError = error;
|
|
70
|
+
const stdout = this.decodeBuffer(execError.stdout);
|
|
71
|
+
const stderr = this.decodeBuffer(execError.stderr);
|
|
72
|
+
return {
|
|
73
|
+
stdout,
|
|
74
|
+
stderr: stderr,
|
|
75
|
+
exitCode: execError.status ?? 1,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`Command execution failed: ${String(error)}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 非同步執行命令
|
|
83
|
+
* @param command - 要執行的命令字串
|
|
84
|
+
* @param onStdout - 標準輸出回調函式
|
|
85
|
+
* @param onStderr - 標準錯誤回調函式
|
|
86
|
+
* @param options - 執行選項(如 cwd, env, timeout)
|
|
87
|
+
* @param _safeCommandForLogging - 用於日誌記錄的安全命令字串(隱藏敏感資料)
|
|
88
|
+
* @returns 解析為命令執行結果的 Promise
|
|
89
|
+
*/
|
|
90
|
+
async exec(command, onStdout, onStderr, options, _safeCommandForLogging) {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const encoding = options?.encoding ?? 'utf8';
|
|
93
|
+
// 預設 shell 為 true 以支援命令字串
|
|
94
|
+
let shell = true;
|
|
95
|
+
if (options?.shell === false) {
|
|
96
|
+
shell = false;
|
|
97
|
+
}
|
|
98
|
+
else if (typeof options?.shell === 'string') {
|
|
99
|
+
shell = options.shell;
|
|
100
|
+
}
|
|
101
|
+
// 如果需要繼承 stdio(用於 WSL 安裝等需要終端訪問的命令)
|
|
102
|
+
if (options?.inheritStdio) {
|
|
103
|
+
const spawnOptions = {
|
|
104
|
+
cwd: options?.cwd,
|
|
105
|
+
env: options?.env,
|
|
106
|
+
shell,
|
|
107
|
+
stdio: 'inherit',
|
|
108
|
+
};
|
|
109
|
+
const childProcess = (0, child_process_1.spawn)(command, [], spawnOptions);
|
|
110
|
+
childProcess.on('close', (code) => {
|
|
111
|
+
resolve({
|
|
112
|
+
stdout: '',
|
|
113
|
+
stderr: '',
|
|
114
|
+
exitCode: code ?? 0,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
childProcess.on('error', (error) => {
|
|
118
|
+
reject(new Error(`Failed to execute command: ${error.message}`));
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const spawnOptions = {
|
|
123
|
+
cwd: options?.cwd,
|
|
124
|
+
env: options?.env,
|
|
125
|
+
shell,
|
|
126
|
+
encoding,
|
|
127
|
+
};
|
|
128
|
+
const childProcess = (0, child_process_1.spawn)(command, [], spawnOptions);
|
|
129
|
+
if (options?.input && childProcess.stdin) {
|
|
130
|
+
childProcess.stdin.write(options.input);
|
|
131
|
+
childProcess.stdin.end();
|
|
132
|
+
}
|
|
133
|
+
// 累積輸出 Buffer
|
|
134
|
+
const stdoutChunks = [];
|
|
135
|
+
const stderrChunks = [];
|
|
136
|
+
// 監聽標準輸出
|
|
137
|
+
if (childProcess.stdout) {
|
|
138
|
+
childProcess.stdout.on('data', (data) => {
|
|
139
|
+
stdoutChunks.push(data);
|
|
140
|
+
if (onStdout) {
|
|
141
|
+
onStdout(this.decodeBuffer(data));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// 監聽標準錯誤輸出
|
|
146
|
+
if (childProcess.stderr) {
|
|
147
|
+
childProcess.stderr.on('data', (data) => {
|
|
148
|
+
stderrChunks.push(data);
|
|
149
|
+
if (onStderr) {
|
|
150
|
+
onStderr(this.decodeBuffer(data));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// 設定 timeout (如果有指定)
|
|
155
|
+
let timeoutId;
|
|
156
|
+
if (options?.timeout) {
|
|
157
|
+
timeoutId = setTimeout(() => {
|
|
158
|
+
childProcess.kill('SIGTERM');
|
|
159
|
+
reject(new Error(`Command timed out after ${options.timeout}ms`));
|
|
160
|
+
}, options.timeout);
|
|
161
|
+
}
|
|
162
|
+
// 監聽進程結束
|
|
163
|
+
childProcess.on('close', (code) => {
|
|
164
|
+
if (timeoutId) {
|
|
165
|
+
clearTimeout(timeoutId);
|
|
166
|
+
}
|
|
167
|
+
const stdoutBuffer = Buffer.concat(stdoutChunks);
|
|
168
|
+
const stderrBuffer = Buffer.concat(stderrChunks);
|
|
169
|
+
resolve({
|
|
170
|
+
stdout: this.decodeBuffer(stdoutBuffer),
|
|
171
|
+
stderr: this.decodeBuffer(stderrBuffer),
|
|
172
|
+
exitCode: code ?? 0,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
childProcess.on('error', (error) => {
|
|
176
|
+
if (timeoutId) {
|
|
177
|
+
clearTimeout(timeoutId);
|
|
178
|
+
}
|
|
179
|
+
reject(new Error(`Failed to execute command: ${error.message}`));
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 解碼 Buffer
|
|
185
|
+
* 嘗試偵測 UTF-16 LE (常見於 Windows/WSL 輸出),否則使用 UTF-8
|
|
186
|
+
*/
|
|
187
|
+
decodeBuffer(buffer) {
|
|
188
|
+
if (!buffer)
|
|
189
|
+
return '';
|
|
190
|
+
if (typeof buffer === 'string')
|
|
191
|
+
return buffer;
|
|
192
|
+
if (buffer.length === 0)
|
|
193
|
+
return '';
|
|
194
|
+
// 1. 檢查 UTF-16LE BOM (FF FE)
|
|
195
|
+
if (buffer.length >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
|
|
196
|
+
return buffer.toString('utf16le');
|
|
197
|
+
}
|
|
198
|
+
// 2. 檢查是否為 UTF-16LE (無 BOM)
|
|
199
|
+
// WSL 輸出通常沒有 BOM,但使用 UTF-16LE 編碼
|
|
200
|
+
const sample = buffer.subarray(0, Math.min(buffer.length, 200));
|
|
201
|
+
let nullCount = 0;
|
|
202
|
+
for (let i = 0; i < sample.length; i++) {
|
|
203
|
+
if (sample[i] === 0)
|
|
204
|
+
nullCount++;
|
|
205
|
+
}
|
|
206
|
+
// 如果 null bytes 超過 20%,很可能是 UTF-16LE
|
|
207
|
+
if (nullCount > sample.length * 0.2) {
|
|
208
|
+
return buffer.toString('utf16le');
|
|
209
|
+
}
|
|
210
|
+
// 3. 預設使用 UTF-8
|
|
211
|
+
return buffer.toString('utf8');
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
exports.CommandExecutorService = CommandExecutorService;
|
|
215
|
+
__decorate([
|
|
216
|
+
__param(1, (0, sensitive_decorator_1.Sensitive)()),
|
|
217
|
+
__metadata("design:type", Function),
|
|
218
|
+
__metadata("design:paramtypes", [String, Object, Boolean, Boolean, String]),
|
|
219
|
+
__metadata("design:returntype", Object)
|
|
220
|
+
], CommandExecutorService.prototype, "execSync", null);
|
|
221
|
+
__decorate([
|
|
222
|
+
__param(3, (0, sensitive_decorator_1.Sensitive)()),
|
|
223
|
+
__metadata("design:type", Function),
|
|
224
|
+
__metadata("design:paramtypes", [String, Function, Function, Object, String]),
|
|
225
|
+
__metadata("design:returntype", Promise)
|
|
226
|
+
], CommandExecutorService.prototype, "exec", null);
|
|
227
|
+
exports.CommandExecutorService = CommandExecutorService = __decorate([
|
|
228
|
+
(0, tsyringe_1.injectable)()
|
|
229
|
+
], CommandExecutorService);
|
|
230
|
+
//# sourceMappingURL=command-executor.service.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WslExecutionEnvironment = void 0;
|
|
4
|
+
const execution_environment_interface_1 = require("../interfaces/execution-environment.interface");
|
|
5
|
+
const wsl_command_builder_1 = require("../builders/wsl-command.builder");
|
|
6
|
+
const paths_1 = require("../../../constants/paths");
|
|
7
|
+
/**
|
|
8
|
+
* WSL 執行環境
|
|
9
|
+
*
|
|
10
|
+
* 提供在 WSL 實例內執行命令的能力
|
|
11
|
+
*/
|
|
12
|
+
class WslExecutionEnvironment {
|
|
13
|
+
constructor(identifier, commandExecutor) {
|
|
14
|
+
this.identifier = identifier;
|
|
15
|
+
this.commandExecutor = commandExecutor;
|
|
16
|
+
this.type = execution_environment_interface_1.EXECUTION_ENVIRONMENT_TYPES.WSL;
|
|
17
|
+
}
|
|
18
|
+
helm(subcommand) {
|
|
19
|
+
const builder = new wsl_command_builder_1.WslCommandBuilder(this.identifier, this.commandExecutor);
|
|
20
|
+
builder.setExecutable(paths_1.LINUX_PATHS.MICROK8S_HELM);
|
|
21
|
+
builder.arg(subcommand);
|
|
22
|
+
return builder;
|
|
23
|
+
}
|
|
24
|
+
kubectl(subcommand) {
|
|
25
|
+
const builder = new wsl_command_builder_1.WslCommandBuilder(this.identifier, this.commandExecutor);
|
|
26
|
+
builder.setExecutable(paths_1.LINUX_PATHS.KUBECTL_BIN);
|
|
27
|
+
builder.arg(subcommand);
|
|
28
|
+
return builder;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 執行 shell 命令
|
|
32
|
+
* @param command 可執行檔名稱(如 'mkdir', 'cat', 'chmod')
|
|
33
|
+
* @returns 命令建構器,可用 .arg() 添加參數
|
|
34
|
+
* @example env.shell('mkdir').arg('-p').arg('/var/data')
|
|
35
|
+
* @example env.shell('cat').arg('/proc/uptime')
|
|
36
|
+
*/
|
|
37
|
+
shell(command) {
|
|
38
|
+
const builder = new wsl_command_builder_1.WslCommandBuilder(this.identifier, this.commandExecutor);
|
|
39
|
+
builder.setExecutable(command);
|
|
40
|
+
return builder;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 執行 shell 腳本(支援重定向、管道等 shell 特性)
|
|
44
|
+
* @param script 完整的 shell 腳本字串
|
|
45
|
+
* @returns 命令建構器
|
|
46
|
+
* @example env.shellScript('cat > /tmp/file').stdin(content)
|
|
47
|
+
* @example env.shellScript('echo $HOME | grep user')
|
|
48
|
+
*/
|
|
49
|
+
shellScript(script) {
|
|
50
|
+
const builder = new wsl_command_builder_1.WslCommandBuilder(this.identifier, this.commandExecutor);
|
|
51
|
+
builder.setExecutable('sh');
|
|
52
|
+
builder.arg('-c');
|
|
53
|
+
builder.arg(`"${script}"`);
|
|
54
|
+
return builder;
|
|
55
|
+
}
|
|
56
|
+
async isAvailable() {
|
|
57
|
+
try {
|
|
58
|
+
const builder = new wsl_command_builder_1.WslCommandBuilder(this.identifier, this.commandExecutor);
|
|
59
|
+
builder.setExecutable('echo');
|
|
60
|
+
builder.arg('ok');
|
|
61
|
+
const result = await builder.exec();
|
|
62
|
+
return result.exitCode === 0;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.WslExecutionEnvironment = WslExecutionEnvironment;
|
|
70
|
+
//# sourceMappingURL=wsl-execution.environment.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
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.ExecutionEnvironmentFactory = void 0;
|
|
16
|
+
const tsyringe_1 = require("tsyringe");
|
|
17
|
+
const tokens_1 = require("../../di/tokens");
|
|
18
|
+
const wsl_execution_environment_1 = require("./environments/wsl-execution.environment");
|
|
19
|
+
/**
|
|
20
|
+
* 執行環境工廠
|
|
21
|
+
*
|
|
22
|
+
* 提供建立執行環境的工廠方法
|
|
23
|
+
*/
|
|
24
|
+
let ExecutionEnvironmentFactory = class ExecutionEnvironmentFactory {
|
|
25
|
+
constructor(commandExecutor, hostCommandBuilder) {
|
|
26
|
+
this.commandExecutor = commandExecutor;
|
|
27
|
+
this.hostCommandBuilder = hostCommandBuilder;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 取得指定實例的執行環境
|
|
31
|
+
* @param instanceName 實例名稱
|
|
32
|
+
* @returns 執行環境實例
|
|
33
|
+
*/
|
|
34
|
+
getForInstance(instanceName) {
|
|
35
|
+
// 目前只有 WSL 實作,未來可根據 Instance 元資料決定使用哪種執行環境
|
|
36
|
+
return new wsl_execution_environment_1.WslExecutionEnvironment(instanceName, this.commandExecutor);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 取得主機命令建構器
|
|
40
|
+
* @returns 主機命令建構器(根據平台返回對應實作,透過 DI 注入)
|
|
41
|
+
*/
|
|
42
|
+
getHostEnvironment() {
|
|
43
|
+
return this.hostCommandBuilder;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.ExecutionEnvironmentFactory = ExecutionEnvironmentFactory;
|
|
47
|
+
exports.ExecutionEnvironmentFactory = ExecutionEnvironmentFactory = __decorate([
|
|
48
|
+
(0, tsyringe_1.injectable)(),
|
|
49
|
+
__param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.ICommandExecutor)),
|
|
50
|
+
__param(1, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.IHostCommandBuilder)),
|
|
51
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
52
|
+
], ExecutionEnvironmentFactory);
|
|
53
|
+
//# sourceMappingURL=execution-environment.factory.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./command-executor.service"), exports);
|
|
18
|
+
__exportStar(require("./script-executor.service"), exports);
|
|
19
|
+
__exportStar(require("./execution-environment.factory"), exports);
|
|
20
|
+
__exportStar(require("./builders/base-command.builder"), exports);
|
|
21
|
+
__exportStar(require("./builders/host-command.builder"), exports);
|
|
22
|
+
__exportStar(require("./builders/windows-host-command.builder"), exports);
|
|
23
|
+
__exportStar(require("./builders/wsl-command.builder"), exports);
|
|
24
|
+
__exportStar(require("./environments/wsl-execution.environment"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EXECUTION_ENVIRONMENT_TYPES = void 0;
|
|
4
|
+
// 重新匯出類型供外部使用
|
|
5
|
+
var environments_1 = require("../../../constants/environments");
|
|
6
|
+
Object.defineProperty(exports, "EXECUTION_ENVIRONMENT_TYPES", { enumerable: true, get: function () { return environments_1.EXECUTION_ENVIRONMENT_TYPES; } });
|
|
7
|
+
//# sourceMappingURL=execution-environment.interface.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./command-executor.interface"), exports);
|
|
18
|
+
__exportStar(require("./script-executor.interface"), exports);
|
|
19
|
+
__exportStar(require("./command-builder.interface"), exports);
|
|
20
|
+
__exportStar(require("./execution-environment.interface"), exports);
|
|
21
|
+
__exportStar(require("./host-command-builder.interface"), exports);
|
|
22
|
+
__exportStar(require("./execution-environment-factory.interface"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|