@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,442 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.WslInstanceLifecycleService = void 0;
|
|
49
|
+
const tsyringe_1 = require("tsyringe");
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const os = __importStar(require("os"));
|
|
52
|
+
const tokens_1 = require("../../../../di/tokens");
|
|
53
|
+
const command_builder_1 = require("../../../execution/command-builder");
|
|
54
|
+
const index_1 = require("../../../../constants/index");
|
|
55
|
+
const errors_1 = require("../../../errors");
|
|
56
|
+
const input_validator_util_1 = require("../../../utils/input-validator.util");
|
|
57
|
+
/**
|
|
58
|
+
* WSL 實例生命週期服務
|
|
59
|
+
*
|
|
60
|
+
* 負責 WSL 實例的建立、啟動、停止、刪除等生命週期操作
|
|
61
|
+
* 包含系統檢查功能:WSL 安裝檢查、Rootfs 存在性、磁碟空間
|
|
62
|
+
*/
|
|
63
|
+
let WslInstanceLifecycleService = class WslInstanceLifecycleService {
|
|
64
|
+
constructor(commandExecutor, namingService, inspectionService, wslConfigService, microK8sService, wslInfo, metadataPort, appLogger) {
|
|
65
|
+
this.commandExecutor = commandExecutor;
|
|
66
|
+
this.namingService = namingService;
|
|
67
|
+
this.inspectionService = inspectionService;
|
|
68
|
+
this.wslConfigService = wslConfigService;
|
|
69
|
+
this.microK8sService = microK8sService;
|
|
70
|
+
this.wslInfo = wslInfo;
|
|
71
|
+
this.metadataPort = metadataPort;
|
|
72
|
+
this.appLogger = appLogger;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 建立 WSL 實例 (高階方法)
|
|
76
|
+
*/
|
|
77
|
+
async createInstance(displayName, installPath, chartVersion, rootfsPath, output) {
|
|
78
|
+
if (!this.namingService.validateInstanceName(displayName)) {
|
|
79
|
+
throw new errors_1.AppError(`Invalid instance name: ${displayName}`, {
|
|
80
|
+
exitCode: errors_1.EXIT_CODES.VALIDATION_ERROR,
|
|
81
|
+
solution: 'Only alphanumeric characters and hyphens are allowed'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const fullInstanceName = this.namingService.getFullInstanceName(displayName);
|
|
85
|
+
this.appLogger?.info('[WSL] Creating WSL instance', {
|
|
86
|
+
shortName: displayName,
|
|
87
|
+
fullName: fullInstanceName,
|
|
88
|
+
installPath,
|
|
89
|
+
chartVersion,
|
|
90
|
+
component: 'WslInstanceLifecycleService'
|
|
91
|
+
});
|
|
92
|
+
const actualRootfsPath = rootfsPath || this.namingService.getDefaultRootfsPath();
|
|
93
|
+
if (!await this.checkWslInstalled()) {
|
|
94
|
+
throw new errors_1.AppError('WSL is not installed', {
|
|
95
|
+
exitCode: errors_1.EXIT_CODES.ENVIRONMENT_ERROR,
|
|
96
|
+
solution: 'Please install WSL using: wsl --install'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (!this.checkRootfsExists(actualRootfsPath)) {
|
|
100
|
+
throw new errors_1.AppError('Ubuntu rootfs not found', {
|
|
101
|
+
exitCode: errors_1.EXIT_CODES.ENVIRONMENT_ERROR,
|
|
102
|
+
solution: 'Please download the rootfs first using: uofx env download-rootfs',
|
|
103
|
+
context: { expectedLocation: actualRootfsPath }
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (!await this.checkDiskSpace(5)) {
|
|
107
|
+
throw new errors_1.AppError('Insufficient disk space', {
|
|
108
|
+
exitCode: errors_1.EXIT_CODES.ENVIRONMENT_ERROR,
|
|
109
|
+
solution: 'Please free up disk space (required: 5 GB) and try again'
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (await this.inspectionService.checkInstanceExists(fullInstanceName)) {
|
|
113
|
+
throw new errors_1.AppError(`Instance '${fullInstanceName}' already exists`, {
|
|
114
|
+
exitCode: errors_1.EXIT_CODES.SYSTEM_ERROR,
|
|
115
|
+
solution: `Delete it first by running: uofx env delete --name ${displayName}`,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (!fs.existsSync(installPath)) {
|
|
119
|
+
fs.mkdirSync(installPath, { recursive: true });
|
|
120
|
+
}
|
|
121
|
+
output?.item('arrow', `Importing WSL instance (this may take a few minutes)...`).flush();
|
|
122
|
+
await this.importInstance(fullInstanceName, installPath, actualRootfsPath, output);
|
|
123
|
+
if (!await this.inspectionService.verifyInstance(fullInstanceName)) {
|
|
124
|
+
throw new errors_1.AppError(`Failed to verify instance '${fullInstanceName}'`, { exitCode: errors_1.EXIT_CODES.SYSTEM_ERROR });
|
|
125
|
+
}
|
|
126
|
+
output?.item('arrow', `Configuring systemd support...`).flush();
|
|
127
|
+
try {
|
|
128
|
+
output?.indent().item('arrow', `Creating default user 'ubuntu'`).outdent().flush();
|
|
129
|
+
await this.wslConfigService.createUser(fullInstanceName, 'ubuntu');
|
|
130
|
+
output?.indent().item('arrow', `Creating /etc/wsl.conf`).outdent().flush();
|
|
131
|
+
await this.wslConfigService.createWslConfig(fullInstanceName, 'ubuntu');
|
|
132
|
+
output?.indent().item('arrow', `Restarting WSL instance`).outdent().flush();
|
|
133
|
+
await this.wslConfigService.restartWslInstance(fullInstanceName);
|
|
134
|
+
output?.indent().success(`Systemd support enabled`).outdent().flush();
|
|
135
|
+
output?.indent().success(`Default user: ubuntu`).outdent().flush();
|
|
136
|
+
output?.indent().success(`WSL instance ready for use`).outdent().flush();
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
output?.error(`Failed to configure systemd: ${error}`).flush();
|
|
140
|
+
output?.indent().item('arrow', `Instance created but systemd configuration failed`).outdent().flush();
|
|
141
|
+
output?.indent().item('arrow', `You may need to configure it manually`).outdent().flush();
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
const metadata = {
|
|
145
|
+
name: fullInstanceName,
|
|
146
|
+
displayName: displayName,
|
|
147
|
+
createdAt: new Date().toISOString(),
|
|
148
|
+
version: '0.1.0',
|
|
149
|
+
chartVersion: chartVersion,
|
|
150
|
+
rootfsVersion: 'Ubuntu 22.04',
|
|
151
|
+
};
|
|
152
|
+
this.saveMetadata(metadata, installPath);
|
|
153
|
+
this.appLogger?.info('[WSL] WSL instance created successfully', {
|
|
154
|
+
fullName: fullInstanceName,
|
|
155
|
+
component: 'WslInstanceLifecycleService'
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 刪除 WSL 實例
|
|
160
|
+
*/
|
|
161
|
+
async deleteInstance(instanceName) {
|
|
162
|
+
(0, input_validator_util_1.requireValidInstanceName)(instanceName);
|
|
163
|
+
this.appLogger?.info('Deleting WSL instance', { instanceName });
|
|
164
|
+
const builder = command_builder_1.CommandBuilder.create('wsl')
|
|
165
|
+
.arg('--unregister')
|
|
166
|
+
.arg(instanceName);
|
|
167
|
+
await builder.exec(this.commandExecutor);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 匯入 WSL 實例
|
|
171
|
+
*/
|
|
172
|
+
async importInstance(instanceName, installPath, rootfsPath, output) {
|
|
173
|
+
(0, input_validator_util_1.requireValidInstanceName)(instanceName);
|
|
174
|
+
if (!fs.existsSync(installPath)) {
|
|
175
|
+
fs.mkdirSync(installPath, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
const builder = command_builder_1.CommandBuilder.create('wsl')
|
|
178
|
+
.arg('--import')
|
|
179
|
+
.arg(instanceName)
|
|
180
|
+
.arg(installPath)
|
|
181
|
+
.arg(rootfsPath);
|
|
182
|
+
await builder.exec(this.commandExecutor, () => { }, (stderr) => {
|
|
183
|
+
if (stderr.trim()) {
|
|
184
|
+
output?.error(`${stderr.trim()}`).flush();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 啟動 WSL 實例和 MicroK8s
|
|
190
|
+
*/
|
|
191
|
+
async startInstance(instanceName, output) {
|
|
192
|
+
(0, input_validator_util_1.requireValidInstanceName)(instanceName);
|
|
193
|
+
this.appLogger?.info('Starting WSL instance', { instanceName });
|
|
194
|
+
output?.item('arrow', `Starting WSL instance '${instanceName}'...`).flush();
|
|
195
|
+
output?.item('arrow', 'Initializing D-Bus session...').flush();
|
|
196
|
+
await this.initDBusSession(instanceName, output);
|
|
197
|
+
await new Promise((resolve) => setTimeout(resolve, index_1.TIMEOUTS.WSL_STARTUP_DELAY));
|
|
198
|
+
output?.item('arrow', 'Starting MicroK8s services...').flush();
|
|
199
|
+
try {
|
|
200
|
+
await this.microK8sService.start(instanceName);
|
|
201
|
+
await new Promise((resolve) => setTimeout(resolve, index_1.TIMEOUTS.WSL_FULL_STARTUP));
|
|
202
|
+
await this.microK8sService.restartContainerd(instanceName);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
// MicroK8s start 失敗不應阻止整個啟動流程
|
|
206
|
+
this.appLogger?.warn('MicroK8s start warning, continuing...', { error });
|
|
207
|
+
}
|
|
208
|
+
// output?.item('arrow', 'Waiting for MicroK8s to initialize...').flush();
|
|
209
|
+
// await new Promise((resolve) => setTimeout(resolve, TIMEOUTS.WSL_FULL_STARTUP));
|
|
210
|
+
output?.item('arrow', 'Waiting for MicroK8s to be ready...').flush();
|
|
211
|
+
try {
|
|
212
|
+
// await this.microK8sService.restartContainerd(instanceName);
|
|
213
|
+
const isReady = await this.microK8sService.waitForReady(instanceName);
|
|
214
|
+
if (!isReady) {
|
|
215
|
+
throw new errors_1.AppError('MicroK8s did not become ready within timeout', { exitCode: errors_1.EXIT_CODES.SYSTEM_ERROR, context: { instanceName } });
|
|
216
|
+
}
|
|
217
|
+
output?.success('MicroK8s is ready').flush();
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
this.appLogger?.error(error instanceof Error ? error : new Error(String(error)), {
|
|
221
|
+
operation: 'startInstance',
|
|
222
|
+
instanceName,
|
|
223
|
+
});
|
|
224
|
+
throw new errors_1.AppError('Failed to wait for MicroK8s ready', {
|
|
225
|
+
exitCode: errors_1.EXIT_CODES.SYSTEM_ERROR,
|
|
226
|
+
cause: error instanceof Error ? error : new Error(String(error)),
|
|
227
|
+
context: { instanceName }
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 停止 WSL 實例
|
|
233
|
+
*/
|
|
234
|
+
async stopInstance(instanceName, force = false, output) {
|
|
235
|
+
(0, input_validator_util_1.requireValidInstanceName)(instanceName);
|
|
236
|
+
this.appLogger?.info('Stopping WSL instance', { instanceName, force });
|
|
237
|
+
output?.item('arrow', `Stopping instance '${instanceName}'...`).flush();
|
|
238
|
+
if (!force) {
|
|
239
|
+
output?.item('arrow', 'Stopping MicroK8s services...').flush();
|
|
240
|
+
try {
|
|
241
|
+
await this.microK8sService.stop(instanceName);
|
|
242
|
+
await this.microK8sService.waitForStop();
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
this.appLogger?.warn('Failed to stop MicroK8s gracefully', { error });
|
|
246
|
+
output?.warning(`Failed to stop MicroK8s gracefully: ${error}`).flush();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
output?.item('arrow', 'Force stop requested, skipping MicroK8s graceful shutdown').flush();
|
|
251
|
+
}
|
|
252
|
+
output?.item('arrow', 'Shutting down WSL instance...').flush();
|
|
253
|
+
try {
|
|
254
|
+
const terminateBuilder = command_builder_1.CommandBuilder.create('wsl')
|
|
255
|
+
.arg('--terminate')
|
|
256
|
+
.arg(instanceName);
|
|
257
|
+
await terminateBuilder.exec(this.commandExecutor);
|
|
258
|
+
await new Promise((resolve) => setTimeout(resolve, index_1.TIMEOUTS.WSL_STARTUP_DELAY));
|
|
259
|
+
const status = await this.inspectionService.getInstanceStatus(instanceName);
|
|
260
|
+
if (status.running) {
|
|
261
|
+
await terminateBuilder.exec(this.commandExecutor);
|
|
262
|
+
await new Promise((resolve) => setTimeout(resolve, index_1.TIMEOUTS.WSL_STARTUP_DELAY));
|
|
263
|
+
const retryStatus = await this.inspectionService.getInstanceStatus(instanceName);
|
|
264
|
+
if (retryStatus.running) {
|
|
265
|
+
throw new errors_1.AppError('WSL instance is still running after termination', { exitCode: errors_1.EXIT_CODES.SYSTEM_ERROR, context: { instanceName } });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
this.appLogger?.error(error instanceof Error ? error : new Error(String(error)), {
|
|
271
|
+
operation: 'stopInstance',
|
|
272
|
+
instanceName,
|
|
273
|
+
});
|
|
274
|
+
throw new errors_1.AppError('Failed to terminate WSL instance', {
|
|
275
|
+
exitCode: errors_1.EXIT_CODES.SYSTEM_ERROR,
|
|
276
|
+
cause: error instanceof Error ? error : new Error(String(error)),
|
|
277
|
+
context: { instanceName }
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 初始化 D-Bus session (防止 WSL 自動停止)
|
|
283
|
+
*/
|
|
284
|
+
async initDBusSession(fullInstanceName, output) {
|
|
285
|
+
(0, input_validator_util_1.requireValidInstanceName)(fullInstanceName);
|
|
286
|
+
try {
|
|
287
|
+
const builder = command_builder_1.CommandBuilder.create('wsl')
|
|
288
|
+
.arg('-d')
|
|
289
|
+
.arg(fullInstanceName)
|
|
290
|
+
.arg('--exec')
|
|
291
|
+
.arg('dbus-launch')
|
|
292
|
+
.arg('true');
|
|
293
|
+
await builder.exec(this.commandExecutor);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
this.appLogger?.warn('D-Bus initialization warning', { error });
|
|
297
|
+
output?.warning(`D-Bus initialization warning: ${error}`).flush();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 等待 Kubernetes Pods 就緒
|
|
302
|
+
*/
|
|
303
|
+
async waitForPodsReady(instanceName, timeoutMs = index_1.TIMEOUTS.K8S_READY_TIMEOUT) {
|
|
304
|
+
return await this.microK8sService.waitForPodsReady(instanceName, timeoutMs);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 檢查 MicroK8s 是否正在執行
|
|
308
|
+
*/
|
|
309
|
+
async isMicroK8sRunning(instanceName) {
|
|
310
|
+
return await this.microK8sService.isRunning(instanceName);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* 等待 MicroK8s 停止
|
|
314
|
+
*/
|
|
315
|
+
async waitForMicroK8sStop() {
|
|
316
|
+
return await this.microK8sService.waitForStop();
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* 儲存實例 metadata
|
|
320
|
+
*/
|
|
321
|
+
saveMetadata(metadata, installPath) {
|
|
322
|
+
this.metadataPort.save(metadata, installPath);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* 載入實例 metadata
|
|
326
|
+
*/
|
|
327
|
+
loadMetadata(installPath) {
|
|
328
|
+
return this.metadataPort.load(installPath);
|
|
329
|
+
}
|
|
330
|
+
// ===========================================================================
|
|
331
|
+
// File Management Methods (原 WslFileManagerService)
|
|
332
|
+
// ===========================================================================
|
|
333
|
+
/**
|
|
334
|
+
* 移除實例儲存目錄
|
|
335
|
+
* @param instanceName 實例名稱(短名稱)
|
|
336
|
+
* @param output 輸出介面
|
|
337
|
+
*/
|
|
338
|
+
async removeInstanceDirectory(instanceName, output) {
|
|
339
|
+
const installPath = this.namingService.getInstallPath(instanceName);
|
|
340
|
+
output?.item('arrow', `Removing data directory: ${installPath}`).flush();
|
|
341
|
+
try {
|
|
342
|
+
if (fs.existsSync(installPath)) {
|
|
343
|
+
fs.rmSync(installPath, { recursive: true, force: true });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
this.appLogger?.warn('Failed to remove directory', { installPath, error });
|
|
348
|
+
output?.warning(`Failed to remove directory: ${installPath}`).flush();
|
|
349
|
+
output?.warning(`Error: ${error}`).flush();
|
|
350
|
+
output?.warning(`Please manually delete the directory`).flush();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* 取得目錄大小 (Bytes)
|
|
355
|
+
* @param dirPath 目錄路徑
|
|
356
|
+
* @returns 目錄大小 (Bytes)
|
|
357
|
+
*/
|
|
358
|
+
async getDirectorySize(dirPath) {
|
|
359
|
+
try {
|
|
360
|
+
const builder = command_builder_1.CommandBuilder.create('powershell')
|
|
361
|
+
.arg('-NoProfile')
|
|
362
|
+
.arg('-Command')
|
|
363
|
+
.arg(`(Get-ChildItem -Path '${dirPath.replace(/'/g, "''")}' -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum`);
|
|
364
|
+
const result = await builder.exec(this.commandExecutor);
|
|
365
|
+
if (result.exitCode !== 0)
|
|
366
|
+
return 0;
|
|
367
|
+
const size = parseInt(result.stdout.trim(), 10);
|
|
368
|
+
return isNaN(size) ? 0 : size;
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return 0;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* 格式化檔案大小為人類可讀格式
|
|
376
|
+
* @param bytes 位元組數
|
|
377
|
+
* @returns 格式化後的字串 (e.g., "1.5 GB")
|
|
378
|
+
*/
|
|
379
|
+
formatSize(bytes) {
|
|
380
|
+
const gb = bytes / index_1.FILE_SIZE.GB;
|
|
381
|
+
if (gb >= 1) {
|
|
382
|
+
return `${gb.toFixed(1)} GB`;
|
|
383
|
+
}
|
|
384
|
+
const mb = bytes / index_1.FILE_SIZE.MB;
|
|
385
|
+
return `${mb.toFixed(1)} MB`;
|
|
386
|
+
}
|
|
387
|
+
// ===========================================================================
|
|
388
|
+
// System Check Methods (原 WslSystemCheckService)
|
|
389
|
+
// ===========================================================================
|
|
390
|
+
/**
|
|
391
|
+
* 檢查 WSL 是否已安裝
|
|
392
|
+
* @returns 是否已安裝
|
|
393
|
+
*/
|
|
394
|
+
async checkWslInstalled() {
|
|
395
|
+
return await this.wslInfo.isWslInstalled();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* 檢查 rootfs 檔案是否存在
|
|
399
|
+
* @param rootfsPath Rootfs 檔案路徑
|
|
400
|
+
* @returns 是否存在
|
|
401
|
+
*/
|
|
402
|
+
checkRootfsExists(rootfsPath) {
|
|
403
|
+
return fs.existsSync(rootfsPath);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* 檢查磁碟空間是否足夠
|
|
407
|
+
* @param requiredSpaceGB 所需空間 (GB),預設 5 GB
|
|
408
|
+
* @returns 是否足夠
|
|
409
|
+
*/
|
|
410
|
+
async checkDiskSpace(requiredSpaceGB = 5) {
|
|
411
|
+
const homeDir = os.homedir();
|
|
412
|
+
const driveLetter = homeDir.charAt(0);
|
|
413
|
+
try {
|
|
414
|
+
const builder = command_builder_1.CommandBuilder.create('powershell')
|
|
415
|
+
.powershell(`(Get-PSDrive ${driveLetter}).Free`);
|
|
416
|
+
const result = await builder.exec(this.commandExecutor);
|
|
417
|
+
const freeSpaceBytes = parseInt(result.stdout.trim(), 10);
|
|
418
|
+
if (isNaN(freeSpaceBytes)) {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
const freeSpaceGB = freeSpaceBytes / index_1.FILE_SIZE.GB;
|
|
422
|
+
return freeSpaceGB >= requiredSpaceGB;
|
|
423
|
+
}
|
|
424
|
+
catch {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
exports.WslInstanceLifecycleService = WslInstanceLifecycleService;
|
|
430
|
+
exports.WslInstanceLifecycleService = WslInstanceLifecycleService = __decorate([
|
|
431
|
+
(0, tsyringe_1.injectable)(),
|
|
432
|
+
__param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.ICommandExecutor)),
|
|
433
|
+
__param(1, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.IWslInstanceNaming)),
|
|
434
|
+
__param(2, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.IWslInstanceInspection)),
|
|
435
|
+
__param(3, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.IWslConfig)),
|
|
436
|
+
__param(4, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.IMicroK8s)),
|
|
437
|
+
__param(5, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.WslInfoService)),
|
|
438
|
+
__param(6, (0, tsyringe_1.inject)(tokens_1.TOKENS.IInstanceMetadataPort)),
|
|
439
|
+
__param(7, (0, tsyringe_1.inject)(tokens_1.TOKENS.ILoggerPort)),
|
|
440
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object, Object, Object, Object, Object])
|
|
441
|
+
], WslInstanceLifecycleService);
|
|
442
|
+
//# sourceMappingURL=wsl-instance-lifecycle.service.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.WslInstanceNamingService = void 0;
|
|
43
|
+
const tsyringe_1 = require("tsyringe");
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const os = __importStar(require("os"));
|
|
46
|
+
const index_1 = require("../../../../constants/index");
|
|
47
|
+
const paths_1 = require("../../../../constants/paths");
|
|
48
|
+
const instance_name_value_object_1 = require("../../../../domain/value-objects/instance-name.value-object");
|
|
49
|
+
/**
|
|
50
|
+
* WSL 實例命名服務
|
|
51
|
+
*
|
|
52
|
+
* 負責實例名稱的驗證、轉換和路徑管理
|
|
53
|
+
*/
|
|
54
|
+
let WslInstanceNamingService = class WslInstanceNamingService {
|
|
55
|
+
/**
|
|
56
|
+
* 驗證實例名稱格式是否合法
|
|
57
|
+
* @param name 實例名稱
|
|
58
|
+
* @returns 是否合法 (委託給 Domain VO 驗證)
|
|
59
|
+
*/
|
|
60
|
+
validateInstanceName(name) {
|
|
61
|
+
return instance_name_value_object_1.InstanceName.isValid(name);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 產生完整實例名稱 (加上 uofx- 前綴)
|
|
65
|
+
* @param name 顯示名稱
|
|
66
|
+
* @returns 完整實例名稱
|
|
67
|
+
*/
|
|
68
|
+
getFullInstanceName(name) {
|
|
69
|
+
return `${index_1.INSTANCE_DEFAULTS.PREFIX}${name}`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 取得標準安裝路徑
|
|
73
|
+
* @param instanceName 實例名稱
|
|
74
|
+
* @returns 安裝路徑 (~/.uofx/instances/{instanceName})
|
|
75
|
+
*/
|
|
76
|
+
getInstallPath(instanceName) {
|
|
77
|
+
const homeDir = os.homedir();
|
|
78
|
+
return path.join(homeDir, paths_1.WINDOWS_PATHS.USER_CONFIG_DIR, 'instances', instanceName);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 取得預設 rootfs 路徑
|
|
82
|
+
* @returns 預設 rootfs 檔案路徑
|
|
83
|
+
*/
|
|
84
|
+
getDefaultRootfsPath() {
|
|
85
|
+
const homeDir = os.homedir();
|
|
86
|
+
return path.join(homeDir, paths_1.WINDOWS_PATHS.USER_CONFIG_DIR, paths_1.WINDOWS_PATHS.DEFAULT_ROOTFS);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.WslInstanceNamingService = WslInstanceNamingService;
|
|
90
|
+
exports.WslInstanceNamingService = WslInstanceNamingService = __decorate([
|
|
91
|
+
(0, tsyringe_1.injectable)()
|
|
92
|
+
], WslInstanceNamingService);
|
|
93
|
+
//# sourceMappingURL=wsl-instance-naming.service.js.map
|