@@ -5,6 +5,7 @@ import generateConfigFiles, { ConfigFileOptions } from './configFiles'
55import path from 'path'
66import SettingsService from '../settings'
77import fs from 'fs'
8+ import PerunController from '../../controllers/perun'
89
910const { app } = env
1011const platform = ( ) : string => {
@@ -20,7 +21,9 @@ const platform = (): string => {
2021 }
2122}
2223const binaryPath = ( ) : string => {
23- return app . isPackaged ? path . join ( path . dirname ( app . getAppPath ( ) ) , '..' , './bin' ) : path . join ( __dirname , '../../bin' )
24+ return app . isPackaged
25+ ? path . join ( path . dirname ( app . getAppPath ( ) ) , '..' , './bin' )
26+ : path . join ( __dirname , '../../../bin' )
2427}
2528const channelServiceRunnerBinary = ( ) : string => {
2629 const binary = app . isPackaged ? path . resolve ( binaryPath ( ) , './channel-service-runner' ) : path . resolve ( binaryPath ( ) , `./${ platform ( ) } ` , './channel-service-runner' )
@@ -57,7 +60,7 @@ export default class PerunChannelServiceRunner {
5760 await this . stop ( )
5861 }
5962
60- const { config, contractCellDeps , systemScripts } = generateConfigFiles ( opt )
63+ const { config } = generateConfigFiles ( opt ) // , contractCellDeps, systemScripts
6164
6265 const perunFolderPath = SettingsService . getInstance ( ) . getPeurnDataFolderPath ( ) ;
6366 const pathWithNetwork = path . join ( perunFolderPath , opt . network ) ;
@@ -66,34 +69,70 @@ export default class PerunChannelServiceRunner {
6669 const file_config_path = path . join ( pathWithNetwork , 'config.json' ) ;
6770 fs . writeFileSync ( file_config_path , JSON . stringify ( config , null , 2 ) ) ;
6871
69- const file_contractCellDeps_path = path . join ( pathWithNetwork , 'contracts_cell_deps.json' ) ;
70- fs . writeFileSync ( file_contractCellDeps_path , JSON . stringify ( contractCellDeps , null , 2 ) ) ;
72+ // const file_contractCellDeps_path = path.join(pathWithNetwork, 'contracts_cell_deps.json');
73+ // fs.writeFileSync(file_contractCellDeps_path, JSON.stringify(contractCellDeps, null, 2));
74+
75+ // const file_systemScripts_path = path.join(pathWithNetwork, 'system_scripts.json');
76+ // fs.writeFileSync(file_systemScripts_path, JSON.stringify(systemScripts, null, 2));
77+
78+
79+ console . log ( channelServiceRunnerBinary ( ) , file_config_path )
7180
72- const file_systemScripts_path = path . join ( pathWithNetwork , 'system_scripts.json' ) ;
73- fs . writeFileSync ( file_systemScripts_path , JSON . stringify ( systemScripts , null , 2 ) ) ;
74-
7581 const scrProcess = spawn ( channelServiceRunnerBinary ( ) , [
7682 // --config config.json
7783 '--config' ,
78- `" ${ file_config_path } " ` ,
84+ `${ file_config_path } ` ,
7985 // --system_scripts default_scripts.json
80- '--system_scripts' ,
81- `"${ file_systemScripts_path } "` ,
86+ // '--system_scripts',
87+ // `"${file_systemScripts_path}"`,
8288 // --migration_data contracts_cell_deps.json
83- '--migration_data' ,
84- `"${ file_contractCellDeps_path } "` ,
89+ // '--migration_data',
90+ // `"${file_contractCellDeps_path}"`,
8591 ] )
8692
87- scrProcess . stderr ?. on ( 'data' , data => {
88- logger . error ( 'PerunChannelServiceRunner:\t fail:' , data . toString ( ) )
93+ scrProcess ?. on ( 'spawn' , ( ) => {
94+ logger . info ( `PerunChannelServiceRunner spawn` )
95+ // this.logStream?.write(data)
96+ } )
97+
98+ scrProcess . stderr . on ( 'data' , data => {
99+ logger . error ( `PerunChannelServiceRunner stderr: ${ data } ` )
100+ // this.logStream?.write(data)
101+ } )
102+
103+ scrProcess . stdout . on ( 'data' , data => {
104+ logger . info ( `PerunChannelServiceRunner stdout: ${ data } ` )
105+ // this.logStream?.write(data)
106+ } )
107+
108+ scrProcess . on ( 'message' , data => {
109+ logger . info ( `PerunChannelServiceRunner message: ${ data } ` )
110+ // this.logStream?.write(data)
89111 } )
90112
113+ scrProcess . on ( 'exit' , data => {
114+ logger . info ( `PerunChannelServiceRunner exit: ${ data } ` )
115+ // this.logStream?.write(data)
116+ } )
117+
118+
91119 scrProcess . on ( "error" , error => {
92120 logger . error ( 'PerunChannelServiceRunner:\t fail:' , error )
121+ this . runnerProcess ?. kill ( )
122+ this . runnerProcess = undefined
123+ PerunController . emiter . emit ( "perun-service" , {
124+ runner : "channel-service-runner" ,
125+ type : 'stop' ,
126+ message : error . message
127+ } )
93128 } )
94129
95130 scrProcess . once ( "close" , ( ) => {
96131 logger . info ( 'PerunChannelServiceRunner:\t closed' )
132+ PerunController . emiter . emit ( "perun-service" , {
133+ runner : "channel-service-runner" ,
134+ type : 'stop'
135+ } )
97136 this . runnerProcess = undefined ;
98137 } )
99138
0 commit comments