@@ -4,17 +4,25 @@ const express = require('express')
44const fs = require ( 'fs' )
55const https = require ( 'https' )
66const ipc = require ( 'node-ipc' )
7+ const ora = require ( 'ora' )
78const path = require ( 'path' )
89
910const config = require ( '../lib/config' ) ( )
1011
1112const port = 8443
1213
13- module . exports = async options => {
14+ module . exports = async ( ) => {
1415 let client = argv [ '_' ] [ 1 ] || null
1516 let instance = argv [ '_' ] [ 2 ] || null
1617 let selected = null
1718 let remote
19+ let spinner
20+
21+ const output = fn => {
22+ spinner . stop ( )
23+ fn ( )
24+ spinner . start ( )
25+ }
1826
1927 // Get Client & Instance, or check for Default
2028 if ( client && instance ) {
@@ -32,20 +40,32 @@ module.exports = async options => {
3240 if ( selected ) {
3341 const sslKey = path . resolve ( __dirname , '../remote/ssl/sfcc-cli-ca.pvk' )
3442 const sslCrt = path . resolve ( __dirname , '../remote/ssl/sfcc-cli-ca.cer' )
35- const jsFile = path . resolve ( __dirname , '../remote/sfcc-cli-remote.js' )
3643
3744 // Start Message Bus
3845 ipc . config . id = 'remote'
3946 ipc . config . retry = 1500
4047 ipc . config . silent = true
4148 ipc . serve ( ( ) => {
42- ipc . server . on ( 'message' , message => {
43- console . log ( 'MESSAGE' , message )
44- remote . emit ( 'message' , message )
49+ ipc . server . on ( 'message' , data => {
50+ if ( remote && typeof remote . emit !== 'undefined' ) {
51+ remote . emit ( 'message' , data )
52+ } else {
53+ output ( ( ) => console . log ( chalk . red . bold ( `✖ Failed Remote Message` , data ) ) )
54+ }
4555 } )
4656 ipc . server . on ( 'watch' , data => {
47- console . log ( 'WATCH' , data )
48- remote . emit ( 'watch' , data )
57+ if ( remote && typeof remote . emit !== 'undefined' ) {
58+ remote . emit ( 'watch' , data )
59+ } else {
60+ output ( ( ) => console . log ( chalk . red . bold ( `✖ Failed Remote Watch` , data ) ) )
61+ }
62+ } )
63+ ipc . server . on ( 'log' , data => {
64+ if ( remote && typeof remote . emit !== 'undefined' ) {
65+ remote . emit ( 'log' , data )
66+ } else {
67+ output ( ( ) => console . log ( chalk . red . bold ( `✖ Failed Remote Log` , data ) ) )
68+ }
4969 } )
5070 } )
5171
@@ -76,19 +96,9 @@ module.exports = async options => {
7696
7797 const io = require ( 'socket.io' ) ( server )
7898
79- // https://localhost:8443/sfcc-cli-remote.js
80- app . get ( '/sfcc-cli-remote.js' , ( req , res ) => {
81- res . set ( 'Content-Type' , 'application/javascript' )
82- res . send ( fs . readFileSync ( jsFile ) )
83- } )
84-
8599 // Handle connections from remote script
86100 io . on ( 'connection' , socket => {
87101 remote = socket
88- // Check if Live Reload flag was enabled
89- if ( options . liveReload ) {
90- remote . emit ( 'message' , 'Live Reload Enabled' )
91- }
92102
93103 socket . on ( 'message' , message => {
94104 console . log ( 'MESSAGE' , message )
@@ -100,12 +110,9 @@ module.exports = async options => {
100110 } )
101111
102112 server . listen ( port , function ( ) {
103- console . log ( `\n${ chalk . bold ( 'IMPORTANT' ) } : Make sure your sandbox has the following script tag:` )
104- console . log ( '<script src="https://localhost:8443/sfcc-cli-remote.js" id="sfcc-cli-remote"></script>\n' )
105-
106- // ora(
107- // `${chalk.bold('REMOTE')} ${chalk.cyan.bold(client)} ${chalk.magenta.bold(instance)} [Ctrl-C to Cancel]\n`
108- // ).start()
113+ spinner = ora (
114+ `${ chalk . bold ( 'REMOTE' ) } ${ chalk . cyan . bold ( client ) } ${ chalk . magenta . bold ( instance ) } [Ctrl-C to Cancel]\n`
115+ ) . start ( )
109116 } )
110117 }
111118}
0 commit comments