@salla.sa/twilight 2.6.10 → 2.6.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/twilight",
3
- "version": "2.6.10",
3
+ "version": "2.6.12",
4
4
  "description": "Salla Theme Toolkit, Webcomponents, Events, Requests, Utils",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
package/watcher.js CHANGED
@@ -1,11 +1,9 @@
1
1
  const path = require('path');
2
2
  const glob = require("glob");
3
3
  const color = {normal: "\x1b[0m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\x1b[33m", cyan: "\x1b[36m",}
4
- const {spawnSync} = require("child_process");
4
+ const {execSync} = require("child_process");
5
5
  const fs = require("fs");
6
6
  const WebSocketClient = require('websocket').client;
7
- const WebSocketServer = require("websocket").server;
8
- const http = require("http");
9
7
  //const webpack = require("webpack");
10
8
  /**
11
9
  * @callback HookCallback
@@ -68,8 +66,18 @@ class WatcherPlugin {
68
66
  this.upload_url = upload_url;
69
67
  this.store_id = store_id;
70
68
  this.draft_id = draft_id;
71
-
72
- this.startWebsocketServer(wsport);
69
+ // connect to live reload server
70
+ let client = new WebSocketClient();
71
+ client.on('connectFailed', (error)=> {
72
+ console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
73
+ });
74
+
75
+ client.on('connect', (connection)=> {
76
+ this.connection = connection;
77
+ console.log(color.green, `✓ Performing hot reload on port ws://localhost:${wsport}`, color.normal);
78
+ });
79
+
80
+ client.connect(`ws://localhost:${wsport}`, 'echo-protocol');
73
81
 
74
82
  }
75
83
 
@@ -100,16 +108,7 @@ class WatcherPlugin {
100
108
  let changes = false;
101
109
  files.map((file)=>{
102
110
  if(file.toLowerCase().endsWith('.twig')){
103
- // https://github.com/vercel/pkg/issues/1292
104
- console.log(spawnSync("salla", [this.sallaCli,
105
- "theme","sync",
106
- "-f",file,
107
- "-id",this.theme_id,
108
- "-store_id",this.store_id,
109
- "-draft_id",this.draft_id,
110
- "-upload_url",this.upload_url,
111
- "--nohead"
112
- ]).stdout.toString());
111
+ execSync(`${this.sallaCli} theme sync -f "${file}" -id ${this.theme_id} -store_id ${this.store_id} -draft_id ${this.draft_id} -upload_url ${this.upload_url}`, {stdio: 'inherit'});
113
112
  changes = true;
114
113
  }
115
114
  });
@@ -147,42 +146,6 @@ class WatcherPlugin {
147
146
 
148
147
  return !!this.theme_id;
149
148
  }
150
- startWebsocketServer(wsport){
151
- // start the live reload ws server
152
- const wsServer = new WebSocketServer({
153
- httpServer: http.createServer().listen(wsport),
154
- });
155
- let users = [];
156
- wsServer.on("request", function (request) {
157
- let connection = request.accept("echo-protocol", request.origin);
158
- users.push(connection);
159
-
160
- connection.on("error", function (message) {
161
- console.log("error", message);
162
- });
163
- connection.on("message", function (message) {
164
- // mirror to all users
165
- users.map((user) => {
166
- // check user
167
- if(user.connected)
168
- user.sendUTF(message.utf8Data);
169
- });
170
- });
171
- });
172
-
173
- // connect to live reload server
174
- let client = new WebSocketClient();
175
- client.on('connectFailed', (error)=> {
176
- console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
177
- });
178
-
179
- client.on('connect', (connection)=> {
180
- this.connection = connection;
181
- console.log(color.green, `✓ Performing hot reload on port ws://localhost:${wsport}`, color.normal);
182
- });
183
-
184
- client.connect(`ws://localhost:${wsport}`, 'echo-protocol');
185
- }
186
149
  }
187
150
 
188
151
  module.exports = WatcherPlugin;