@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.
Files changed (58) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/CHANGELOG.md +164 -146
  3. package/LICENSE +23 -23
  4. package/README.md +809 -347
  5. package/dist/cjs/errors/Result.js +76 -0
  6. package/dist/cjs/errors/UnityError.js +77 -0
  7. package/dist/cjs/errors/index.js +18 -0
  8. package/dist/cjs/events/hubEventEmitter.js +16 -16
  9. package/dist/cjs/events/hubEventParser.js +97 -27
  10. package/dist/cjs/events/patterns/implementations/bracketModulePattern.js +57 -0
  11. package/dist/cjs/events/patterns/implementations/errorPattern.js +99 -0
  12. package/dist/cjs/events/patterns/implementations/fallbackPattern.js +63 -0
  13. package/dist/cjs/events/patterns/implementations/index.js +9 -0
  14. package/dist/cjs/events/patterns/index.js +23 -0
  15. package/dist/cjs/events/patterns/patternRegistry.js +69 -0
  16. package/dist/cjs/events/patterns/statusNormalizer.js +280 -0
  17. package/dist/cjs/events/patterns/types.js +2 -0
  18. package/dist/cjs/index.js +7 -6
  19. package/dist/cjs/unityEditor.js +162 -194
  20. package/dist/cjs/unityHub.js +82 -78
  21. package/dist/cjs/utils/commandExecutor.js +8 -9
  22. package/dist/esm/errors/Result.d.ts +21 -0
  23. package/dist/esm/errors/Result.js +63 -0
  24. package/dist/esm/errors/UnityError.d.ts +36 -0
  25. package/dist/esm/errors/UnityError.js +64 -0
  26. package/dist/esm/errors/index.d.ts +2 -0
  27. package/dist/esm/errors/index.js +2 -0
  28. package/dist/esm/events/hubEventEmitter.d.ts +1 -1
  29. package/dist/esm/events/hubEventParser.d.ts +17 -3
  30. package/dist/esm/events/hubEventParser.js +97 -27
  31. package/dist/esm/events/patterns/implementations/bracketModulePattern.d.ts +11 -0
  32. package/dist/esm/events/patterns/implementations/bracketModulePattern.js +53 -0
  33. package/dist/esm/events/patterns/implementations/errorPattern.d.ts +22 -0
  34. package/dist/esm/events/patterns/implementations/errorPattern.js +95 -0
  35. package/dist/esm/events/patterns/implementations/fallbackPattern.d.ts +13 -0
  36. package/dist/esm/events/patterns/implementations/fallbackPattern.js +59 -0
  37. package/dist/esm/events/patterns/implementations/index.d.ts +3 -0
  38. package/dist/esm/events/patterns/implementations/index.js +3 -0
  39. package/dist/esm/events/patterns/index.d.ts +4 -0
  40. package/dist/esm/events/patterns/index.js +4 -0
  41. package/dist/esm/events/patterns/patternRegistry.d.ts +14 -0
  42. package/dist/esm/events/patterns/patternRegistry.js +65 -0
  43. package/dist/esm/events/patterns/statusNormalizer.d.ts +15 -0
  44. package/dist/esm/events/patterns/statusNormalizer.js +276 -0
  45. package/dist/esm/events/patterns/types.d.ts +30 -0
  46. package/dist/esm/events/patterns/types.js +1 -0
  47. package/dist/esm/index.d.ts +5 -4
  48. package/dist/esm/index.js +1 -0
  49. package/dist/esm/unityEditor.d.ts +11 -13
  50. package/dist/esm/unityEditor.js +175 -207
  51. package/dist/esm/unityHub.d.ts +12 -11
  52. package/dist/esm/unityHub.js +80 -76
  53. package/dist/esm/utils/commandExecutor.d.ts +4 -3
  54. package/dist/esm/utils/commandExecutor.js +8 -9
  55. package/package.json +70 -70
  56. package/sandbox/index.js +51 -0
  57. package/sandbox/node_modules/.package-lock.json +10495 -0
  58. package/sandbox/package.json +13 -0
package/dist/esm/index.js CHANGED
@@ -2,3 +2,4 @@ export { default as UnityHub } from "./unityHub.js";
2
2
  export { default as UnityEditor } from "./unityEditor.js";
3
3
  export { UnityHubInstallerEvent } from "./events/hubEventEmitter.js";
4
4
  export * from "./types/unity.js";
5
+ export * from "./errors/index.js";
@@ -1,19 +1,17 @@
1
1
  import { ProjectInfo, TestMode, UnityBuildTarget, UnityEditorInfo } from "./types/unity.js";
