@notask/unity-cli-tools 1.2.0-rc.1 → 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 -164
- 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 +8 -11
- package/dist/cjs/unityEditor.js +182 -230
- package/dist/cjs/unityHub.js +110 -85
- 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 -6
- package/dist/esm/index.js +1 -2
- package/dist/esm/unityEditor.d.ts +11 -15
- package/dist/esm/unityEditor.js +196 -244
- package/dist/esm/unityHub.d.ts +13 -11
- package/dist/esm/unityHub.js +108 -83
- 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/cjs/configs/unityConfig.js +0 -74
- package/dist/cjs/unityTemplates.js +0 -29
- package/dist/esm/configs/unityConfig.d.ts +0 -25
- package/dist/esm/configs/unityConfig.js +0 -68
- package/dist/esm/unityTemplates.d.ts +0 -10
- package/dist/esm/unityTemplates.js +0 -24
package/dist/esm/unityEditor.js
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
+
import os from "os";
|
|
1
2
|
import fs from "fs-extra";
|
|
2
3
|
import path from "path";
|
|
3
4
|
import { TestMode } from "./types/unity.js";
|
|
4
5
|
import { executeCommand } from "./utils/commandExecutor.js";
|
|
5
6
|
import { redactSensitiveArgs } from "./utils/security.js";
|
|
6
|
-
import {
|
|
7
|
+
import { ok, err, UnityEditorNotFoundError, UnityCommandError, UnityTestError, UnityLicenseError, UnityPackageError, UnityProjectError, } from "./errors/index.js";
|
|
7
8
|
class UnityEditor {
|
|
8
|
-
static
|
|
9
|
+
static UNITY_PATHS = {
|
|
10
|
+
win32: {
|
|
11
|
+
base: "C:/Program Files/Unity/Hub/Editor",
|
|
12
|
+
executable: "Editor/Unity.exe",
|
|
13
|
+
},
|
|
14
|
+
darwin: {
|
|
15
|
+
base: "/Applications/Unity/Hub/Editor",
|
|
16
|
+
executable: "Unity.app/Contents/MacOS/Unity",
|
|
17
|
+
},
|
|
18
|
+
linux: {
|
|
19
|
+
base: "/opt/unity/editor",
|
|
20
|
+
executable: "Editor/Unity",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
9
23
|
static getUnityExecutablePath(version) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static getUnityTemplatesPath(version) {
|
|
14
|
-
const unityPath = path.join(this.unityConfig.base, version, this.unityConfig.projectTemplates);
|
|
24
|
+
const platform = os.platform();
|
|
25
|
+
const unityConfig = UnityEditor.UNITY_PATHS[platform];
|
|
26
|
+
const unityPath = path.join(unityConfig.base, version, unityConfig.executable);
|
|
15
27
|
return unityPath;
|
|
16
28
|
}
|
|
17
29
|
static async isUnityVersionInstalled(version) {
|
|
@@ -25,276 +37,216 @@ class UnityEditor {
|
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
39
|
static async execUnityEditorCommand(editorInfo, args, options = {}) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const editorArgs = [...args];
|
|
39
|
-
const redactedArgs = redactSensitiveArgs(editorArgs);
|
|
40
|
-
console.debug(`Executing Unity Editor command: ${unityPath} ${redactedArgs.join(" ")}`);
|
|
41
|
-
return await executeCommand(unityPath, editorArgs, options);
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
console.error("Error executing Unity Editor command:", error);
|
|
45
|
-
return {
|
|
46
|
-
success: false,
|
|
47
|
-
stdout: "",
|
|
48
|
-
stderr: String(error),
|
|
49
|
-
exitCode: -1,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
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);
|
|
52
48
|
}
|
|
53
49
|
static async executeMethod(projectInfo, method, args = [], options = {}) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
success: true,
|
|
70
|
-
stdout: stdout,
|
|
71
|
-
stderr: "",
|
|
72
|
-
exitCode: 0,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
console.error("Error executing method:", error);
|
|
77
|
-
return {
|
|
78
|
-
success: false,
|
|
79
|
-
stdout: "",
|
|
80
|
-
stderr: String(error),
|
|
81
|
-
exitCode: -1,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
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;
|
|
84
63
|
}
|
|
85
64
|
static async runTests(projectInfo, testPlatform = TestMode.EditMode, testCategory) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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,
|
|
95
90
|
testPlatform,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
args.push("-testCategory", testCategory);
|
|
99
|
-
}
|
|
100
|
-
const editorInfo = { version: projectInfo.editorVersion };
|
|
101
|
-
const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
|
|
102
|
-
reject: false,
|
|
103
|
-
});
|
|
104
|
-
const testsFailed = stdout.includes("Some tests failed") ||
|
|
105
|
-
stdout.includes("Test run failed") ||
|
|
106
|
-
stderr.includes("Test run failed");
|
|
107
|
-
return {
|
|
108
|
-
success: !testsFailed,
|
|
109
|
-
output: stdout,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
console.error("Error running tests:", error);
|
|
114
|
-
return {
|
|
115
|
-
success: false,
|
|
116
|
-
output: String(error),
|
|
117
|
-
};
|
|
91
|
+
testCategory,
|
|
92
|
+
}));
|
|
118
93
|
}
|
|
94
|
+
return ok(stdout);
|
|
119
95
|
}
|
|
120
96
|
static async activateLicense(projectInfo, serial, username, password) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
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
|
+
}));
|
|
143
118
|
}
|
|
144
119
|
static async returnLicense(projectInfo) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
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
|
+
}));
|
|
167
141
|
}
|
|
168
142
|
static async exportPackage(projectInfo, assetPaths, outputPath) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
+
}));
|
|
190
165
|
}
|
|
191
166
|
static async importPackage(projectInfo, packagePath) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
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
|
+
}));
|
|
213
188
|
}
|
|
214
|
-
static async createProject(projectInfo,
|
|
189
|
+
static async createProject(projectInfo, waitForExit = true) {
|
|
190
|
+
console.debug(`Creating new project at ${projectInfo.projectPath}`);
|
|
215
191
|
try {
|
|
216
|
-
console.debug(`Creating new project at ${projectInfo.projectPath}`);
|
|
217
192
|
const parentDir = path.dirname(projectInfo.projectPath);
|
|
218
193
|
await fs.ensureDir(parentDir);
|
|
219
194
|
const args = ["-createProject", projectInfo.projectPath];
|
|
220
|
-
if (
|
|
221
|
-
args.push("-useHub", "-hubIPC");
|
|
222
|
-
if (quit)
|
|
195
|
+
if (waitForExit) {
|
|
223
196
|
args.push("-quit");
|
|
197
|
+
}
|
|
224
198
|
const editorInfo = { version: projectInfo.editorVersion };
|
|
225
|
-
const
|
|
199
|
+
const result = await this.execUnityEditorCommand(editorInfo, args, {
|
|
226
200
|
reject: false,
|
|
227
201
|
});
|
|
202
|
+
if (!result.success) {
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
const { stdout, stderr } = result.value;
|
|
228
206
|
const creationSuccessful = !stdout.includes("Failed to create project") && !stderr.includes("Failed to create project");
|
|
229
207
|
if (creationSuccessful) {
|
|
230
208
|
console.debug(`Successfully created project at ${projectInfo.projectPath}`);
|
|
231
|
-
return
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
console.error(`Failed to create project: ${stderr || stdout}`);
|
|
235
|
-
return false;
|
|
209
|
+
return ok(undefined);
|
|
236
210
|
}
|
|
211
|
+
return err(new UnityProjectError(`Failed to create project: ${stderr || stdout}`, {
|
|
212
|
+
projectInfo,
|
|
213
|
+
stderr,
|
|
214
|
+
stdout,
|
|
215
|
+
}));
|
|
237
216
|
}
|
|
238
217
|
catch (error) {
|
|
239
218
|
console.error("Error creating project:", error);
|
|
240
|
-
return
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
static async createProjectFromTemplate(projectInfo, templatePath, quit = false, useHub = true) {
|
|
244
|
-
try {
|
|
245
|
-
console.debug(`Creating new project from template at ${projectInfo.projectPath}`);
|
|
246
|
-
const parentDir = path.dirname(projectInfo.projectPath);
|
|
247
|
-
await fs.ensureDir(parentDir);
|
|
248
|
-
const args = ["-createProject", projectInfo.projectPath, "-cloneFromTemplate", templatePath];
|
|
249
|
-
if (quit)
|
|
250
|
-
args.push("-quit");
|
|
251
|
-
if (useHub)
|
|
252
|
-
args.push("-useHub", "-hubIPC");
|
|
253
|
-
const editorInfo = { version: projectInfo.editorVersion };
|
|
254
|
-
const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, {
|
|
255
|
-
reject: false,
|
|
256
|
-
});
|
|
257
|
-
const creationSuccessful = !stdout.includes("Failed to create project") && !stderr.includes("Failed to create project");
|
|
258
|
-
if (creationSuccessful) {
|
|
259
|
-
console.debug(`Successfully created project from template at ${projectInfo.projectPath}`);
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
console.error(`Failed to create project from template: ${stderr || stdout}`);
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
console.error("Error creating project from template:", error);
|
|
269
|
-
return false;
|
|
219
|
+
return err(new UnityProjectError(`Error creating project: ${String(error)}`, { projectInfo }));
|
|
270
220
|
}
|
|
271
221
|
}
|
|
272
222
|
static async openProject(projectInfo, useHub = true, batchmode = false, waitForExit = true) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
+
}));
|
|
298
250
|
}
|
|
299
251
|
}
|
|
300
252
|
export default UnityEditor;
|
package/dist/esm/unityHub.d.ts
CHANGED
|
@@ -1,20 +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 {
|
|
6
|
+
private static CONFIG_PATHS;
|
|
5
7
|
static getUnityHubPath(): string;
|
|
6
8
|
static isUnityHubAvailable(): Promise<boolean>;
|
|
7
|
-
static execUnityHubCommand(args: string[], options?: CommandOptions): Promise<
|
|
8
|
-
static getInstallPath(): Promise<string
|
|
9
|
-
static setInstallPath(path: string): Promise<void
|
|
10
|
-
static getUnityInstallations(filter?: string): Promise<UnityInstallations
|
|
11
|
-
static addModule(editorVersion: string, modules: ModuleId[], childModules?: boolean): Promise<UnityHubInstallerEvent
|
|
12
|
-
static addEditor(version: string, modules?: ModuleId[], architecture?: EditorArchitecture): Promise<UnityHubInstallerEvent
|
|
13
|
-
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<{
|
|
14
16
|
name: string;
|
|
15
17
|
path: string;
|
|
16
18
|
version: string;
|
|
17
|
-
}[]
|
|
18
|
-
static getDefaultProjectsDirectory(): Promise<string | null
|
|
19
|
+
}[], UnityProjectError>>;
|
|
20
|
+
static getDefaultProjectsDirectory(): Promise<Result<string | null, UnityProjectError>>;
|
|
19
21
|
}
|
|
20
22
|
export default UnityHub;
|