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