@salla.sa/twilight 2.6.15 → 2.6.17
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 +39 -24
package/package.json
CHANGED
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
|
-
|
|
70
|
-
|
|
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,9 +83,19 @@ 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);
|
|
88
|
+
this.afterCompile(compiler);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {Compiler} compiler
|
|
93
|
+
*/
|
|
94
|
+
afterCompile(compiler) {
|
|
95
|
+
compiler.hooks.afterCompile.tap('SallaAfterCompilePlugin', (compilation) => {
|
|
96
|
+
this.connection.sendUTF(JSON.stringify({ msg: "reload" }));
|
|
97
|
+
});
|
|
98
98
|
}
|
|
99
|
-
|
|
100
99
|
/**
|
|
101
100
|
* @param {Compiler} compiler
|
|
102
101
|
*/
|
|
@@ -106,12 +105,9 @@ class WatcherPlugin {
|
|
|
106
105
|
? Array.from(compiler_.modifiedFiles || [])
|
|
107
106
|
: Object.keys(compiler_.watchFileSystem.watcher.mtimes);
|
|
108
107
|
|
|
109
|
-
files.map((file)=>{
|
|
110
|
-
|
|
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'});
|
|
108
|
+
files.map((file) => {
|
|
109
|
+
if (file.toLowerCase().endsWith(".twig")) this.addToQ(file);
|
|
112
110
|
});
|
|
113
|
-
|
|
114
|
-
if(this.connection ) this.connection.sendUTF(JSON.stringify({msg:"reload"}));
|
|
115
111
|
}
|
|
116
112
|
);
|
|
117
113
|
}
|
|
@@ -138,13 +134,32 @@ class WatcherPlugin {
|
|
|
138
134
|
* @return {boolean}
|
|
139
135
|
*/
|
|
140
136
|
canWatch(options) {
|
|
141
|
-
if (
|
|
142
|
-
console.log(color.green, `✓ Skipping Watching Theme files in production.`, color.normal);
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
|
|
137
|
+
if (!options.watch) return false;
|
|
146
138
|
return !!this.theme_id;
|
|
147
139
|
}
|
|
140
|
+
connectToWsServer(){
|
|
141
|
+
// connect to live reload server
|
|
142
|
+
let client = new WebSocketClient();
|
|
143
|
+
client.on('connectFailed', (error)=> {
|
|
144
|
+
console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
client.on('connect', (connection)=> {
|
|
148
|
+
this.connection = connection;
|
|
149
|
+
console.log(color.green, `✓ Performing hot reload on port ws://localhost:${this.wsport}`, color.normal);
|
|
150
|
+
});
|
|
151
|
+
client.connect(`ws://localhost:${this.wsport}`, 'echo-protocol');
|
|
152
|
+
}
|
|
153
|
+
addToQ(file) {
|
|
154
|
+
if (this.files[file]) clearTimeout(this.files[file]);
|
|
155
|
+
this.files[file] = setTimeout(() => {
|
|
156
|
+
execSync(
|
|
157
|
+
`${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}`,
|
|
158
|
+
{ stdio: "inherit" }
|
|
159
|
+
);
|
|
160
|
+
delete this.files[file];
|
|
161
|
+
}, 700);
|
|
162
|
+
}
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
module.exports = WatcherPlugin;
|