@@ -10,6 +10,7 @@ import {
1010} from "./types/unity.js" ;
1111import { CommandOptions , CommandResult , executeCommand } from "./utils/commandExecutor.js" ;
1212import { getUnityChangeset } from "unity-changeset" ;
13+ import { UnityHubInstallerEvent } from "./events/hubEventEmitter.ts" ;
1314
1415/**
1516 * Class for interacting with Unity Hub via command line interface
@@ -210,15 +211,15 @@ class UnityHub {
210211 * @param {string } editorVersion - Unity version to add modules to (e.g. "2022.3.60f1")
211212 * @param {ModuleId[] } modules - Array of module IDs to add
212213 * @param {boolean } [childModules=false] - Whether to include child modules
213- * @returns {Promise<void> } Resolves when modules are added successfully
214+ * @returns {UnityHubInstallerEvent } Event emitter for installation progress
214215 * @throws Will throw an error if module addition fails
215216 * @public
216217 */
217218 public static async addModule (
218219 editorVersion : string ,
219220 modules : ModuleId [ ] ,
220221 childModules : boolean = true
221- ) : Promise < void > {
222+ ) : Promise < UnityHubInstallerEvent > {
222223 try {
223224 console . debug ( `Adding module ${ modules } to Unity ${ editorVersion } ` ) ;
224225
@@ -234,19 +235,15 @@ class UnityHub {
234235 throw new Error ( "No module IDs provided." ) ;
235236 }
236237
237- const { stderr } = await this . execUnityHubCommand ( args , {
238+ const installerEmitter = new UnityHubInstallerEvent ( ) ;
239+ this . execUnityHubCommand ( args , {
238240 reject : false ,
239- onStderr : ( data : string ) => {
240- console . warn ( `Unity Hub stderr: ${ data } ` ) ;
241- } ,
242- onStdout : ( data : string ) => {
243- console . debug ( `Unity Hub stdout: ${ data } ` ) ;
244- } ,
241+ //onStderr: (data: string) => installerEmitter.Progress(data),
242+ onStdout : ( data : string ) => installerEmitter . Progress ( data ) ,
243+ } ) . catch ( ( error ) => {
244+ console . error ( `Error adding module ${ modules } to Unity ${ editorVersion } :` , error ) ;
245245 } ) ;
246-
247- if ( stderr ) {
248- console . warn ( `Add module command warning/error: ${ stderr } ` ) ;
249- }
246+ return installerEmitter ;
250247 } catch ( error ) {
251248 console . error ( `Error adding module ${ modules } to Unity ${ editorVersion } :` , error ) ;
252249 throw error ;
@@ -259,15 +256,15 @@ class UnityHub {
259256 * @param {string } [changeset] - Optional specific changeset to install
260257 * @param {ModuleId[] } [modules=[]] - Optional array of modules to install with the editor
261258 * @param {EditorArchitecture } [architecture=EditorArchitecture.x86_64] - Optional architecture (x86_64 or arm64)
262- * @returns {Promise<void> } Resolves when editor installation begins successfully
259+ * @returns {UnityHubInstallerEvent } Event emitter for installation progress
263260 * @throws Will throw an error if installation fails to start
264261 * @public
265262 */
266263 public static async addEditor (
267264 version : string ,
268265 modules : ModuleId [ ] = [ ] ,
269266 architecture ?: EditorArchitecture
270- ) : Promise < void > {
267+ ) : Promise < UnityHubInstallerEvent > {
271268 try {
272269 const data = await getUnityChangeset ( version ) ;
273270 const args = [ "install" , "-v" , version ] ;
@@ -288,21 +285,16 @@ class UnityHub {
288285
289286 args . push ( "--architecture" , architecture ) ;
290287
291- const { stdout, stderr } = await this . execUnityHubCommand ( args , {
288+ const installerEmitter = new UnityHubInstallerEvent ( ) ;
289+ this . execUnityHubCommand ( args , {
292290 reject : false ,
293- onStderr : ( data : string ) => {
294- console . warn ( `Unity Hub stderr: ${ data } ` ) ;
295- } ,
296- onStdout : ( data : string ) => {
297- console . debug ( `Unity Hub stdout: ${ data } ` ) ;
298- } ,
291+ //onStderr: (data: string) => installerEmitter.Error(data),
292+ onStdout : ( data : string ) => installerEmitter . Progress ( data ) ,
293+ } ) . catch ( ( error ) => {
294+ console . error ( `Error installing Unity ${ version } :` , error ) ;
299295 } ) ;
300296
301- if ( stderr ) {
302- throw new Error ( `Error installing Unity ${ version } : ${ stderr } ` ) ;
303- }
304-
305- console . debug ( `Unity ${ version } . ${ stdout } ` ) ;
297+ return installerEmitter ;
306298 } catch ( error ) {
307299 console . error ( error ) ;
308300 throw error ;
0 commit comments