@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
@@ -9,6 +9,7 @@ const path_1 = __importDefault(require("path"));
9
9
  const unity_js_1 = require("./types/unity.js");
10
10
  const commandExecutor_js_1 = require("./utils/commandExecutor.js");
11
11
  const security_js_1 = require("./utils/security.js");
12
+ const index_js_1 = require("./errors/index.js");
12
13
  class UnityEditor {
13
14
  static UNITY_PATHS = {
14
15
  win32: {
@@ -41,195 +42,158 @@ class UnityEditor {
41
42
  }
42
43
  }
43
44
  static async execUnityEditorCommand(editorInfo, args, options = {}) {
44
- try {
45
- const unityPath = this.getUnityExecutablePath(editorInfo.version);
46
- if (!fs_extra_1.default.existsSync(unityPath)) {
47
- return {
48
- success: false,
49
- stdout: "",
50
- stderr: `Unity executable not found at path: ${unityPath}`,
51
- exitCode: -1,
52
- };
53
- }
54
- const editorArgs = [...args];
55
- const redactedArgs = (0, security_js_1.redactSensitiveArgs)(editorArgs);
56
- console.debug(`Executing Unity Editor command: ${unityPath} ${redactedArgs.join(" ")}`);
57
- return await (0, commandExecutor_js_1.executeCommand)(unityPath, editorArgs, options);
58
- }
59
- catch (error) {
60
- console.error("Error executing Unity Editor command:", error);
61
- return {
62
- success: false,
63
- stdout: "",
64
- stderr: String(error),
65
- exitCode: -1,
66
- };
45
+ const unityPath = this.getUnityExecutablePath(editorInfo.version);
46
+ if (!fs_extra_1.default.existsSync(unityPath)) {
47
+ return (0, index_js_1.err)(new index_js_1.UnityEditorNotFoundError(editorInfo.version, unityPath));
67
48
  }
49
+ const editorArgs = [...args];
50
+ const redactedArgs = (0, security_js_1.redactSensitiveArgs)(editorArgs);
51
+ console.debug(`Executing Unity Editor command: ${unityPath} ${redactedArgs.join(" ")}`);
52
+ return await (0, commandExecutor_js_1.executeCommand)(unityPath, editorArgs, options);
68
53
  }
69
54
  static async executeMethod(projectInfo, method, args = [], options = {}) {
70
- try {
71
- console.debug(`Executing method ${method} in Unity Editor`);
72
- const unityPath = this.getUnityExecutablePath(projectInfo.editorVersion);
73
- const editorArgs = ["-projectPath", projectInfo.projectPath, "-executeMethod", method, ...args];
74
- const { stdout, stderr } = await this.execUnityEditorCommand({ version: projectInfo.editorVersion, path: unityPath }, editorArgs, options);
75
- if (stderr) {
76
- console.error(`Error executing method: ${stderr}`);
77
- return {
78
- success: false,
79
- stdout: "",
80
- stderr: stderr,
81
- exitCode: -1,
82
- };
83
- }
84
- return {
85
- success: true,
86
- stdout: stdout,
87
- stderr: "",
88
- exitCode: 0,
89
- };
55
+ console.debug(`Executing method ${method} in Unity Editor`);
56
+ const unityPath = this.getUnityExecutablePath(projectInfo.editorVersion);
57
+ const editorArgs = ["-projectPath", projectInfo.projectPath, "-executeMethod", method, ...args];
58
+ const result = await this.execUnityEditorCommand({ version: projectInfo.editorVersion, path: unityPath }, editorArgs, options);
59
+ if (!result.success) {
60
+ console.error(`Error executing method: ${result.error.message}`);
61
+ return result;
90
62
  }
91
- catch (error) {
92
- console.error("Error executing method:", error);
93
- return {
94
- success: false,
95
- stdout: "",
96
- stderr: String(error),
97
- exitCode: -1,
98
- };
63
+ if (result.value.stderr) {
64
+ console.error(`Error executing method: ${result.value.stderr}`);
65
+ return (0, index_js_1.err)(new index_js_1.UnityCommandError(`Error executing method ${method}: ${result.value.stderr}`, result.value.stdout, result.value.stderr, result.value.exitCode, { method, projectInfo }));
99
66
  }
67
+ return result;
100
68
  }
101
69
  static async runTests(projectInfo, testPlatform = unity_js_1.TestMode.EditMode, testCategory) {
102
- try {
103
- console.debug(`Running ${testPlatform} tests for project ${testCategory ? ` in category ${testCategory}` : ""}`);
104
- const args = [
105
- "-batchmode",
106
- "-quit",
107
- "-projectPath",
108
- projectInfo.projectPath,
109
- "-runTests",
110
- "-testPlatform",
111
- testPlatform,
112
- ];
113
- if (testCategory) {
114
- args.push("-testCategory", testCategory);
115
- }
116
- const editorInfo = { version: projectInfo.editorVersion };
117
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
118
- reject: false,
119
- });
120
- const testsFailed = stdout.includes("Some tests failed") ||
121
- stdout.includes("Test run failed") ||
122
- stderr.includes("Test run failed");
123
- return {
124
- success: !testsFailed,
125
- output: stdout,
126
- };
70
+ console.debug(`Running ${testPlatform} tests for project${testCategory ? ` in category ${testCategory}` : ""}`);
71
+ const args = [
72
+ "-batchmode",
73
+ "-quit",
74
+ "-projectPath",
75
+ projectInfo.projectPath,
76
+ "-runTests",
77
+ "-testPlatform",
78
+ testPlatform,
79
+ ];
80
+ if (testCategory) {
81
+ args.push("-testCategory", testCategory);
127
82
  }
128
- catch (error) {
129
- console.error("Error running tests:", error);
130
- return {
131
- success: false,
132
- output: String(error),
133
- };
83
+ const editorInfo = { version: projectInfo.editorVersion };
84
+ const result = await this.execUnityEditorCommand(editorInfo, args, {
85
+ reject: false,
86
+ });
87
+ if (!result.success) {
88
+ return result;
89
+ }
90
+ const { stdout, stderr } = result.value;
91
+ const testsFailed = stdout.includes("Some tests failed") || stdout.includes("Test run failed") || stderr.includes("Test run failed");
92
+ if (testsFailed) {
93
+ return (0, index_js_1.err)(new index_js_1.UnityTestError("Some tests failed", stdout, {
94
+ projectInfo,
95
+ testPlatform,
96
+ testCategory,
97
+ }));
134
98
  }
99
+ return (0, index_js_1.ok)(stdout);
135
100
  }
136
101
  static async activateLicense(projectInfo, serial, username, password) {
137
- try {
138
- console.debug(`Activating Unity license for version ${projectInfo.editorVersion}`);
139
- const args = ["-quit", "-serial", serial, "-username", username, "-password", password];
140
- const editorInfo = { version: projectInfo.editorVersion };
141
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
142
- reject: false,
143
- });
144
- const activationSuccessful = stdout.includes("successfully activated") ||
145
- (!stdout.includes("License activation failed") && !stderr.includes("License activation failed"));
146
- if (activationSuccessful) {
147
- console.debug(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
148
- return true;
149
- }
150
- else {
151
- console.error(`Failed to activate license: ${stderr || stdout}`);
152
- return false;
153
- }
102
+ console.debug(`Activating Unity license for version ${projectInfo.editorVersion}`);
103
+ const args = ["-quit", "-serial", serial, "-username", username, "-password", password];
104
+ const editorInfo = { version: projectInfo.editorVersion };
105
+ const result = await this.execUnityEditorCommand(editorInfo, args, {
106
+ reject: false,
107
+ });
108
+ if (!result.success) {
109
+ return result;
154
110
  }
155
- catch (error) {
156
- console.error("Error activating license:", error);
157
- return false;
111
+ const { stdout, stderr } = result.value;
112
+ const activationSuccessful = stdout.includes("successfully activated") ||
113
+ (!stdout.includes("License activation failed") && !stderr.includes("License activation failed"));
114
+ if (activationSuccessful) {
115
+ console.debug(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
116
+ return (0, index_js_1.ok)(undefined);
158
117
  }
118
+ return (0, index_js_1.err)(new index_js_1.UnityLicenseError(`Failed to activate license: ${stderr || stdout}`, {
119
+ projectInfo,
120
+ stderr,
121
+ stdout,
122
+ }));
159
123
  }
160
124
  static async returnLicense(projectInfo) {
161
- try {
162
- console.debug(`Returning Unity license for version ${projectInfo.editorVersion}`);
163
- const args = ["-quit", "-returnlicense"];
164
- const editorInfo = { version: projectInfo.editorVersion };
165
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
166
- reject: false,
167
- });
168
- const returnSuccessful = stdout.includes("license return succeeded") ||
169
- (!stdout.includes("Failed to return license") && !stderr.includes("Failed to return license"));
170
- if (returnSuccessful) {
171
- console.debug(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
172
- return true;
173
- }
174
- else {
175
- console.error(`Failed to return license: ${stderr || stdout}`);
176
- return false;
177
- }
125
+ console.debug(`Returning Unity license for version ${projectInfo.editorVersion}`);
126
+ const args = ["-quit", "-returnlicense"];
127
+ const editorInfo = { version: projectInfo.editorVersion };
128
+ const result = await this.execUnityEditorCommand(editorInfo, args, {
129
+ reject: false,
130
+ });
131
+ if (!result.success) {
132
+ return result;
178
133
  }
179
- catch (error) {
180
- console.error("Error returning license:", error);
181
- return false;
134
+ const { stdout, stderr } = result.value;
135
+ const returnSuccessful = stdout.includes("license return succeeded") ||
136
+ (!stdout.includes("Failed to return license") && !stderr.includes("Failed to return license"));
137
+ if (returnSuccessful) {
138
+ console.debug(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
139
+ return (0, index_js_1.ok)(undefined);
182
140
  }
141
+ return (0, index_js_1.err)(new index_js_1.UnityLicenseError(`Failed to return license: ${stderr || stdout}`, {
142
+ projectInfo,
143
+ stderr,
144
+ stdout,
145
+ }));
183
146
  }
184
147
  static async exportPackage(projectInfo, assetPaths, outputPath) {
185
- try {
186
- console.debug(`Exporting package from project`);
187
- const args = ["-projectPath", projectInfo.projectPath, "-exportPackage", ...assetPaths, outputPath, "-quit"];
188
- const editorInfo = { version: projectInfo.editorVersion };
189
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
190
- reject: false,
191
- });
192
- const exportSuccessful = !stdout.includes("Failed to export package") && !stderr.includes("Failed to export package");
193
- if (exportSuccessful) {
194
- console.debug(`Successfully exported package to ${outputPath}`);
195
- return true;
196
- }
197
- else {
198
- console.error(`Failed to export package: ${stderr || stdout}`);
199
- return false;
200
- }
148
+ console.debug(`Exporting package from project`);
149
+ const args = ["-projectPath", projectInfo.projectPath, "-exportPackage", ...assetPaths, outputPath, "-quit"];
150
+ const editorInfo = { version: projectInfo.editorVersion };
151
+ const result = await this.execUnityEditorCommand(editorInfo, args, {
152
+ reject: false,
153
+ });
154
+ if (!result.success) {
155
+ return result;
201
156
  }
202
- catch (error) {
203
- console.error("Error exporting package:", error);
204
- return false;
157
+ const { stdout, stderr } = result.value;
158
+ const exportSuccessful = !stdout.includes("Failed to export package") && !stderr.includes("Failed to export package");
159
+ if (exportSuccessful) {
160
+ console.debug(`Successfully exported package to ${outputPath}`);
161
+ return (0, index_js_1.ok)(undefined);
205
162
  }
163
+ return (0, index_js_1.err)(new index_js_1.UnityPackageError(`Failed to export package: ${stderr || stdout}`, {
164
+ projectInfo,
165
+ assetPaths,
166
+ outputPath,
167
+ stderr,
168
+ stdout,
169
+ }));
206
170
  }
207
171
  static async importPackage(projectInfo, packagePath) {
208
- try {
209
- console.debug(`Importing package ${packagePath} to project`);
210
- const args = ["-projectPath", projectInfo.projectPath, "-importPackage", packagePath, "-quit"];
211
- const editorInfo = { version: projectInfo.editorVersion };
212
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
213
- reject: false,
214
- });
215
- const importSuccessful = !stdout.includes("Failed to import package") && !stderr.includes("Failed to import package");
216
- if (importSuccessful) {
217
- console.debug(`Successfully imported package ${packagePath}`);
218
- return true;
219
- }
220
- else {
221
- console.error(`Failed to import package: ${stderr || stdout}`);
222
- return false;
223
- }
172
+ console.debug(`Importing package ${packagePath} to project`);
173
+ const args = ["-projectPath", projectInfo.projectPath, "-importPackage", packagePath, "-quit"];
174
+ const editorInfo = { version: projectInfo.editorVersion };
175
+ const result = await this.execUnityEditorCommand(editorInfo, args, {
176
+ reject: false,
177
+ });
178
+ if (!result.success) {
179
+ return result;
224
180
  }
225
- catch (error) {
226
- console.error("Error importing package:", error);
227
- return false;
181
+ const { stdout, stderr } = result.value;
182
+ const importSuccessful = !stdout.includes("Failed to import package") && !stderr.includes("Failed to import package");
183
+ if (importSuccessful) {
184
+ console.debug(`Successfully imported package ${packagePath}`);
185
+ return (0, index_js_1.ok)(undefined);
228
186
  }
187
+ return (0, index_js_1.err)(new index_js_1.UnityPackageError(`Failed to import package: ${stderr || stdout}`, {
188
+ projectInfo,
189
+ packagePath,
190
+ stderr,
191
+ stdout,
192
+ }));
229
193
  }
230
194
  static async createProject(projectInfo, waitForExit = true) {
195
+ console.debug(`Creating new project at ${projectInfo.projectPath}`);
231
196
  try {
232
- console.debug(`Creating new project at ${projectInfo.projectPath}`);
233
197
  const parentDir = path_1.default.dirname(projectInfo.projectPath);
234
198
  await fs_extra_1.default.ensureDir(parentDir);
235
199
  const args = ["-createProject", projectInfo.projectPath];
@@ -237,53 +201,57 @@ class UnityEditor {
237
201
  args.push("-quit");
238
202
  }
239
203
  const editorInfo = { version: projectInfo.editorVersion };
240
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
204
+ const result = await this.execUnityEditorCommand(editorInfo, args, {
241
205
  reject: false,
242
206
  });
207
+ if (!result.success) {
208
+ return result;
209
+ }
210
+ const { stdout, stderr } = result.value;
243
211
  const creationSuccessful = !stdout.includes("Failed to create project") && !stderr.includes("Failed to create project");
244
212
  if (creationSuccessful) {
245
213
  console.debug(`Successfully created project at ${projectInfo.projectPath}`);
246
- return true;
247
- }
248
- else {
249
- console.error(`Failed to create project: ${stderr || stdout}`);
250
- return false;
214
+ return (0, index_js_1.ok)(undefined);
251
215
  }
216
+ return (0, index_js_1.err)(new index_js_1.UnityProjectError(`Failed to create project: ${stderr || stdout}`, {
217
+ projectInfo,
218
+ stderr,
219
+ stdout,
220
+ }));
252
221
  }
253
222
  catch (error) {
254
223
  console.error("Error creating project:", error);
255
- return false;
224
+ return (0, index_js_1.err)(new index_js_1.UnityProjectError(`Error creating project: ${String(error)}`, { projectInfo }));
256
225
  }
257
226
  }
258
227
  static async openProject(projectInfo, useHub = true, batchmode = false, waitForExit = true) {
259
- try {
260
- console.debug(`Opening project at ${projectInfo.projectPath}`);
261
- const args = ["-projectPath", projectInfo.projectPath];
262
- if (waitForExit) {
263
- args.push("-quit");
264
- }
265
- if (batchmode) {
266
- args.push("-batchmode");
267
- }
268
- if (useHub) {
269
- args.push(...["-useHub", "-hubIPC"]);
270
- }
271
- const editorInfo = { version: projectInfo.editorVersion };
272
- const options = { reject: false };
273
- const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, options);
274
- const openingSuccessful = !stdout.includes("Failed to open project") && !stderr.includes("Failed to open project");
275
- if (openingSuccessful) {
276
- console.debug(`Successfully opened project`);
277
- }
278
- else {
279
- console.error(`Failed to open project: ${stderr || stdout}`);
280
- }
281
- return openingSuccessful;
228
+ console.debug(`Opening project at ${projectInfo.projectPath}`);
229
+ const args = ["-projectPath", projectInfo.projectPath];
230
+ if (waitForExit) {
231
+ args.push("-quit");
282
232
  }
283
- catch (error) {
284
- console.error("Error opening project:", error);
285
- return false;
233
+ if (batchmode) {
234
+ args.push("-batchmode");
235
+ }
236
+ if (useHub) {
237
+ args.push("-useHub", "-hubIPC");
238
+ }
239
+ const editorInfo = { version: projectInfo.editorVersion };
240
+ const result = await this.execUnityEditorCommand(editorInfo, args, { reject: false });
241
+ if (!result.success) {
242
+ return result;
243
+ }
244
+ const { stdout, stderr } = result.value;
245
+ const openingSuccessful = !stdout.includes("Failed to open project") && !stderr.includes("Failed to open project");
246
+ if (openingSuccessful) {
247
+ console.debug(`Successfully opened project`);
248
+ return (0, index_js_1.ok)(undefined);
286
249
  }
250
+ return (0, index_js_1.err)(new index_js_1.UnityProjectError(`Failed to open project: ${stderr || stdout}`, {
251
+ projectInfo,
252
+ stderr,
253
+ stdout,
254
+ }));
287
255
  }
288
256
  }
289
257
  exports.default = UnityEditor;