@notask/unity-cli-tools 1.1.2 → 2.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/.claude/settings.local.json +7 -0
- package/CHANGELOG.md +164 -146
- package/LICENSE +23 -23
- package/README.md +809 -347
- package/dist/cjs/errors/Result.js +76 -0
- package/dist/cjs/errors/UnityError.js +77 -0
- package/dist/cjs/errors/index.js +18 -0
- package/dist/cjs/events/hubEventEmitter.js +16 -16
- package/dist/cjs/events/hubEventParser.js +97 -27
- package/dist/cjs/events/patterns/implementations/bracketModulePattern.js +57 -0
- package/dist/cjs/events/patterns/implementations/errorPattern.js +99 -0
- package/dist/cjs/events/patterns/implementations/fallbackPattern.js +63 -0
- package/dist/cjs/events/patterns/implementations/index.js +9 -0
- package/dist/cjs/events/patterns/index.js +23 -0
- package/dist/cjs/events/patterns/patternRegistry.js +69 -0
- package/dist/cjs/events/patterns/statusNormalizer.js +280 -0
- package/dist/cjs/events/patterns/types.js +2 -0
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/unityEditor.js +162 -194
- package/dist/cjs/unityHub.js +82 -78
- package/dist/cjs/utils/commandExecutor.js +8 -9
- package/dist/esm/errors/Result.d.ts +21 -0
- package/dist/esm/errors/Result.js +63 -0
- package/dist/esm/errors/UnityError.d.ts +36 -0
- package/dist/esm/errors/UnityError.js +64 -0
- package/dist/esm/errors/index.d.ts +2 -0
- package/dist/esm/errors/index.js +2 -0
- package/dist/esm/events/hubEventEmitter.d.ts +1 -1
- package/dist/esm/events/hubEventParser.d.ts +17 -3
- package/dist/esm/events/hubEventParser.js +97 -27
- package/dist/esm/events/patterns/implementations/bracketModulePattern.d.ts +11 -0
- package/dist/esm/events/patterns/implementations/bracketModulePattern.js +53 -0
- package/dist/esm/events/patterns/implementations/errorPattern.d.ts +22 -0
- package/dist/esm/events/patterns/implementations/errorPattern.js +95 -0
- package/dist/esm/events/patterns/implementations/fallbackPattern.d.ts +13 -0
- package/dist/esm/events/patterns/implementations/fallbackPattern.js +59 -0
- package/dist/esm/events/patterns/implementations/index.d.ts +3 -0
- package/dist/esm/events/patterns/implementations/index.js +3 -0
- package/dist/esm/events/patterns/index.d.ts +4 -0
- package/dist/esm/events/patterns/index.js +4 -0
- package/dist/esm/events/patterns/patternRegistry.d.ts +14 -0
- package/dist/esm/events/patterns/patternRegistry.js +65 -0
- package/dist/esm/events/patterns/statusNormalizer.d.ts +15 -0
- package/dist/esm/events/patterns/statusNormalizer.js +276 -0
- package/dist/esm/events/patterns/types.d.ts +30 -0
- package/dist/esm/events/patterns/types.js +1 -0
- package/dist/esm/index.d.ts +5 -4
- package/dist/esm/index.js +1 -0
- package/dist/esm/unityEditor.d.ts +11 -13
- package/dist/esm/unityEditor.js +175 -207
- package/dist/esm/unityHub.d.ts +12 -11
- package/dist/esm/unityHub.js +80 -76
- package/dist/esm/utils/commandExecutor.d.ts +4 -3
- package/dist/esm/utils/commandExecutor.js +8 -9
- package/package.json +70 -70
- package/sandbox/index.js +51 -0
- package/sandbox/node_modules/.package-lock.json +10495 -0
- package/sandbox/package.json +13 -0
package/dist/esm/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { ProjectInfo, TestMode, UnityBuildTarget, UnityEditorInfo } from "./types/unity.js";
|
|
2
|
-
import { CommandOptions,
|
|
2
|
+
import { CommandOptions, CommandOutput } from "./utils/commandExecutor.js";
|
|
3
|
+
import { Result, UnityEditorNotFoundError, UnityCommandError, UnityTestError, UnityLicenseError, UnityPackageError, UnityProjectError } from "./errors/index.js";
|
|
3
4
|
declare class UnityEditor {
|
|
4
5
|
static getUnityExecutablePath(version: string): string;
|
|
5
6
|
static isUnityVersionInstalled(version: string): Promise<boolean>;
|
|
6
|
-
static execUnityEditorCommand(editorInfo: UnityEditorInfo, args: string[], options?: CommandOptions): Promise<
|
|
7
|
-
static executeMethod(projectInfo: ProjectInfo, method: string, args?: string[], options?: CommandOptions): Promise<
|
|
8
|
-
static runTests(projectInfo: ProjectInfo, testPlatform?: TestMode | UnityBuildTarget, testCategory?: string): Promise<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
15
|
-
static importPackage(projectInfo: ProjectInfo, packagePath: string): Promise<boolean>;
|
|
16
|
-
static createProject(projectInfo: ProjectInfo, waitForExit?: boolean): Promise<boolean>;
|
|
17
|
-
static openProject(projectInfo: ProjectInfo, useHub?: boolean, batchmode?: boolean, waitForExit?: boolean): Promise<boolean>;
|
|
7
|
+
static execUnityEditorCommand(editorInfo: UnityEditorInfo, args: string[], options?: CommandOptions): Promise<Result<CommandOutput, UnityEditorNotFoundError | UnityCommandError>>;
|
|
8
|
+
static executeMethod(projectInfo: ProjectInfo, method: string, args?: string[], options?: CommandOptions): Promise<Result<CommandOutput, UnityEditorNotFoundError | UnityCommandError>>;
|
|
9
|
+
static runTests(projectInfo: ProjectInfo, testPlatform?: TestMode | UnityBuildTarget, testCategory?: string): Promise<Result<string, UnityEditorNotFoundError | UnityCommandError | UnityTestError>>;
|
|
10
|
+
static activateLicense(projectInfo: ProjectInfo, serial: string, username: string, password: string): Promise<Result<void, UnityEditorNotFoundError | UnityCommandError | UnityLicenseError>>;
|
|
11
|
+
static returnLicense(projectInfo: ProjectInfo): Promise<Result<void, UnityEditorNotFoundError | UnityCommandError | UnityLicenseError>>;
|
|
12
|
+
static exportPackage(projectInfo: ProjectInfo, assetPaths: string[], outputPath: string): Promise<Result<void, UnityEditorNotFoundError | UnityCommandError | UnityPackageError>>;
|
|
13
|
+
static importPackage(projectInfo: ProjectInfo, packagePath: string): Promise<Result<void, UnityEditorNotFoundError | UnityCommandError | UnityPackageError>>;
|
|
14
|
+
static createProject(projectInfo: ProjectInfo, waitForExit?: boolean): Promise<Result<void, UnityEditorNotFoundError | UnityCommandError | UnityProjectError>>;
|
|
15
|
+
static openProject(projectInfo: ProjectInfo, useHub?: boolean, batchmode?: boolean, waitForExit?: boolean): Promise<Result<void, UnityEditorNotFoundError | UnityCommandError | UnityProjectError>>;
|
|
18
16
|
}
|
|
19
17
|
export default UnityEditor;
|
package/dist/esm/unityEditor.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from "path";
|
|
|
4
4
|
import { TestMode } from "./types/unity.js";
|
|
5
5
|
import { executeCommand } from "./utils/commandExecutor.js";
|
|
6
6
|
import { redactSensitiveArgs } from "./utils/security.js";
|
|
7
|
+
import { ok, err, UnityEditorNotFoundError, UnityCommandError, UnityTestError, UnityLicenseError, UnityPackageError, UnityProjectError, } from "./errors/index.js";
|
|
7
8
|
class UnityEditor {
|
|
8
9
|
static UNITY_PATHS = {
|
|
9
10
|
win32: {
|
|
@@ -36,195 +37,158 @@ class UnityEditor {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
static async execUnityEditorCommand(editorInfo, args, options = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const editorArgs = [...args];
|
|
50
|
-
const redactedArgs = redactSensitiveArgs(editorArgs);
|
|
51
|
-
console.debug(`Executing Unity Editor command: ${unityPath} ${redactedArgs.join(" ")}`);
|
|
52
|
-
return await executeCommand(unityPath, editorArgs, options);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
console.error("Error executing Unity Editor command:", error);
|
|
56
|
-
return {
|
|
57
|
-
success: false,
|
|
58
|
-
stdout: "",
|
|
59
|
-
stderr: String(error),
|
|
60
|
-
exitCode: -1,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
40
|
+
const unityPath = this.getUnityExecutablePath(editorInfo.version);
|
|
41
|
+
if (!fs.existsSync(unityPath)) {
|
|
42
|
+
return err(new UnityEditorNotFoundError(editorInfo.version, unityPath));
|
|
43
|
+
}
|
|
44
|
+
const editorArgs = [...args];
|
|
45
|
+
const redactedArgs = redactSensitiveArgs(editorArgs);
|
|
46
|
+
console.debug(`Executing Unity Editor command: ${unityPath} ${redactedArgs.join(" ")}`);
|
|
47
|
+
return await executeCommand(unityPath, editorArgs, options);
|
|
63
48
|
}
|
|
64
49
|
static async executeMethod(projectInfo, method, args = [], options = {}) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
success: true,
|
|
81
|
-
stdout: stdout,
|
|
82
|
-
stderr: "",
|
|
83
|
-
exitCode: 0,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
console.error("Error executing method:", error);
|
|
88
|
-
return {
|
|
89
|
-
success: false,
|
|
90
|
-
stdout: "",
|
|
91
|
-
stderr: String(error),
|
|
92
|
-
exitCode: -1,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
50
|
+
console.debug(`Executing method ${method} in Unity Editor`);
|
|
51
|
+
const unityPath = this.getUnityExecutablePath(projectInfo.editorVersion);
|
|
52
|
+
const editorArgs = ["-projectPath", projectInfo.projectPath, "-executeMethod", method, ...args];
|
|
53
|
+
const result = await this.execUnityEditorCommand({ version: projectInfo.editorVersion, path: unityPath }, editorArgs, options);
|
|
54
|
+
if (!result.success) {
|
|
55
|
+
console.error(`Error executing method: ${result.error.message}`);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
if (result.value.stderr) {
|
|
59
|
+
console.error(`Error executing method: ${result.value.stderr}`);
|
|
60
|
+
return err(new UnityCommandError(`Error executing method ${method}: ${result.value.stderr}`, result.value.stdout, result.value.stderr, result.value.exitCode, { method, projectInfo }));
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
95
63
|
}
|
|
96
64
|
static async runTests(projectInfo, testPlatform = TestMode.EditMode, testCategory) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
65
|
+
console.debug(`Running ${testPlatform} tests for project${testCategory ? ` in category ${testCategory}` : ""}`);
|
|
66
|
+
const args = [
|
|
67
|
+
"-batchmode",
|
|
68
|
+
"-quit",
|
|
69
|
+
"-projectPath",
|
|
70
|
+
projectInfo.projectPath,
|
|
71
|
+
"-runTests",
|
|
72
|
+
"-testPlatform",
|
|
73
|
+
testPlatform,
|
|
74
|
+
];
|
|
75
|
+
if (testCategory) {
|
|
76
|
+
args.push("-testCategory", testCategory);
|
|
77
|
+
}
|
|
78
|
+
const editorInfo = { version: projectInfo.editorVersion };
|
|
79
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, {
|
|
80
|
+
reject: false,
|
|
81
|
+
});
|
|
82
|
+
if (!result.success) {
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
const { stdout, stderr } = result.value;
|
|
86
|
+
const testsFailed = stdout.includes("Some tests failed") || stdout.includes("Test run failed") || stderr.includes("Test run failed");
|
|
87
|
+
if (testsFailed) {
|
|
88
|
+
return err(new UnityTestError("Some tests failed", stdout, {
|
|
89
|
+
projectInfo,
|
|
106
90
|
testPlatform,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
args.push("-testCategory", testCategory);
|
|
110
|
-
}
|
|
111
|
-
const editorInfo = { version: projectInfo.editorVersion };
|
|
112
|
-
const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
|
|
113
|
-
reject: false,
|
|
114
|
-
});
|
|
115
|
-
const testsFailed = stdout.includes("Some tests failed") ||
|
|
116
|
-
stdout.includes("Test run failed") ||
|
|
117
|
-
stderr.includes("Test run failed");
|
|
118
|
-
return {
|
|
119
|
-
success: !testsFailed,
|
|
120
|
-
output: stdout,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
console.error("Error running tests:", error);
|
|
125
|
-
return {
|
|
126
|
-
success: false,
|
|
127
|
-
output: String(error),
|
|
128
|
-
};
|
|
91
|
+
testCategory,
|
|
92
|
+
}));
|
|
129
93
|
}
|
|
94
|
+
return ok(stdout);
|
|
130
95
|
}
|
|
131
96
|
static async activateLicense(projectInfo, serial, username, password) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
97
|
+
console.debug(`Activating Unity license for version ${projectInfo.editorVersion}`);
|
|
98
|
+
const args = ["-quit", "-serial", serial, "-username", username, "-password", password];
|
|
99
|
+
const editorInfo = { version: projectInfo.editorVersion };
|
|
100
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, {
|
|
101
|
+
reject: false,
|
|
102
|
+
});
|
|
103
|
+
if (!result.success) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
const { stdout, stderr } = result.value;
|
|
107
|
+
const activationSuccessful = stdout.includes("successfully activated") ||
|
|
108
|
+
(!stdout.includes("License activation failed") && !stderr.includes("License activation failed"));
|
|
109
|
+
if (activationSuccessful) {
|
|
110
|
+
console.debug(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
|
|
111
|
+
return ok(undefined);
|
|
112
|
+
}
|
|
113
|
+
return err(new UnityLicenseError(`Failed to activate license: ${stderr || stdout}`, {
|
|
114
|
+
projectInfo,
|
|
115
|
+
stderr,
|
|
116
|
+
stdout,
|
|
117
|
+
}));
|
|
154
118
|
}
|
|
155
119
|
static async returnLicense(projectInfo) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
120
|
+
console.debug(`Returning Unity license for version ${projectInfo.editorVersion}`);
|
|
121
|
+
const args = ["-quit", "-returnlicense"];
|
|
122
|
+
const editorInfo = { version: projectInfo.editorVersion };
|
|
123
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, {
|
|
124
|
+
reject: false,
|
|
125
|
+
});
|
|
126
|
+
if (!result.success) {
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
const { stdout, stderr } = result.value;
|
|
130
|
+
const returnSuccessful = stdout.includes("license return succeeded") ||
|
|
131
|
+
(!stdout.includes("Failed to return license") && !stderr.includes("Failed to return license"));
|
|
132
|
+
if (returnSuccessful) {
|
|
133
|
+
console.debug(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
|
|
134
|
+
return ok(undefined);
|
|
135
|
+
}
|
|
136
|
+
return err(new UnityLicenseError(`Failed to return license: ${stderr || stdout}`, {
|
|
137
|
+
projectInfo,
|
|
138
|
+
stderr,
|
|
139
|
+
stdout,
|
|
140
|
+
}));
|
|
178
141
|
}
|
|
179
142
|
static async exportPackage(projectInfo, assetPaths, outputPath) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
143
|
+
console.debug(`Exporting package from project`);
|
|
144
|
+
const args = ["-projectPath", projectInfo.projectPath, "-exportPackage", ...assetPaths, outputPath, "-quit"];
|
|
145
|
+
const editorInfo = { version: projectInfo.editorVersion };
|
|
146
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, {
|
|
147
|
+
reject: false,
|
|
148
|
+
});
|
|
149
|
+
if (!result.success) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
const { stdout, stderr } = result.value;
|
|
153
|
+
const exportSuccessful = !stdout.includes("Failed to export package") && !stderr.includes("Failed to export package");
|
|
154
|
+
if (exportSuccessful) {
|
|
155
|
+
console.debug(`Successfully exported package to ${outputPath}`);
|
|
156
|
+
return ok(undefined);
|
|
157
|
+
}
|
|
158
|
+
return err(new UnityPackageError(`Failed to export package: ${stderr || stdout}`, {
|
|
159
|
+
projectInfo,
|
|
160
|
+
assetPaths,
|
|
161
|
+
outputPath,
|
|
162
|
+
stderr,
|
|
163
|
+
stdout,
|
|
164
|
+
}));
|
|
201
165
|
}
|
|
202
166
|
static async importPackage(projectInfo, packagePath) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
167
|
+
console.debug(`Importing package ${packagePath} to project`);
|
|
168
|
+
const args = ["-projectPath", projectInfo.projectPath, "-importPackage", packagePath, "-quit"];
|
|
169
|
+
const editorInfo = { version: projectInfo.editorVersion };
|
|
170
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, {
|
|
171
|
+
reject: false,
|
|
172
|
+
});
|
|
173
|
+
if (!result.success) {
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
const { stdout, stderr } = result.value;
|
|
177
|
+
const importSuccessful = !stdout.includes("Failed to import package") && !stderr.includes("Failed to import package");
|
|
178
|
+
if (importSuccessful) {
|
|
179
|
+
console.debug(`Successfully imported package ${packagePath}`);
|
|
180
|
+
return ok(undefined);
|
|
181
|
+
}
|
|
182
|
+
return err(new UnityPackageError(`Failed to import package: ${stderr || stdout}`, {
|
|
183
|
+
projectInfo,
|
|
184
|
+
packagePath,
|
|
185
|
+
stderr,
|
|
186
|
+
stdout,
|
|
187
|
+
}));
|
|
224
188
|
}
|
|
225
189
|
static async createProject(projectInfo, waitForExit = true) {
|
|
190
|
+
console.debug(`Creating new project at ${projectInfo.projectPath}`);
|
|
226
191
|
try {
|
|
227
|
-
console.debug(`Creating new project at ${projectInfo.projectPath}`);
|
|
228
192
|
const parentDir = path.dirname(projectInfo.projectPath);
|
|
229
193
|
await fs.ensureDir(parentDir);
|
|
230
194
|
const args = ["-createProject", projectInfo.projectPath];
|
|
@@ -232,53 +196,57 @@ class UnityEditor {
|
|
|
232
196
|
args.push("-quit");
|
|
233
197
|
}
|
|
234
198
|
const editorInfo = { version: projectInfo.editorVersion };
|
|
235
|
-
const
|
|
199
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, {
|
|
236
200
|
reject: false,
|
|
237
201
|
});
|
|
202
|
+
if (!result.success) {
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
const { stdout, stderr } = result.value;
|
|
238
206
|
const creationSuccessful = !stdout.includes("Failed to create project") && !stderr.includes("Failed to create project");
|
|
239
207
|
if (creationSuccessful) {
|
|
240
208
|
console.debug(`Successfully created project at ${projectInfo.projectPath}`);
|
|
241
|
-
return
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
console.error(`Failed to create project: ${stderr || stdout}`);
|
|
245
|
-
return false;
|
|
209
|
+
return ok(undefined);
|
|
246
210
|
}
|
|
211
|
+
return err(new UnityProjectError(`Failed to create project: ${stderr || stdout}`, {
|
|
212
|
+
projectInfo,
|
|
213
|
+
stderr,
|
|
214
|
+
stdout,
|
|
215
|
+
}));
|
|
247
216
|
}
|
|
248
217
|
catch (error) {
|
|
249
218
|
console.error("Error creating project:", error);
|
|
250
|
-
return
|
|
219
|
+
return err(new UnityProjectError(`Error creating project: ${String(error)}`, { projectInfo }));
|
|
251
220
|
}
|
|
252
221
|
}
|
|
253
222
|
static async openProject(projectInfo, useHub = true, batchmode = false, waitForExit = true) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
223
|
+
console.debug(`Opening project at ${projectInfo.projectPath}`);
|
|
224
|
+
const args = ["-projectPath", projectInfo.projectPath];
|
|
225
|
+
if (waitForExit) {
|
|
226
|
+
args.push("-quit");
|
|
227
|
+
}
|
|
228
|
+
if (batchmode) {
|
|
229
|
+
args.push("-batchmode");
|
|
230
|
+
}
|
|
231
|
+
if (useHub) {
|
|
232
|
+
args.push("-useHub", "-hubIPC");
|
|
233
|
+
}
|
|
234
|
+
const editorInfo = { version: projectInfo.editorVersion };
|
|
235
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, { reject: false });
|
|
236
|
+
if (!result.success) {
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
const { stdout, stderr } = result.value;
|
|
240
|
+
const openingSuccessful = !stdout.includes("Failed to open project") && !stderr.includes("Failed to open project");
|
|
241
|
+
if (openingSuccessful) {
|
|
242
|
+
console.debug(`Successfully opened project`);
|
|
243
|
+
return ok(undefined);
|
|
244
|
+
}
|
|
245
|
+
return err(new UnityProjectError(`Failed to open project: ${stderr || stdout}`, {
|
|
246
|
+
projectInfo,
|
|
247
|
+
stderr,
|
|
248
|
+
stdout,
|
|
249
|
+
}));
|
|
282
250
|
}
|
|
283
251
|
}
|
|
284
252
|
export default UnityEditor;
|
package/dist/esm/unityHub.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { EditorArchitecture, ModuleId, UnityInstallations } from "./types/unity.js";
|
|
2
|
-
import { CommandOptions,
|
|
3
|
-
import { UnityHubInstallerEvent } from "./events/hubEventEmitter.
|
|
2
|
+
import { CommandOptions, CommandOutput } from "./utils/commandExecutor.js";
|
|
3
|
+
import { UnityHubInstallerEvent } from "./events/hubEventEmitter.js";
|
|
4
|
+
import { Result, UnityHubNotFoundError, UnityCommandError, UnityInstallationError, UnityProjectError, InvalidArgumentError } from "./errors/index.js";
|
|
4
5
|
declare class UnityHub {
|
|
5
6
|
private static CONFIG_PATHS;
|
|
6
7
|
static getUnityHubPath(): string;
|
|
7
8
|
static isUnityHubAvailable(): Promise<boolean>;
|
|
8
|
-
static execUnityHubCommand(args: string[], options?: CommandOptions): Promise<
|
|
9
|
-
static getInstallPath(): Promise<string
|
|
10
|
-
static setInstallPath(path: string): Promise<void
|
|
11
|
-
static getUnityInstallations(filter?: string): Promise<UnityInstallations
|
|
12
|
-
static addModule(editorVersion: string, modules: ModuleId[], childModules?: boolean): Promise<UnityHubInstallerEvent
|
|
13
|
-
static addEditor(version: string, modules?: ModuleId[], architecture?: EditorArchitecture): Promise<UnityHubInstallerEvent
|
|
14
|
-
static getProjects(): Promise<{
|
|
9
|
+
static execUnityHubCommand(args: string[], options?: CommandOptions): Promise<Result<CommandOutput, UnityHubNotFoundError | UnityCommandError>>;
|
|
10
|
+
static getInstallPath(): Promise<Result<string, UnityHubNotFoundError | UnityCommandError>>;
|
|
11
|
+
static setInstallPath(path: string): Promise<Result<void, UnityHubNotFoundError | UnityCommandError>>;
|
|
12
|
+
static getUnityInstallations(filter?: string): Promise<Result<UnityInstallations, InvalidArgumentError | UnityHubNotFoundError | UnityCommandError | UnityInstallationError>>;
|
|
13
|
+
static addModule(editorVersion: string, modules: ModuleId[], childModules?: boolean): Promise<Result<UnityHubInstallerEvent, InvalidArgumentError>>;
|
|
14
|
+
static addEditor(version: string, modules?: ModuleId[], architecture?: EditorArchitecture): Promise<Result<UnityHubInstallerEvent, UnityInstallationError>>;
|
|
15
|
+
static getProjects(): Promise<Result<{
|
|
15
16
|
name: string;
|
|
16
17
|
path: string;
|
|
17
18
|
version: string;
|
|
18
|
-
}[]
|
|
19
|
-
static getDefaultProjectsDirectory(): Promise<string | null
|
|
19
|
+
}[], UnityProjectError>>;
|
|
20
|
+
static getDefaultProjectsDirectory(): Promise<Result<string | null, UnityProjectError>>;
|
|
20
21
|
}
|
|
21
22
|
export default UnityHub;
|