@salla.sa/twilight 2.0.291 → 2.0.292

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/watcher.js +29 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/twilight",
3
- "version": "2.0.291",
3
+ "version": "2.0.292",
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
@@ -60,6 +60,16 @@ class WatcherPlugin {
60
60
  this.upload_url = upload_url;
61
61
  this.store_id = store_id;
62
62
  this.draft_id = draft_id;
63
+
64
+ if(typeof theme_id === "undefined"){
65
+ // a hacky way to get args from process.env.npm_lifecycle_script
66
+ let args = parseNpmScriptsPassedArgs(process.env.npm_lifecycle_script);
67
+ this.theme_id = args.theme_id;
68
+ this.upload_url = args.upload_url;
69
+ this.store_id = args.store_id;
70
+ this.draft_id = args.draft_id;
71
+ port = args.port || 8000;
72
+ }
63
73
 
64
74
  let client = new WebSocketClient();
65
75
 
@@ -140,5 +150,23 @@ class WatcherPlugin {
140
150
  return true;
141
151
  }
142
152
  }
143
-
153
+ function parseNpmScriptsPassedArgs(str){
154
+ // get all strings between equal sign
155
+ let strs = str.match(/"([^"]*)"/g);
156
+ // remove quotes
157
+ strs = strs.map(str => str.replace(/"/g, ''));
158
+ // split by =
159
+ strs = strs.map(str => str.split('='));
160
+ // to be object
161
+ strs = strs.map(str => {
162
+ let obj = {};
163
+ obj[str[0]] = str[1];
164
+ return obj;
165
+ }
166
+ );
167
+ // reduce to one object
168
+ return strs.reduce((acc, curr) => {
169
+ return {...acc, ...curr};
170
+ })
171
+ }
144
172
  module.exports = WatcherPlugin;