@@ -3,7 +3,7 @@ global.logs = '';
33global . console . log = function ( x ) {
44 global . logs += JSON . stringify ( x ) + '\n' ;
55 process . stdout . write ( util . format . apply ( util , arguments ) ) ;
6- } ;
6+ } ;
77
88var fs = require ( 'fs' ) ;
99var gui = require ( 'nw.gui' ) ;
@@ -12,6 +12,22 @@ var nwPath = process.execPath;
1212var nwDir = path . dirname ( nwPath ) ;
1313var exec = require ( 'child_process' ) . exec ;
1414var spawn = require ( 'child_process' ) . spawn ;
15+ var execSync = require ( 'child_process' ) . execSync ;
16+
17+ function kill ( port ) {
18+ if ( ! Number . parseInt ( port ) ) {
19+ return Promise . reject ( new Error ( 'Invalid argument provided for port' ) )
20+ }
21+ if ( process . platform == "darwin" ) {
22+ return execSync ( `lsof -i tcp:${ port } | grep LISTEN | awk '{print $2}' | xargs kill -9` ) ;
23+ console . log ( "run on MAC" ) ;
24+ } else {
25+ return spawn ( 'cmd.exe' , [ 'for' , '/f' , '"tokens=5"' , '%a' , 'in' , '(\'netstat' , '-aon' , , '|' , 'findstr' , ':${port}' , '|' , 'find' , '"LISTENING"\')' , 'do' , 'taskkill' , '/f' , '/pid' , '%a' ] ) ;
26+ console . log ( "run on Windows" ) ;
27+ }
28+
29+ }
30+
1531
1632var $ = function ( selector ) {
1733 return document . querySelector ( selector ) ;
@@ -30,27 +46,28 @@ function startNode(path) {
3046
3147 if ( process . env . NODE_ENV === 'dev' && / ^ w i n / . test ( process . platform ) ) nodePath = global . __dirname + '\\node\\win32\\node.exe' ;
3248 // if (process.env.NODE_ENV === 'dev' && /^darwin/.test(process.platform)) nodePath = global.__dirname + '/node/osx64/node';
33-
49+
3450 if ( process . env . NODE_ENV != 'dev' && / ^ w i n / . test ( process . platform ) ) {
3551 nodePath = nwDir + '\\node.exe' ;
3652 }
3753
3854 if ( process . env . NODE_ENV != 'dev' && process . platform === 'darwin' ) {
39- var folderDir = require ( global . __dirname + '/config' ) . path ;
55+ var folderDir = require ( global . __dirname + '/config' ) . path ;
4056 nodePath = folderDir + '/node' ;
4157 }
4258
59+ console . log ( "nodePath is " + nodePath ) ;
4360 var lite_server = spawn ( nodePath , [ path ] ) ;
4461
45- lite_server . stdout . on ( 'data' , function ( data ) {
62+ lite_server . stdout . on ( 'data' , function ( data ) {
4663 console . log ( data . toString ( ) ) ;
4764 } ) ;
4865
49- lite_server . stderr . on ( 'data' , function ( data ) {
50- console . log ( data . toString ( ) ) ;
66+ lite_server . stderr . on ( 'data' , function ( data ) {
67+ console . log ( data . toString ( ) ) ;
5168 } ) ;
52-
53- lite_server . on ( 'close' , function ( status ) {
69+
70+ lite_server . on ( 'close' , function ( status ) {
5471 console . log ( "Terminal MCS Lite server:" + status ) ;
5572 } ) ;
5673}
@@ -98,7 +115,7 @@ function initApp() {
98115 adminServer = require ( folderDir + '\\adminServer\\index' ) ;
99116 $admin = require ( folderDir + '\\configs\\admin' ) ;
100117 }
101-
118+
102119 adminServer . listen ( $admin . port ) ;
103120 var win = gui . Window . get ( ) ;
104121 win . show ( ) ;
@@ -127,14 +144,13 @@ function initApp() {
127144 $admin = require ( folderDir + '/configs/admin' ) ;
128145 }
129146 }
130- var kill = require ( 'kill-port' ) ;
131147 kill ( $rest . port ) ;
132148 kill ( $wot . port ) ;
133149 kill ( $stream . serverPort ) ;
134150 kill ( $stream . rtmpServerPort ) ;
135151 win . close ( true ) ;
136152 } ) ;
137-
153+
138154 if ( process . env . NODE_ENV === 'dev' ) {
139155 document . body . innerHTML += '<iframe frameborder="0" src="http://' + $admin . host + ':' + $admin . port + '/login' + '" style="width: 100%; height: 580px; overflow: auto;" nwdisable nwfaketop>' ;
140156 // document.body.innerHTML += '<iframe frameborder="0" src="' + $admin.webClient.redirect.dev + '" style="width: 100%; height: 580px; overflow: auto;" nwdisable nwfaketop>';
0 commit comments