@salla.sa/twilight 2.6.14 → 2.6.16

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.14",
3
+ "version": "2.6.16",
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
@@ -66,19 +66,8 @@ class WatcherPlugin {
66
66
  this.upload_url = upload_url;
67
67
  this.store_id = store_id;
68
68
  this.draft_id = draft_id;
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');
81
-
69
+ this.wsport = wsport;
70
+ this.files = {};
82
71
  }
83
72
 
84
73
  /**
@@ -94,6 +83,7 @@ class WatcherPlugin {
94
83
 
95
84
  console.log(color.green, '✓ Listening to webpack watch.', color.normal);
96
85
  this.addFilesToWatcher(compiler);
86
+ this.connectToWsServer();
97
87
  this.watchingChangedFiles(compiler);
98
88
  }
99
89
 
@@ -106,12 +96,12 @@ class WatcherPlugin {
106
96
  ? Array.from(compiler_.modifiedFiles || [])
107
97
  : Object.keys(compiler_.watchFileSystem.watcher.mtimes);
108
98
 
109
- files.map((file)=>{
110
- if(file.toLowerCase().endsWith('.twig'))
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'});
99
+ files.map((file) => {
100
+ if (file.toLowerCase().endsWith(".twig")) this.addToQ(file);
112
101
  });
113
-
114
- if(this.connection ) this.connection.sendUTF(JSON.stringify({msg:"reload"}));
102
+
103
+ if (this.connection)
104
+ this.connection.sendUTF(JSON.stringify({ msg: "reload" }));
115
105
  }
116
106
  );
117
107
  }
@@ -138,13 +128,34 @@ class WatcherPlugin {
138
128
  * @return {boolean}
139
129
  */
140
130
  canWatch(options) {
141
- if (options.mode !== 'development' || !options.watch) {
142
- console.log(color.green, `✓ Skipping Watching Theme files in production.`, color.normal);
143
- return false;
144
- }
145
-
131
+ if (!options.watch) return false;
146
132
  return !!this.theme_id;
147
133
  }
134
+ connectToWsServer(){
135
+ // connect to live reload server
136
+ let client = new WebSocketClient();
137
+ client.on('connectFailed', (error)=> {
138
+ console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
139
+ });
140
+
141
+ client.on('connect', (connection)=> {
142
+ this.connection = connection;
143
+ console.log(color.green, `✓ Performing hot reload on port ws://localhost:${this.wsport}`, color.normal);
144
+ });
145
+ client.connect(`ws://localhost:${this.wsport}`, 'echo-protocol');
146
+ }
147
+ addToQ(file) {
148
+ if (this.files[file]) clearTimeout(this.files[file]);
149
+ this.files[file] = setTimeout(() => {
150
+ execSync(
151
+ `${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}`,
152
+ { stdio: "inherit" }
153
+ );
154
+ delete this.files[file];
155
+ if (this.connection)
156
+ this.connection.sendUTF(JSON.stringify({ msg: "reload" }));
157
+ }, 700);
158
+ }
148
159
  }
149
160
 
150
161
  module.exports = WatcherPlugin;