@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,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OutputBuilder Service
|
|
4
|
+
*
|
|
5
|
+
* Fluent API 風格的輸出建構器
|
|
6
|
+
* 提供統一的縮排管理和緩衝輸出機制
|
|
7
|
+
*/
|
|
8
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
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;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
};
|
|
14
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
16
|
+
};
|
|
17
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
18
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.OutputBuilder = void 0;
|
|
22
|
+
const tsyringe_1 = require("tsyringe");
|
|
23
|
+
const tokens_1 = require("../../di/tokens");
|
|
24
|
+
const log_level_enum_1 = require("./log-level.enum");
|
|
25
|
+
const output_symbols_1 = require("./constants/output-symbols");
|
|
26
|
+
/**
|
|
27
|
+
* ANSI 顏色碼常數
|
|
28
|
+
*/
|
|
29
|
+
const ANSI = {
|
|
30
|
+
reset: '\x1b[0m',
|
|
31
|
+
bold: '\x1b[1m',
|
|
32
|
+
dim: '\x1b[2m',
|
|
33
|
+
green: '\x1b[32m',
|
|
34
|
+
yellow: '\x1b[33m',
|
|
35
|
+
red: '\x1b[31m',
|
|
36
|
+
cyan: '\x1b[36m',
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* OutputBuilder 實作
|
|
40
|
+
*
|
|
41
|
+
* 提供 Fluent API 風格的輸出建構器:
|
|
42
|
+
* - 支援縮排管理(indent/outdent)
|
|
43
|
+
* - 緩衝輸出機制(render/flush)
|
|
44
|
+
* - 自動清空 buffer
|
|
45
|
+
*/
|
|
46
|
+
let OutputBuilder = class OutputBuilder {
|
|
47
|
+
constructor(formatter) {
|
|
48
|
+
this.formatter = formatter;
|
|
49
|
+
this.buffer = [];
|
|
50
|
+
this.currentIndent = 0;
|
|
51
|
+
this.logLevel = log_level_enum_1.OutputLogLevel.INFO;
|
|
52
|
+
this.suppressed = false;
|
|
53
|
+
this.tty = process.stdout.isTTY ?? false;
|
|
54
|
+
this.colorEnabled = this.detectColorSupport();
|
|
55
|
+
this.formatter.setColorEnabled(this.colorEnabled);
|
|
56
|
+
}
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// 私有方法
|
|
59
|
+
// ============================================================================
|
|
60
|
+
/**
|
|
61
|
+
* 偵測顏色支援
|
|
62
|
+
*/
|
|
63
|
+
detectColorSupport() {
|
|
64
|
+
if (process.env.NO_COLOR !== undefined) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (process.env.FORCE_COLOR !== undefined) {
|
|
68
|
+
return process.env.FORCE_COLOR !== '0';
|
|
69
|
+
}
|
|
70
|
+
if (process.env.CI && !process.env.FORCE_COLOR) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return this.tty;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 取得縮排字串
|
|
77
|
+
*/
|
|
78
|
+
getIndentString(level) {
|
|
79
|
+
const safeLevel = Math.min(Math.max(0, level), output_symbols_1.INDENT_CONFIG.MAX_LEVEL);
|
|
80
|
+
return output_symbols_1.INDENT_CONFIG.UNIT.repeat(safeLevel);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 取得基礎縮排空格數
|
|
84
|
+
* 根據輸出類型決定基礎縮排,讓視覺層級更清晰
|
|
85
|
+
*/
|
|
86
|
+
getBaseIndentSpaces(_type, _itemType) {
|
|
87
|
+
// 所有類型統一 2 空格基礎縮排
|
|
88
|
+
return 2;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 套用顏色格式
|
|
92
|
+
*/
|
|
93
|
+
applyColor(text, colorCode) {
|
|
94
|
+
if (!this.colorEnabled) {
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
97
|
+
return `${colorCode}${text}${ANSI.reset}`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 檢查訊息是否應該被輸出
|
|
101
|
+
*/
|
|
102
|
+
shouldOutput(level) {
|
|
103
|
+
return (0, log_level_enum_1.shouldOutputLevel)(level, this.logLevel);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 輸出到 stdout
|
|
107
|
+
*/
|
|
108
|
+
write(message) {
|
|
109
|
+
process.stdout.write(message + '\n');
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 輸出到 stderr
|
|
113
|
+
*/
|
|
114
|
+
writeError(message) {
|
|
115
|
+
process.stderr.write(message + '\n');
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 加入緩衝區
|
|
119
|
+
*/
|
|
120
|
+
addToBuffer(item) {
|
|
121
|
+
// 抑制期間跳過非 section/success/error/warning 的輸出
|
|
122
|
+
if (this.suppressed) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.buffer.push(item);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 渲染單一緩衝項目
|
|
129
|
+
*/
|
|
130
|
+
renderItem(item) {
|
|
131
|
+
// 計算總縮排:基礎縮排 + 使用者指定的縮排
|
|
132
|
+
const baseIndentSpaces = this.getBaseIndentSpaces(item.type, item.itemType);
|
|
133
|
+
const userIndent = this.getIndentString(item.indent);
|
|
134
|
+
const baseIndent = ' '.repeat(baseIndentSpaces);
|
|
135
|
+
const totalIndent = baseIndent + userIndent;
|
|
136
|
+
switch (item.type) {
|
|
137
|
+
case 'line':
|
|
138
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.INFO)) {
|
|
139
|
+
const lineIndent = this.getIndentString(item.indent);
|
|
140
|
+
this.write(`${lineIndent}${item.content}`);
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case 'info':
|
|
144
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.INFO)) {
|
|
145
|
+
this.write(`${totalIndent}${item.content}`);
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
case 'section':
|
|
149
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.INFO)) {
|
|
150
|
+
const boldText = this.formatter.formatBold(item.content);
|
|
151
|
+
this.write(`${totalIndent}${boldText}`);
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
case 'success':
|
|
155
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.INFO)) {
|
|
156
|
+
const successText = this.applyColor(`${output_symbols_1.OUTPUT_SYMBOLS.SUCCESS} ${item.content}`, ANSI.green);
|
|
157
|
+
this.write(`${totalIndent}${successText}`);
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case 'error':
|
|
161
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.ERROR)) {
|
|
162
|
+
const errorText = this.applyColor(`${output_symbols_1.OUTPUT_SYMBOLS.ERROR} ${item.content}`, ANSI.red);
|
|
163
|
+
this.writeError(`${totalIndent}${errorText}`);
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
case 'warning':
|
|
167
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.WARN)) {
|
|
168
|
+
const warningText = this.applyColor(`${output_symbols_1.OUTPUT_SYMBOLS.WARNING} ${item.content}`, ANSI.yellow);
|
|
169
|
+
this.write(`${totalIndent}${warningText}`);
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
case 'item':
|
|
173
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.INFO) && item.itemType) {
|
|
174
|
+
const symbol = (0, output_symbols_1.getSymbolForItem)(item.itemType);
|
|
175
|
+
this.write(`${totalIndent}${symbol} ${item.content}`);
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
case 'newline':
|
|
179
|
+
this.write('');
|
|
180
|
+
break;
|
|
181
|
+
case 'divider':
|
|
182
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.INFO) && item.dividerData) {
|
|
183
|
+
const dividerStr = this.formatter.formatDivider(item.dividerData.length, item.dividerData.char);
|
|
184
|
+
this.write(`${totalIndent}${dividerStr}`);
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
case 'table':
|
|
188
|
+
if (this.shouldOutput(log_level_enum_1.OutputLogLevel.INFO) && item.tableData) {
|
|
189
|
+
const tableStr = this.formatter.formatTable(item.tableData.headers, item.tableData.rows, item.tableData.options);
|
|
190
|
+
// 為表格的每一行加上縮排
|
|
191
|
+
const indentedTable = tableStr
|
|
192
|
+
.split('\n')
|
|
193
|
+
.map(line => `${totalIndent}${line}`)
|
|
194
|
+
.join('\n');
|
|
195
|
+
this.write(indentedTable);
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// ============================================================================
|
|
201
|
+
// Fluent API - 文字輸出
|
|
202
|
+
// ============================================================================
|
|
203
|
+
line(message) {
|
|
204
|
+
this.addToBuffer({
|
|
205
|
+
type: 'line',
|
|
206
|
+
content: message,
|
|
207
|
+
indent: this.currentIndent,
|
|
208
|
+
});
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
section(message) {
|
|
212
|
+
this.addToBuffer({
|
|
213
|
+
type: 'section',
|
|
214
|
+
content: message,
|
|
215
|
+
indent: this.currentIndent,
|
|
216
|
+
});
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
info(message) {
|
|
220
|
+
this.addToBuffer({
|
|
221
|
+
type: 'info',
|
|
222
|
+
content: message,
|
|
223
|
+
indent: this.currentIndent,
|
|
224
|
+
});
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
success(message) {
|
|
228
|
+
this.addToBuffer({
|
|
229
|
+
type: 'success',
|
|
230
|
+
content: message,
|
|
231
|
+
indent: this.currentIndent,
|
|
232
|
+
});
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
error(message) {
|
|
236
|
+
this.addToBuffer({
|
|
237
|
+
type: 'error',
|
|
238
|
+
content: message,
|
|
239
|
+
indent: this.currentIndent,
|
|
240
|
+
});
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
warning(message) {
|
|
244
|
+
this.addToBuffer({
|
|
245
|
+
type: 'warning',
|
|
246
|
+
content: message,
|
|
247
|
+
indent: this.currentIndent,
|
|
248
|
+
});
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
item(type, message) {
|
|
252
|
+
this.addToBuffer({
|
|
253
|
+
type: 'item',
|
|
254
|
+
content: message,
|
|
255
|
+
indent: this.currentIndent,
|
|
256
|
+
itemType: type,
|
|
257
|
+
});
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
// ============================================================================
|
|
261
|
+
// Fluent API - 縮排管理
|
|
262
|
+
// ============================================================================
|
|
263
|
+
indent(levels = 1) {
|
|
264
|
+
this.currentIndent = Math.min(this.currentIndent + levels, output_symbols_1.INDENT_CONFIG.MAX_LEVEL);
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
outdent(levels = 1) {
|
|
268
|
+
this.currentIndent = Math.max(this.currentIndent - levels, 0);
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
resetIndent() {
|
|
272
|
+
this.currentIndent = 0;
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
// ============================================================================
|
|
276
|
+
// Fluent API - 格式化輸出
|
|
277
|
+
// ============================================================================
|
|
278
|
+
newline() {
|
|
279
|
+
this.addToBuffer({
|
|
280
|
+
type: 'newline',
|
|
281
|
+
content: '',
|
|
282
|
+
indent: 0,
|
|
283
|
+
});
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
divider(length = 60, char = output_symbols_1.OUTPUT_SYMBOLS.DIVIDER) {
|
|
287
|
+
this.addToBuffer({
|
|
288
|
+
type: 'divider',
|
|
289
|
+
content: '',
|
|
290
|
+
indent: this.currentIndent,
|
|
291
|
+
dividerData: { length, char },
|
|
292
|
+
});
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
table(headers, rows, options) {
|
|
296
|
+
this.addToBuffer({
|
|
297
|
+
type: 'table',
|
|
298
|
+
content: '',
|
|
299
|
+
indent: this.currentIndent,
|
|
300
|
+
tableData: { headers, rows, options },
|
|
301
|
+
});
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
304
|
+
// ============================================================================
|
|
305
|
+
// 渲染方法
|
|
306
|
+
// ============================================================================
|
|
307
|
+
render() {
|
|
308
|
+
for (const item of this.buffer) {
|
|
309
|
+
this.renderItem(item);
|
|
310
|
+
}
|
|
311
|
+
this.buffer = [];
|
|
312
|
+
}
|
|
313
|
+
flush() {
|
|
314
|
+
this.render();
|
|
315
|
+
}
|
|
316
|
+
// ============================================================================
|
|
317
|
+
// 輔助方法
|
|
318
|
+
// ============================================================================
|
|
319
|
+
getBufferSize() {
|
|
320
|
+
return this.buffer.length;
|
|
321
|
+
}
|
|
322
|
+
getIndentLevel() {
|
|
323
|
+
return this.currentIndent;
|
|
324
|
+
}
|
|
325
|
+
clear() {
|
|
326
|
+
this.buffer = [];
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
suppress() {
|
|
330
|
+
this.suppressed = true;
|
|
331
|
+
return this;
|
|
332
|
+
}
|
|
333
|
+
resume() {
|
|
334
|
+
this.suppressed = false;
|
|
335
|
+
return this;
|
|
336
|
+
}
|
|
337
|
+
// ============================================================================
|
|
338
|
+
// 配置方法(為了與現有系統相容)
|
|
339
|
+
// ============================================================================
|
|
340
|
+
/**
|
|
341
|
+
* 設定日誌等級
|
|
342
|
+
*/
|
|
343
|
+
setLogLevel(level) {
|
|
344
|
+
this.logLevel = level;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* 取得目前日誌等級
|
|
348
|
+
*/
|
|
349
|
+
getLogLevel() {
|
|
350
|
+
return this.logLevel;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* 啟用或停用顏色輸出
|
|
354
|
+
*/
|
|
355
|
+
setColorEnabled(enabled) {
|
|
356
|
+
this.colorEnabled = enabled;
|
|
357
|
+
this.formatter.setColorEnabled(enabled);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* 檢查顏色輸出是否啟用
|
|
361
|
+
*/
|
|
362
|
+
isColorEnabled() {
|
|
363
|
+
return this.colorEnabled;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* 檢查是否為 TTY 終端
|
|
367
|
+
*/
|
|
368
|
+
isTTY() {
|
|
369
|
+
return this.tty;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
exports.OutputBuilder = OutputBuilder;
|
|
373
|
+
exports.OutputBuilder = OutputBuilder = __decorate([
|
|
374
|
+
(0, tsyringe_1.injectable)(),
|
|
375
|
+
__param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.IOutputFormatter)),
|
|
376
|
+
__metadata("design:paramtypes", [Object])
|
|
377
|
+
], OutputBuilder);
|
|
378
|
+
//# sourceMappingURL=output-builder.service.js.map
|