2
- import { CommandOptions, CommandResult } from "./utils/commandExecutor.js";
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<CommandResult>;
7
- static executeMethod(projectInfo: ProjectInfo, method: string, args?: string[], options?: CommandOptions): Promise<CommandResult>;
8
- static runTests(projectInfo: ProjectInfo, testPlatform?: TestMode | UnityBuildTarget, testCategory?: string): Promise<{
9
- success: boolean;
10
- output: string;
11
- }>;
12
- static activateLicense(projectInfo: ProjectInfo, serial: string, username: string, password: string): Promise<boolean>;
13
- static returnLicense(projectInfo: ProjectInfo): Promise<boolean>;
14
- static exportPackage(projectInfo: ProjectInfo, assetPaths: string[], outputPath: string): Promise<boolean>;
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;
@@ -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
- try {
40
- const unityPath = this.getUnityExecutablePath(editorInfo.version);
41
- if (!fs.existsSync(unityPath)) {
42
- return {
43
- success: false,
44
- stdout: "",
45
- stderr: `Unity executable not found at path: ${unityPath}`,
46
- exitCode: -1,
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
- try {
66
- console.debug(`Executing method ${method} in Unity Editor`);
67
- const unityPath = this.getUnityExecutablePath(projectInfo.editorVersion);
68
- const editorArgs = ["-projectPath", projectInfo.projectPath, "-executeMethod", method, ...args];
69
- const { stdout, stderr } = await this.execUnityEditorCommand({ version: projectInfo.editorVersion, path: unityPath }, editorArgs, options);
70
- if (stderr) {
71
- console.error(`Error executing method: ${stderr}`);
72
- return {
73
- success: false,
74
- stdout: "",
75
- stderr: stderr,
76
- exitCode: -1,
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
- try {
98
- console.debug(`Running ${testPlatform} tests for project ${testCategory ? ` in category ${testCategory}` : ""}`);
99
- const args = [
100
- "-batchmode",
101
- "-quit",
102
- "-projectPath",
103
- projectInfo.projectPath,
104
- "-runTests",
105
- "-testPlatform",
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
- if (testCategory) {
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
- try {
133
- console.debug(`Activating Unity license for version ${projectInfo.editorVersion}`);
134
- const args = ["-quit", "-serial", serial, "-username", username, "-password", password];
135
- const editorInfo = { version: projectInfo.editorVersion };
136
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
137
- reject: false,
138
- });
139
- const activationSuccessful = stdout.includes("successfully activated") ||
140
- (!stdout.includes("License activation failed") && !stderr.includes("License activation failed"));
141
- if (activationSuccessful) {
142
- console.debug(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
143
- return true;
144
- }
145
- else {
146
- console.error(`Failed to activate license: ${stderr || stdout}`);
147
- return false;
148
- }
149
- }
150
- catch (error) {
151
- console.error("Error activating license:", error);
152
- return false;
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
- try {
157
- console.debug(`Returning Unity license for version ${projectInfo.editorVersion}`);
158
- const args = ["-quit", "-returnlicense"];
159
- const editorInfo = { version: projectInfo.editorVersion };
160
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
161
- reject: false,
162
- });
163
- const returnSuccessful = stdout.includes("license return succeeded") ||
164
- (!stdout.includes("Failed to return license") && !stderr.includes("Failed to return license"));
165
- if (returnSuccessful) {
166
- console.debug(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
167
- return true;
168
- }
169
- else {
170
- console.error(`Failed to return license: ${stderr || stdout}`);
171
- return false;
172
- }
173
- }
174
- catch (error) {
175
- console.error("Error returning license:", error);
176
- return false;
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
- try {
181
- console.debug(`Exporting package from project`);
182
- const args = ["-projectPath", projectInfo.projectPath, "-exportPackage", ...assetPaths, outputPath, "-quit"];
183
- const editorInfo = { version: projectInfo.editorVersion };
184
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
185
- reject: false,
186
- });
187
- const exportSuccessful = !stdout.includes("Failed to export package") && !stderr.includes("Failed to export package");
188
- if (exportSuccessful) {
189
- console.debug(`Successfully exported package to ${outputPath}`);
190
- return true;
191
- }
192
- else {
193
- console.error(`Failed to export package: ${stderr || stdout}`);
194
- return false;
195
- }
196
- }
197
- catch (error) {
198
- console.error("Error exporting package:", error);
199
- return false;
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
- try {
204
- console.debug(`Importing package ${packagePath} to project`);
205
- const args = ["-projectPath", projectInfo.projectPath, "-importPackage", packagePath, "-quit"];
206
- const editorInfo = { version: projectInfo.editorVersion };
207
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
208
- reject: false,
209
- });
210
- const importSuccessful = !stdout.includes("Failed to import package") && !stderr.includes("Failed to import package");
211
- if (importSuccessful) {
212
- console.debug(`Successfully imported package ${packagePath}`);
213
- return true;
214
- }
215
- else {
216
- console.error(`Failed to import package: ${stderr || stdout}`);
217
- return false;
218
- }
219
- }
220
- catch (error) {
221
- console.error("Error importing package:", error);
222
- return false;
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 { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
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 true;
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 false;
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
- try {
255
- console.debug(`Opening project at ${projectInfo.projectPath}`);
256
- const args = ["-projectPath", projectInfo.projectPath];
257
- if (waitForExit) {
258
- args.push("-quit");
259
- }
260
- if (batchmode) {
261
- args.push("-batchmode");
262
- }
263
- if (useHub) {
264
- args.push(...["-useHub", "-hubIPC"]);
265
- }
266
- const editorInfo = { version: projectInfo.editorVersion };
267
- const options = { reject: false };
268
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, options);
269
- const openingSuccessful = !stdout.includes("Failed to open project") && !stderr.includes("Failed to open project");
270
- if (openingSuccessful) {
271
- console.debug(`Successfully opened project`);
272
- }
273
- else {
274
- console.error(`Failed to open project: ${stderr || stdout}`);
275
- }
276
- return openingSuccessful;
277
- }
278
- catch (error) {
279
- console.error("Error opening project:", error);
280
- return false;
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;
@@ -1,21 +1,22 @@
1
1
  import { EditorArchitecture, ModuleId, UnityInstallations } from "./types/unity.js";
2
- import { CommandOptions, CommandResult } from "./utils/commandExecutor.js";
3
- import { UnityHubInstallerEvent } from "./events/hubEventEmitter.ts";
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<CommandResult>;
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;