@notask/unity-cli-tools 1.0.6-rc.2 → 1.0.7-rc.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [1.0.7-rc.1](https://github.com/NoTaskStudios/unity-cli-tools/compare/1.0.6...1.0.7-rc.1) (2025-05-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Editor:** hotfix import error from UnityEditor security ([f7cf9b8](https://github.com/NoTaskStudios/unity-cli-tools/commit/f7cf9b886e63df9e7ad2c10ac3351f42a73b9c81))
7
+ * extended CommandOptions with std events ([8198f9f](https://github.com/NoTaskStudios/unity-cli-tools/commit/8198f9f5fec330a389405194412310d22b3ab785))
8
+ * **Hub:** simple stream output feedback ([ba21b46](https://github.com/NoTaskStudios/unity-cli-tools/commit/ba21b462f3eee168909ae54003936e4c551bcaed)), closes [#13](https://github.com/NoTaskStudios/unity-cli-tools/issues/13)
9
+ * subprocess send streams stdout and stderr ([4348611](https://github.com/NoTaskStudios/unity-cli-tools/commit/4348611f96da5fbbed39895ac587a5e6caad1d03))
10
+
11
+ ## [1.0.6](https://github.com/NoTaskStudios/unity-cli-tools/compare/1.0.5...1.0.6) (2025-04-30)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * **Hub:** adjust in default params values ([ca12050](https://github.com/NoTaskStudios/unity-cli-tools/commit/ca120505433e4c6c01c54e1917de564a4883416b))
17
+ * **Hub:** auto detect system arch when arg no passed ([1e6ff27](https://github.com/NoTaskStudios/unity-cli-tools/commit/1e6ff27ca37a70014823693489447d8cd2ada9b9))
18
+ * **Hub:** Remove some class members ([78c37e2](https://github.com/NoTaskStudios/unity-cli-tools/commit/78c37e2b83197e6d8445bbdeeb23ff4c457eedd0))
19
+
1
20
  ## [1.0.6-rc.2](https://github.com/NoTaskStudios/unity-cli-tools/compare/1.0.6-rc.1...1.0.6-rc.2) (2025-04-30)
2
21
 
3
22
 
@@ -8,7 +8,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  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
- const security_js_1 = require("utils/security.js");
11
+ const security_js_1 = require("./utils/security.js");
12
12
  class UnityEditor {
13
13
  static UNITY_PATHS = {
14
14
  win32: {
@@ -74,13 +74,28 @@ class UnityEditor {
74
74
  const { stdout, stderr } = await this.execUnityEditorCommand({ version: projectInfo.editorVersion, path: unityPath }, editorArgs, options);
75
75
  if (stderr) {
76
76
  console.error(`Error executing method: ${stderr}`);
77
- return null;
77
+ return {
78
+ success: false,
79
+ stdout: "",
80
+ stderr: stderr,
81
+ exitCode: -1,
82
+ };
78
83
  }
79
- return stdout;
84
+ return {
85
+ success: true,
86
+ stdout: stdout,
87
+ stderr: "",
88
+ exitCode: 0,
89
+ };
80
90
  }
81
91
  catch (error) {
82
92
  console.error("Error executing method:", error);
83
- return null;
93
+ return {
94
+ success: false,
95
+ stdout: "",
96
+ stderr: String(error),
97
+ exitCode: -1,
98
+ };
84
99
  }
85
100
  }
86
101
  static async runTests(projectInfo, testPlatform = unity_js_1.TestMode.EditMode, testCategory) {
@@ -129,7 +144,7 @@ class UnityEditor {
129
144
  const activationSuccessful = stdout.includes("successfully activated") ||
130
145
  (!stdout.includes("License activation failed") && !stderr.includes("License activation failed"));
131
146
  if (activationSuccessful) {
132
- console.info(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
147
+ console.debug(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
133
148
  return true;
134
149
  }
135
150
  else {
@@ -153,7 +168,7 @@ class UnityEditor {
153
168
  const returnSuccessful = stdout.includes("license return succeeded") ||
154
169
  (!stdout.includes("Failed to return license") && !stderr.includes("Failed to return license"));
155
170
  if (returnSuccessful) {
156
- console.info(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
171
+ console.debug(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
157
172
  return true;
158
173
  }
159
174
  else {
@@ -176,7 +191,7 @@ class UnityEditor {
176
191
  });
177
192
  const exportSuccessful = !stdout.includes("Failed to export package") && !stderr.includes("Failed to export package");
178
193
  if (exportSuccessful) {
179
- console.info(`Successfully exported package to ${outputPath}`);
194
+ console.debug(`Successfully exported package to ${outputPath}`);
180
195
  return true;
181
196
  }
182
197
  else {
@@ -199,7 +214,7 @@ class UnityEditor {
199
214
  });
200
215
  const importSuccessful = !stdout.includes("Failed to import package") && !stderr.includes("Failed to import package");
201
216
  if (importSuccessful) {
202
- console.info(`Successfully imported package ${packagePath}`);
217
+ console.debug(`Successfully imported package ${packagePath}`);
203
218
  return true;
204
219
  }
205
220
  else {
@@ -227,7 +242,7 @@ class UnityEditor {
227
242
  });
228
243
  const creationSuccessful = !stdout.includes("Failed to create project") && !stderr.includes("Failed to create project");
229
244
  if (creationSuccessful) {
230
- console.info(`Successfully created project at ${projectInfo.projectPath}`);
245
+ console.debug(`Successfully created project at ${projectInfo.projectPath}`);
231
246
  return true;
232
247
  }
233
248
  else {
@@ -258,13 +273,12 @@ class UnityEditor {
258
273
  const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, options);
259
274
  const openingSuccessful = !stdout.includes("Failed to open project") && !stderr.includes("Failed to open project");
260
275
  if (openingSuccessful) {
261
- console.info(`Successfully opened project`);
262
- return true;
276
+ console.debug(`Successfully opened project`);
263
277
  }
264
278
  else {
265
279
  console.error(`Failed to open project: ${stderr || stdout}`);
266
- return false;
267
280
  }
281
+ return openingSuccessful;
268
282
  }
269
283
  catch (error) {
270
284
  console.error("Error opening project:", error);
@@ -44,7 +44,7 @@ class UnityHub {
44
44
  }
45
45
  static async isUnityHubAvailable() {
46
46
  try {
47
- return !this.hubPath || !fs_extra_1.default.existsSync(this.hubPath);
47
+ return !!this.hubPath && fs_extra_1.default.existsSync(this.hubPath);
48
48
  }
49
49
  catch (error) {
50
50
  console.error("Error checking Unity Hub availability:", error);
@@ -130,10 +130,15 @@ class UnityHub {
130
130
  else {
131
131
  throw new Error("No module IDs provided.");
132
132
  }
133
- const { stdout, stderr } = await this.execUnityHubCommand(args, {
133
+ const { stderr } = await this.execUnityHubCommand(args, {
134
134
  reject: false,
135
+ onStderr: (data) => {
136
+ console.warn(`Unity Hub stderr: ${data}`);
137
+ },
138
+ onStdout: (data) => {
139
+ console.debug(`Unity Hub stdout: ${data}`);
140
+ },
135
141
  });
136
- console.debug(`Add module command output: ${stdout}`);
137
142
  if (stderr) {
138
143
  console.warn(`Add module command warning/error: ${stderr}`);
139
144
  }
@@ -143,9 +148,7 @@ class UnityHub {
143
148
  throw error;
144
149
  }
145
150
  }
146
- static async addEditor(version, modules = [], architecture = process.platform === "darwin"
147
- ? unity_js_1.EditorArchitecture.arm64
148
- : unity_js_1.EditorArchitecture.x86_64) {
151
+ static async addEditor(version, modules = [], architecture) {
149
152
  try {
150
153
  const data = await (0, unity_changeset_1.getUnityChangeset)(version);
151
154
  const args = ["install", "-v", version];
@@ -154,9 +157,20 @@ class UnityHub {
154
157
  args.push("--module");
155
158
  args.push(modules.join(" "));
156
159
  }
160
+ if (!architecture) {
161
+ const arch = os_1.default.arch() || process.arch;
162
+ const defaultArchitecture = arch === "arm64" || arch === "arm" ? unity_js_1.EditorArchitecture.arm64 : unity_js_1.EditorArchitecture.x86_64;
163
+ architecture = defaultArchitecture;
164
+ }
157
165
  args.push("--architecture", architecture);
158
166
  const { stdout, stderr } = await this.execUnityHubCommand(args, {
159
167
  reject: false,
168
+ onStderr: (data) => {
169
+ console.warn(`Unity Hub stderr: ${data}`);
170
+ },
171
+ onStdout: (data) => {
172
+ console.debug(`Unity Hub stdout: ${data}`);
173
+ },
160
174
  });
161
175
  if (stderr) {
162
176
  throw new Error(`Error installing Unity ${version}: ${stderr}`);
@@ -4,13 +4,41 @@ exports.executeCommand = executeCommand;
4
4
  const execa_1 = require("execa");
5
5
  async function executeCommand(executable, args, options = {}) {
6
6
  try {
7
+ const streamOutput = options.onStdout || options.onStderr;
7
8
  const subprocess = (0, execa_1.execa)(executable, args, {
8
9
  reject: options.reject ?? false,
9
10
  timeout: options.timeout,
10
11
  env: options.env,
11
12
  cwd: options.cwd,
12
13
  encoding: "utf8",
14
+ buffer: !streamOutput,
13
15
  });
16
+ if (streamOutput) {
17
+ if (subprocess.stdout) {
18
+ subprocess.stdout.on("data", (data) => {
19
+ const lines = data.toString().split(/\r?\n/);
20
+ for (const line of lines) {
21
+ if (line.trim()) {
22
+ if (options.onStdout) {
23
+ options.onStdout(line);
24
+ }
25
+ }
26
+ }
27
+ });
28
+ }
29
+ if (subprocess.stderr) {
30
+ subprocess.stderr.on("data", (data) => {
31
+ const lines = data.toString().split(/\r?\n/);
32
+ for (const line of lines) {
33
+ if (line.trim()) {
34
+ if (options.onStderr) {
35
+ options.onStderr(line);
36
+ }
37
+ }
38
+ }
39
+ });
40
+ }
41
+ }
14
42
  const { stdout, stderr, exitCode } = await subprocess;
15
43
  return {
16
44
  success: true,
@@ -4,7 +4,7 @@ declare class UnityEditor {
4
4
  static getUnityExecutablePath(version: string): string;
5
5
  static isUnityVersionInstalled(version: string): Promise<boolean>;
6
6
  static execUnityEditorCommand(editorInfo: UnityEditorInfo, args: string[], options?: CommandOptions): Promise<CommandResult>;
7
- static executeMethod(projectInfo: ProjectInfo, method: string, args?: string[], options?: CommandOptions): Promise<any>;
7
+ static executeMethod(projectInfo: ProjectInfo, method: string, args?: string[], options?: CommandOptions): Promise<CommandResult>;
8
8
  static runTests(projectInfo: ProjectInfo, testPlatform?: TestMode | UnityBuildTarget, testCategory?: string): Promise<{
9
9
  success: boolean;
10
10
  output: string;
@@ -3,7 +3,7 @@ import fs from "fs-extra";
3
3
  import path from "path";
4
4
  import { TestMode } from "./types/unity.js";
5
5
  import { executeCommand } from "./utils/commandExecutor.js";
6
- import { redactSensitiveArgs } from "utils/security.js";
6
+ import { redactSensitiveArgs } from "./utils/security.js";
7
7
  class UnityEditor {
8
8
  static UNITY_PATHS = {
9
9
  win32: {
@@ -69,13 +69,28 @@ class UnityEditor {
69
69
  const { stdout, stderr } = await this.execUnityEditorCommand({ version: projectInfo.editorVersion, path: unityPath }, editorArgs, options);
70
70
  if (stderr) {
71
71
  console.error(`Error executing method: ${stderr}`);
72
- return null;
72
+ return {
73
+ success: false,
74
+ stdout: "",
75
+ stderr: stderr,
76
+ exitCode: -1,
77
+ };
73
78
  }
74
- return stdout;
79
+ return {
80
+ success: true,
81
+ stdout: stdout,
82
+ stderr: "",
83
+ exitCode: 0,
84
+ };
75
85
  }
76
86
  catch (error) {
77
87
  console.error("Error executing method:", error);
78
- return null;
88
+ return {
89
+ success: false,
90
+ stdout: "",
91
+ stderr: String(error),
92
+ exitCode: -1,
93
+ };
79
94
  }
80
95
  }
81
96
  static async runTests(projectInfo, testPlatform = TestMode.EditMode, testCategory) {
@@ -124,7 +139,7 @@ class UnityEditor {
124
139
  const activationSuccessful = stdout.includes("successfully activated") ||
125
140
  (!stdout.includes("License activation failed") && !stderr.includes("License activation failed"));
126
141
  if (activationSuccessful) {
127
- console.info(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
142
+ console.debug(`Successfully activated license for Unity ${projectInfo.editorVersion}`);
128
143
  return true;
129
144
  }
130
145
  else {
@@ -148,7 +163,7 @@ class UnityEditor {
148
163
  const returnSuccessful = stdout.includes("license return succeeded") ||
149
164
  (!stdout.includes("Failed to return license") && !stderr.includes("Failed to return license"));
150
165
  if (returnSuccessful) {
151
- console.info(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
166
+ console.debug(`Successfully returned license for Unity ${projectInfo.editorVersion}`);
152
167
  return true;
153
168
  }
154
169
  else {
@@ -171,7 +186,7 @@ class UnityEditor {
171
186
  });
172
187
  const exportSuccessful = !stdout.includes("Failed to export package") && !stderr.includes("Failed to export package");
173
188
  if (exportSuccessful) {
174
- console.info(`Successfully exported package to ${outputPath}`);
189
+ console.debug(`Successfully exported package to ${outputPath}`);
175
190
  return true;
176
191
  }
177
192
  else {
@@ -194,7 +209,7 @@ class UnityEditor {
194
209
  });
195
210
  const importSuccessful = !stdout.includes("Failed to import package") && !stderr.includes("Failed to import package");
196
211
  if (importSuccessful) {
197
- console.info(`Successfully imported package ${packagePath}`);
212
+ console.debug(`Successfully imported package ${packagePath}`);
198
213
  return true;
199
214
  }
200
215
  else {
@@ -222,7 +237,7 @@ class UnityEditor {
222
237
  });
223
238
  const creationSuccessful = !stdout.includes("Failed to create project") && !stderr.includes("Failed to create project");
224
239
  if (creationSuccessful) {
225
- console.info(`Successfully created project at ${projectInfo.projectPath}`);
240
+ console.debug(`Successfully created project at ${projectInfo.projectPath}`);
226
241
  return true;
227
242
  }
228
243
  else {
@@ -253,13 +268,12 @@ class UnityEditor {
253
268
  const { stdout, stderr } = await this.execUnityEditorCommand(editorInfo, args, options);
254
269
  const openingSuccessful = !stdout.includes("Failed to open project") && !stderr.includes("Failed to open project");
255
270
  if (openingSuccessful) {
256
- console.info(`Successfully opened project`);
257
- return true;
271
+ console.debug(`Successfully opened project`);
258
272
  }
259
273
  else {
260
274
  console.error(`Failed to open project: ${stderr || stdout}`);
261
- return false;
262
275
  }
276
+ return openingSuccessful;
263
277
  }
264
278
  catch (error) {
265
279
  console.error("Error opening project:", error);
@@ -39,7 +39,7 @@ class UnityHub {
39
39
  }
40
40
  static async isUnityHubAvailable() {
41
41
  try {
42
- return !this.hubPath || !fs.existsSync(this.hubPath);
42
+ return !!this.hubPath && fs.existsSync(this.hubPath);
43
43
  }
44
44
  catch (error) {
45
45
  console.error("Error checking Unity Hub availability:", error);
@@ -125,10 +125,15 @@ class UnityHub {
125
125
  else {
126
126
  throw new Error("No module IDs provided.");
127
127
  }
128
- const { stdout, stderr } = await this.execUnityHubCommand(args, {
128
+ const { stderr } = await this.execUnityHubCommand(args, {
129
129
  reject: false,
130
+ onStderr: (data) => {
131
+ console.warn(`Unity Hub stderr: ${data}`);
132
+ },
133
+ onStdout: (data) => {
134
+ console.debug(`Unity Hub stdout: ${data}`);
135
+ },
130
136
  });
131
- console.debug(`Add module command output: ${stdout}`);
132
137
  if (stderr) {
133
138
  console.warn(`Add module command warning/error: ${stderr}`);
134
139
  }
@@ -138,9 +143,7 @@ class UnityHub {
138
143
  throw error;
139
144
  }
140
145
  }
141
- static async addEditor(version, modules = [], architecture = process.platform === "darwin"
142
- ? EditorArchitecture.arm64
143
- : EditorArchitecture.x86_64) {
146
+ static async addEditor(version, modules = [], architecture) {
144
147
  try {
145
148
  const data = await getUnityChangeset(version);
146
149
  const args = ["install", "-v", version];
@@ -149,9 +152,20 @@ class UnityHub {
149
152
  args.push("--module");
150
153
  args.push(modules.join(" "));
151
154
  }
155
+ if (!architecture) {
156
+ const arch = os.arch() || process.arch;
157
+ const defaultArchitecture = arch === "arm64" || arch === "arm" ? EditorArchitecture.arm64 : EditorArchitecture.x86_64;
158
+ architecture = defaultArchitecture;
159
+ }
152
160
  args.push("--architecture", architecture);
153
161
  const { stdout, stderr } = await this.execUnityHubCommand(args, {
154
162
  reject: false,
163
+ onStderr: (data) => {
164
+ console.warn(`Unity Hub stderr: ${data}`);
165
+ },
166
+ onStdout: (data) => {
167
+ console.debug(`Unity Hub stdout: ${data}`);
168
+ },
155
169
  });
156
170
  if (stderr) {
157
171
  throw new Error(`Error installing Unity ${version}: ${stderr}`);
@@ -2,6 +2,8 @@ import { Options } from "execa";
2
2
  export interface CommandOptions extends Options {
3
3
  reject?: boolean;
4
4
  timeout?: number;
5
+ onStdout?: (data: string) => void;
6
+ onStderr?: (data: string) => void;
5
7
  env?: Record<string, string>;
6
8
  cwd?: string;
7
9
  }
@@ -1,13 +1,41 @@
1
1
  import { execa } from "execa";
2
2
  export async function executeCommand(executable, args, options = {}) {
3
3
  try {
4
+ const streamOutput = options.onStdout || options.onStderr;
4
5
  const subprocess = execa(executable, args, {
5
6
  reject: options.reject ?? false,
6
7
  timeout: options.timeout,
7
8
  env: options.env,
8
9
  cwd: options.cwd,
9
10
  encoding: "utf8",
11
+ buffer: !streamOutput,
10
12
  });
13
+ if (streamOutput) {
14
+ if (subprocess.stdout) {
15
+ subprocess.stdout.on("data", (data) => {
16
+ const lines = data.toString().split(/\r?\n/);
17
+ for (const line of lines) {
18
+ if (line.trim()) {
19
+ if (options.onStdout) {
20
+ options.onStdout(line);
21
+ }
22
+ }
23
+ }
24
+ });
25
+ }
26
+ if (subprocess.stderr) {
27
+ subprocess.stderr.on("data", (data) => {
28
+ const lines = data.toString().split(/\r?\n/);
29
+ for (const line of lines) {
30
+ if (line.trim()) {
31
+ if (options.onStderr) {
32
+ options.onStderr(line);
33
+ }
34
+ }
35
+ }
36
+ });
37
+ }
38
+ }
11
39
  const { stdout, stderr, exitCode } = await subprocess;
12
40
  return {
13
41
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notask/unity-cli-tools",
3
- "version": "1.0.6-rc.2",
3
+ "version": "1.0.7-rc.1",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",