Skip to content

Commit 2c7bd99

Browse files
Pushing up start of support for Browser Extension
1 parent 2dbdc55 commit 2c7bd99

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

commands/remote.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ const express = require('express')
44
const fs = require('fs')
55
const https = require('https')
66
const ipc = require('node-ipc')
7-
const ora = require('ora')
87
const path = require('path')
98

109
const config = require('../lib/config')()
11-
const notify = require('../lib/notify')()
1210

1311
const port = 8443
1412

@@ -17,7 +15,6 @@ module.exports = async options => {
1715
let instance = argv['_'][2] || null
1816
let selected = null
1917
let remote
20-
let reloadTimeout
2118

2219
// Get Client & Instance, or check for Default
2320
if (client && instance) {
@@ -42,24 +39,13 @@ module.exports = async options => {
4239
ipc.config.retry = 1500
4340
ipc.config.silent = true
4441
ipc.serve(() => {
45-
ipc.server.on('message', cmd => {
46-
// Check if `remote` exists from socket.io and listen for commands
47-
if (remote && typeof remote.emit !== 'undefined') {
48-
// Handle Live Reload if enabled
49-
if (cmd === 'live-reload' && options.liveReload) {
50-
clearTimeout(reloadTimeout)
51-
reloadTimeout = setTimeout(() => {
52-
notify({
53-
title: `${client} ${instance}`,
54-
icon: path.join(__dirname, '../icons/', 'sfcc-reload.png'),
55-
subtitle: 'LIVE RELOAD',
56-
message: `Sending Reload Request to Sandbox`
57-
})
58-
59-
remote.emit('refresh', true)
60-
}, 3000)
61-
}
62-
}
42+
ipc.server.on('message', message => {
43+
console.log('MESSAGE', message)
44+
remote.emit('message', message)
45+
})
46+
ipc.server.on('watch', data => {
47+
console.log('WATCH', data)
48+
remote.emit('watch', data)
6349
})
6450
})
6551

@@ -103,15 +89,23 @@ module.exports = async options => {
10389
if (options.liveReload) {
10490
remote.emit('message', 'Live Reload Enabled')
10591
}
92+
93+
socket.on('message', message => {
94+
console.log('MESSAGE', message)
95+
})
96+
97+
socket.on('get-config', () => {
98+
io.emit('set-config', config.getAll())
99+
})
106100
})
107101

108102
server.listen(port, function() {
109103
console.log(`\n${chalk.bold('IMPORTANT')}: Make sure your sandbox has the following script tag:`)
110104
console.log('<script src="https://localhost:8443/sfcc-cli-remote.js" id="sfcc-cli-remote"></script>\n')
111105

112-
ora(
113-
`${chalk.bold('REMOTE')} ${chalk.cyan.bold(client)} ${chalk.magenta.bold(instance)} [Ctrl-C to Cancel]\n`
114-
).start()
106+
// ora(
107+
// `${chalk.bold('REMOTE')} ${chalk.cyan.bold(client)} ${chalk.magenta.bold(instance)} [Ctrl-C to Cancel]\n`
108+
// ).start()
115109
})
116110
}
117111
}

commands/watch.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ module.exports = options => {
8888
}
8989
}
9090

91-
const callback = () => {
92-
if (typeof remote.emit !== 'undefined') {
93-
remote.emit('message', 'live-reload')
91+
const callback = data => {
92+
if (remote && typeof remote.emit !== 'undefined') {
93+
remote.emit('watch', data)
9494
}
9595
}
9696

@@ -121,6 +121,16 @@ module.exports = options => {
121121
wait: true
122122
})
123123

124+
if (remote && typeof remote.emit !== 'undefined') {
125+
remote.emit('watch', {
126+
type: 'error',
127+
client: client,
128+
instance: instance,
129+
message: error,
130+
timestamp: new Date().toString()
131+
})
132+
}
133+
124134
errorMessage = `✖ Watch Error for '${client}' '${instance}': ${error}.`
125135
if (useLog) {
126136
logger.log(errorMessage)
@@ -139,6 +149,18 @@ module.exports = options => {
139149
})
140150
}
141151

152+
setTimeout(() => {
153+
if (remote && typeof remote.emit !== 'undefined') {
154+
remote.emit('watch', {
155+
type: 'watch',
156+
client: client,
157+
instance: instance,
158+
message: 'Starting Watcher',
159+
timestamp: new Date().toString()
160+
})
161+
}
162+
}, 100)
163+
142164
if (useLog) {
143165
logger.log(`Watching ${client} ${instance}`, true)
144166
} else {

lib/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ module.exports = () => {
5353
return config
5454
}
5555

56+
const getAll = () => {
57+
return config
58+
}
59+
5660
const set = (config, isUpdate) => {
5761
fs.writeFileSync(configFile, JSON.stringify(config), 'utf8')
5862

@@ -65,6 +69,7 @@ module.exports = () => {
6569

6670
return {
6771
get,
72+
getAll,
6873
set
6974
}
7075
}

lib/upload.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ module.exports = async ({file, spinner, selected, client, instance, options, cal
6363
}
6464

6565
if (typeof callback === 'function') {
66-
callback()
66+
callback({
67+
type: 'upload',
68+
client: client,
69+
instance: instance,
70+
message: file.replace(selected.d, '.'),
71+
timestamp: new Date().toString()
72+
})
6773
}
6874

6975
logMessage = `${chalk.green('COMPLETE')} ${file.replace(selected.d, '.')}`

0 commit comments

Comments
 (0)