@salla.sa/twilight 2.6.11 → 2.6.13
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/dist/@salla.sa/twilight.min.js +1 -1
- package/dist/@salla.sa/twilight.min.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/watcher.js +16 -45
package/package.json
CHANGED
package/watcher.js
CHANGED
|
@@ -4,8 +4,6 @@ const color = {normal: "\x1b[0m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\
|
|
|
4
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
|
-
|
|
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
|
|
|
@@ -97,14 +105,13 @@ class WatcherPlugin {
|
|
|
97
105
|
let files = this.isWebpack5
|
|
98
106
|
? Array.from(compiler_.modifiedFiles || [])
|
|
99
107
|
: Object.keys(compiler_.watchFileSystem.watcher.mtimes);
|
|
100
|
-
|
|
108
|
+
|
|
101
109
|
files.map((file)=>{
|
|
102
|
-
if(file.toLowerCase().endsWith('.twig'))
|
|
110
|
+
if(file.toLowerCase().endsWith('.twig'))
|
|
103
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'});
|
|
104
|
-
changes = true;
|
|
105
|
-
}
|
|
106
112
|
});
|
|
107
|
-
|
|
113
|
+
|
|
114
|
+
if(this.connection ) this.connection.sendUTF(JSON.stringify({msg:"reload"}));
|
|
108
115
|
}
|
|
109
116
|
);
|
|
110
117
|
}
|
|
@@ -138,42 +145,6 @@ class WatcherPlugin {
|
|
|
138
145
|
|
|
139
146
|
return !!this.theme_id;
|
|
140
147
|
}
|
|
141
|
-
startWebsocketServer(wsport){
|
|
142
|
-
// start the live reload ws server
|
|
143
|
-
const wsServer = new WebSocketServer({
|
|
144
|
-
httpServer: http.createServer().listen(wsport),
|
|
145
|
-
});
|
|
146
|
-
let users = [];
|
|
147
|
-
wsServer.on("request", function (request) {
|
|
148
|
-
let connection = request.accept("echo-protocol", request.origin);
|
|
149
|
-
users.push(connection);
|
|
150
|
-
|
|
151
|
-
connection.on("error", function (message) {
|
|
152
|
-
console.log("error", message);
|
|
153
|
-
});
|
|
154
|
-
connection.on("message", function (message) {
|
|
155
|
-
// mirror to all users
|
|
156
|
-
users.map((user) => {
|
|
157
|
-
// check user
|
|
158
|
-
if(user.connected)
|
|
159
|
-
user.sendUTF(message.utf8Data);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// connect to live reload server
|
|
165
|
-
let client = new WebSocketClient();
|
|
166
|
-
client.on('connectFailed', (error)=> {
|
|
167
|
-
console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
client.on('connect', (connection)=> {
|
|
171
|
-
this.connection = connection;
|
|
172
|
-
console.log(color.green, `✓ Performing hot reload on port ws://localhost:${wsport}`, color.normal);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
client.connect(`ws://localhost:${wsport}`, 'echo-protocol');
|
|
176
|
-
}
|
|
177
148
|
}
|
|
178
149
|
|
|
179
150
|
module.exports = WatcherPlugin;
|