@symbo.ls/socket 0.0.5 → 0.0.7
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 +1 -1
- package/server.js +7 -6
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -5,15 +5,16 @@ import express from 'express'
|
|
|
5
5
|
import http from 'http'
|
|
6
6
|
import { Server } from 'socket.io'
|
|
7
7
|
import { dirname } from 'path' // eslint-disable-line
|
|
8
|
-
import merge from 'merge-deep'
|
|
8
|
+
import merge from 'merge-deep' // use the require method
|
|
9
|
+
|
|
10
|
+
import { createRequire } from 'module'
|
|
9
11
|
|
|
10
|
-
import { createRequire } from 'module' // Bring in the ability to create the 'require' method
|
|
11
12
|
const require = createRequire(import.meta.url) // construct the require method
|
|
12
|
-
const
|
|
13
|
+
const DYNAMIC_CONFIG = require('@symbo.ls/init/src/dynamic.json') // Bring in the ability to create the 'require' method
|
|
13
14
|
|
|
14
15
|
const app = express()
|
|
15
16
|
|
|
16
|
-
export const sync = (symbolsInitFile =
|
|
17
|
+
export const sync = (symbolsInitFile = DYNAMIC_CONFIG) => {
|
|
17
18
|
const server = http.createServer(app)
|
|
18
19
|
|
|
19
20
|
const io = new Server(server, {
|
|
@@ -30,10 +31,10 @@ export const sync = (symbolsInitFile = SYMBOLS_RC) => {
|
|
|
30
31
|
io.on('connection', (socket) => {
|
|
31
32
|
console.log('a user connected')
|
|
32
33
|
|
|
33
|
-
socket.emit('init',
|
|
34
|
+
socket.emit('init', symbolsInitFile)
|
|
34
35
|
|
|
35
36
|
socket.on('change', change => {
|
|
36
|
-
const newMerge = merge(
|
|
37
|
+
const newMerge = merge(change, symbolsInitFile)
|
|
37
38
|
const mergeStr = JSON.stringify(newMerge, null, 2)
|
|
38
39
|
const initPath = process.cwd() + '/node_modules/@symbo.ls/init/src/dynamic.json'
|
|
39
40
|
fs.writeFile(initPath, mergeStr, function (err) {
|