@salla.sa/twilight 2.0.277 → 2.0.279

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.0.277",
3
+ "version": "2.0.279",
4
4
  "description": "Salla Theme Toolkit, Webcomponents, Events, Requests, Utils",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -41,7 +41,9 @@
41
41
  "lang.js": "^1.1.14",
42
42
  "rollup-plugin-json": "^4.0.0",
43
43
  "rollup-plugin-node-resolve": "^5.2.0",
44
- "store": "^2.0.12"
44
+ "store": "^2.0.12",
45
+ "dotenv": "^16.0.1",
46
+ "websocket": "^1.0.34"
45
47
  },
46
48
  "devDependencies": {
47
49
  "@babel/core": "^7.17.7",
@@ -13,6 +13,6 @@ export default interface ProductEvent {
13
13
  onSearchFailed: RequestErrorEventWithData</*query*/string|undefined>;
14
14
 
15
15
  onOfferExisted: (callback: (offer: OfferSummary) => void) => void;
16
- ondOffersFetched: (callback: (response: ProductResponse.offers) => void) => void;
16
+ onOffersFetched: (callback: (response: ProductResponse.offers) => void) => void;
17
17
  onFetchOffersFailed: RequestErrorEvent;
18
18
  }
package/watcher.js CHANGED
@@ -2,6 +2,10 @@ 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
4
  const {execSync} = require("child_process");
5
+ const fs = require("fs");
6
+ const env = require("dotenv");
7
+ const WebSocketClient = require('websocket').client;
8
+
5
9
  //const webpack = require("webpack");
6
10
  /**
7
11
  * @callback HookCallback
@@ -48,8 +52,24 @@ const {execSync} = require("child_process");
48
52
  * @property {boolean} isWin
49
53
  */
50
54
  class WatcherPlugin {
51
- constructor(sallaCli = 'salla') {
52
- this.sallaCli = sallaCli;
55
+ constructor({port = 8000,sallaCli = "salla",theme_id}) {
56
+
57
+ this.sallaCli = sallaCli;
58
+ this.theme_id = theme_id;
59
+
60
+ let client = new WebSocketClient();
61
+
62
+ client.on('connectFailed', function(error) {
63
+ console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
64
+ });
65
+
66
+ client.on('connect', (connection)=> {
67
+ this.connection = connection;
68
+ console.log(color.green, `✓ Performing hot reload on port ws://localhost:${port}`, color.normal);
69
+ });
70
+
71
+ client.connect(`ws://localhost:${port}`, 'echo-protocol');
72
+
53
73
  }
54
74
 
55
75
  /**
@@ -76,8 +96,13 @@ class WatcherPlugin {
76
96
  let files = this.isWebpack5
77
97
  ? Array.from(compiler_.modifiedFiles || [])
78
98
  : Object.keys(compiler_.watchFileSystem.watcher.mtimes);
79
- files.filter(file => file.toLowerCase().endsWith('.twig'))
80
- .forEach(file => execSync(`${this.sallaCli} theme sync -f "${file}" -t ${this.draftId}`, {stdio: 'inherit'}));
99
+
100
+ files.map((file)=>{
101
+ if(file.toLowerCase().endsWith('.twig'))
102
+ execSync(`${this.sallaCli} theme sync -f "${file}" -id ${this.theme_id}`, {stdio: 'inherit'});
103
+
104
+ if(this.connection) this.connection.sendUTF(JSON.stringify({msg:"reload"}));
105
+ });
81
106
  }
82
107
  );
83
108
  }
@@ -103,20 +128,12 @@ class WatcherPlugin {
103
128
  * @param {{mode:'development'|'none'|'production', watch:boolean, ...}} options - @see https://webpack.js.org/configuration
104
129
  * @return {boolean}
105
130
  */
106
- canWatch(options) {
131
+ canWatch(options) {
107
132
  if (options.mode !== 'development' || !options.watch) {
108
133
  console.log(color.green, `✓ Skipping Watching Theme files in production.`, color.normal);
109
134
  return false;
110
135
  }
111
- //if theme id not existed go out
112
- try {
113
- this.draftId = require(path.resolve(process.cwd(), 'theme.json')).draft_id
114
- return !!this.draftId;
115
- } catch (e) {
116
- let command = color.cyan + this.sallaCli + ' theme watch' + color.red
117
- console.log(color.red, `X Theme files won't sync! if you want to sync them, run: ${command}`, color.normal);
118
- return false;
119
- }
136
+ return true;
120
137
  }
121
138
  }
122
139