@symbo.ls/socket 2.10.121 → 2.10.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/server.js +19 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/socket",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.123",
|
|
4
4
|
"description": "Connect your app to Symbols editor",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"author": "symbo.ls",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"socket.io": "^4.5.2",
|
|
18
18
|
"socket.io-client": "^4.5.2"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "8e7c8dada6686b012c70e414cada2dd249790ab2"
|
|
21
21
|
}
|
package/server.js
CHANGED
|
@@ -4,16 +4,31 @@ import fs from 'fs'
|
|
|
4
4
|
import express from 'express'
|
|
5
5
|
import http from 'http'
|
|
6
6
|
import { Server } from 'socket.io'
|
|
7
|
-
import { dirname } from 'path' // eslint-disable-line
|
|
8
|
-
import mergeDeep from 'merge-deep' // use the require method
|
|
9
|
-
|
|
10
7
|
import { createRequire } from 'module'
|
|
8
|
+
import { deepMerge, overwriteDeep } from '@domql/utils'
|
|
11
9
|
|
|
12
10
|
const require = createRequire(import.meta.url) // construct the require method
|
|
13
11
|
const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/dynamic.json') // Bring in the ability to create the 'require' method
|
|
14
12
|
|
|
15
13
|
const app = express()
|
|
16
14
|
|
|
15
|
+
export const updateDynamycFile = (changes, options = {}) => {
|
|
16
|
+
const { key, live } = options
|
|
17
|
+
const file = require('@symbo.ls/init/dynamic.json')
|
|
18
|
+
|
|
19
|
+
const newMerge = overwriteDeep(changes, file)
|
|
20
|
+
const mergeStr = JSON.stringify(newMerge, null, 2)
|
|
21
|
+
const initPath = process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
|
|
22
|
+
|
|
23
|
+
if (live) {
|
|
24
|
+
io.to(key).emit('liveChange', mergeStr)
|
|
25
|
+
} else {
|
|
26
|
+
fs.writeFile(initPath, mergeStr, function (err) {
|
|
27
|
+
if (err) { return console.log(err) }
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, options = {}) => {
|
|
18
33
|
const server = http.createServer(app)
|
|
19
34
|
const { key, live } = options
|
|
@@ -49,20 +64,7 @@ export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, options = {}) => {
|
|
|
49
64
|
io.to(key).emit('route', data, options)
|
|
50
65
|
})
|
|
51
66
|
|
|
52
|
-
socket.on('change',
|
|
53
|
-
const file = require('@symbo.ls/init/dynamic.json')
|
|
54
|
-
const newMerge = mergeDeep(file, changes)
|
|
55
|
-
const mergeStr = JSON.stringify(newMerge, null, 2)
|
|
56
|
-
const initPath = process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
|
|
57
|
-
|
|
58
|
-
if (live) {
|
|
59
|
-
io.to(key).emit('liveChange', mergeStr)
|
|
60
|
-
} else {
|
|
61
|
-
fs.writeFile(initPath, mergeStr, function (err) {
|
|
62
|
-
if (err) { return console.log(err) }
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
})
|
|
67
|
+
socket.on('change', updateDynamycFile)
|
|
66
68
|
|
|
67
69
|
socket.on('disconnect', (changes, options) => {
|
|
68
70
|
const { clientsCount } = io.engine
|