matterbridge 2.2.3 → 2.2.4-dev.2

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 (152) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cli.js +2 -37
  3. package/dist/cluster/export.js +0 -2
  4. package/dist/defaultConfigSchema.js +0 -23
  5. package/dist/deviceManager.js +1 -94
  6. package/dist/frontend.js +33 -306
  7. package/dist/index.js +1 -28
  8. package/dist/logger/export.js +0 -1
  9. package/dist/matter/behaviors.js +0 -2
  10. package/dist/matter/clusters.js +0 -2
  11. package/dist/matter/devices.js +0 -2
  12. package/dist/matter/endpoints.js +0 -2
  13. package/dist/matter/export.js +0 -2
  14. package/dist/matter/types.js +0 -2
  15. package/dist/matterbridge.js +65 -725
  16. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  17. package/dist/matterbridgeBehaviors.js +1 -32
  18. package/dist/matterbridgeDeviceTypes.js +11 -112
  19. package/dist/matterbridgeDynamicPlatform.js +0 -33
  20. package/dist/matterbridgeEndpoint.js +6 -690
  21. package/dist/matterbridgeEndpointHelpers.js +9 -118
  22. package/dist/matterbridgePlatform.js +7 -185
  23. package/dist/matterbridgeTypes.js +0 -24
  24. package/dist/pluginManager.js +3 -229
  25. package/dist/shelly.js +6 -121
  26. package/dist/storage/export.js +0 -1
  27. package/dist/update.js +0 -45
  28. package/dist/utils/colorUtils.js +2 -205
  29. package/dist/utils/copyDirectory.js +1 -37
  30. package/dist/utils/createZip.js +2 -42
  31. package/dist/utils/deepCopy.js +0 -40
  32. package/dist/utils/deepEqual.js +1 -65
  33. package/dist/utils/export.js +0 -1
  34. package/dist/utils/isvalid.js +0 -86
  35. package/dist/utils/network.js +5 -77
  36. package/dist/utils/parameter.js +0 -41
  37. package/dist/utils/wait.js +5 -48
  38. package/frontend/build/asset-manifest.json +3 -3
  39. package/frontend/build/index.html +1 -1
  40. package/frontend/build/static/js/{main.6ffd2c31.js → main.819c0908.js} +4 -4
  41. package/frontend/build/static/js/{main.6ffd2c31.js.map → main.819c0908.js.map} +1 -1
  42. package/npm-shrinkwrap.json +2 -2
  43. package/package.json +1 -2
  44. package/dist/cli.d.ts +0 -29
  45. package/dist/cli.d.ts.map +0 -1
  46. package/dist/cli.js.map +0 -1
  47. package/dist/cluster/export.d.ts +0 -2
  48. package/dist/cluster/export.d.ts.map +0 -1
  49. package/dist/cluster/export.js.map +0 -1
  50. package/dist/defaultConfigSchema.d.ts +0 -27
  51. package/dist/defaultConfigSchema.d.ts.map +0 -1
  52. package/dist/defaultConfigSchema.js.map +0 -1
  53. package/dist/deviceManager.d.ts +0 -114
  54. package/dist/deviceManager.d.ts.map +0 -1
  55. package/dist/deviceManager.js.map +0 -1
  56. package/dist/frontend.d.ts +0 -201
  57. package/dist/frontend.d.ts.map +0 -1
  58. package/dist/frontend.js.map +0 -1
  59. package/dist/index.d.ts +0 -35
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.js.map +0 -1
  62. package/dist/logger/export.d.ts +0 -2
  63. package/dist/logger/export.d.ts.map +0 -1
  64. package/dist/logger/export.js.map +0 -1
  65. package/dist/matter/behaviors.d.ts +0 -2
  66. package/dist/matter/behaviors.d.ts.map +0 -1
  67. package/dist/matter/behaviors.js.map +0 -1
  68. package/dist/matter/clusters.d.ts +0 -2
  69. package/dist/matter/clusters.d.ts.map +0 -1
  70. package/dist/matter/clusters.js.map +0 -1
  71. package/dist/matter/devices.d.ts +0 -2
  72. package/dist/matter/devices.d.ts.map +0 -1
  73. package/dist/matter/devices.js.map +0 -1
  74. package/dist/matter/endpoints.d.ts +0 -2
  75. package/dist/matter/endpoints.d.ts.map +0 -1
  76. package/dist/matter/endpoints.js.map +0 -1
  77. package/dist/matter/export.d.ts +0 -5
  78. package/dist/matter/export.d.ts.map +0 -1
  79. package/dist/matter/export.js.map +0 -1
  80. package/dist/matter/types.d.ts +0 -3
  81. package/dist/matter/types.d.ts.map +0 -1
  82. package/dist/matter/types.js.map +0 -1
  83. package/dist/matterbridge.d.ts +0 -412
  84. package/dist/matterbridge.d.ts.map +0 -1
  85. package/dist/matterbridge.js.map +0 -1
  86. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
  87. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  88. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  89. package/dist/matterbridgeBehaviors.d.ts +0 -1056
  90. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  91. package/dist/matterbridgeBehaviors.js.map +0 -1
  92. package/dist/matterbridgeDeviceTypes.d.ts +0 -177
  93. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  94. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  95. package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
  96. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  97. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  98. package/dist/matterbridgeEndpoint.d.ts +0 -835
  99. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  100. package/dist/matterbridgeEndpoint.js.map +0 -1
  101. package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
  102. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  103. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  104. package/dist/matterbridgePlatform.d.ts +0 -251
  105. package/dist/matterbridgePlatform.d.ts.map +0 -1
  106. package/dist/matterbridgePlatform.js.map +0 -1
  107. package/dist/matterbridgeTypes.d.ts +0 -178
  108. package/dist/matterbridgeTypes.d.ts.map +0 -1
  109. package/dist/matterbridgeTypes.js.map +0 -1
  110. package/dist/pluginManager.d.ts +0 -236
  111. package/dist/pluginManager.d.ts.map +0 -1
  112. package/dist/pluginManager.js.map +0 -1
  113. package/dist/shelly.d.ts +0 -77
  114. package/dist/shelly.d.ts.map +0 -1
  115. package/dist/shelly.js.map +0 -1
  116. package/dist/storage/export.d.ts +0 -2
  117. package/dist/storage/export.d.ts.map +0 -1
  118. package/dist/storage/export.js.map +0 -1
  119. package/dist/update.d.ts +0 -32
  120. package/dist/update.d.ts.map +0 -1
  121. package/dist/update.js.map +0 -1
  122. package/dist/utils/colorUtils.d.ts +0 -61
  123. package/dist/utils/colorUtils.d.ts.map +0 -1
  124. package/dist/utils/colorUtils.js.map +0 -1
  125. package/dist/utils/copyDirectory.d.ts +0 -32
  126. package/dist/utils/copyDirectory.d.ts.map +0 -1
  127. package/dist/utils/copyDirectory.js.map +0 -1
  128. package/dist/utils/createZip.d.ts +0 -38
  129. package/dist/utils/createZip.d.ts.map +0 -1
  130. package/dist/utils/createZip.js.map +0 -1
  131. package/dist/utils/deepCopy.d.ts +0 -31
  132. package/dist/utils/deepCopy.d.ts.map +0 -1
  133. package/dist/utils/deepCopy.js.map +0 -1
  134. package/dist/utils/deepEqual.d.ts +0 -53
  135. package/dist/utils/deepEqual.d.ts.map +0 -1
  136. package/dist/utils/deepEqual.js.map +0 -1
  137. package/dist/utils/export.d.ts +0 -10
  138. package/dist/utils/export.d.ts.map +0 -1
  139. package/dist/utils/export.js.map +0 -1
  140. package/dist/utils/isvalid.d.ts +0 -87
  141. package/dist/utils/isvalid.d.ts.map +0 -1
  142. package/dist/utils/isvalid.js.map +0 -1
  143. package/dist/utils/network.d.ts +0 -70
  144. package/dist/utils/network.d.ts.map +0 -1
  145. package/dist/utils/network.js.map +0 -1
  146. package/dist/utils/parameter.d.ts +0 -44
  147. package/dist/utils/parameter.d.ts.map +0 -1
  148. package/dist/utils/parameter.js.map +0 -1
  149. package/dist/utils/wait.d.ts +0 -43
  150. package/dist/utils/wait.d.ts.map +0 -1
  151. package/dist/utils/wait.js.map +0 -1
  152. /package/frontend/build/static/js/{main.6ffd2c31.js.LICENSE.txt → main.819c0908.js.LICENSE.txt} +0 -0
package/dist/shelly.js CHANGED
@@ -1,33 +1,5 @@
1
- /**
2
- * This file contains the shelly api functions.
3
- *
4
- * @file shelly.ts
5
- * @author Luca Liguori
6
- * @date 2025-02-19
7
- * @version 1.0.3
8
- *
9
- * Copyright 2025, 2026, 2027 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
1
  import { WS_ID_SHELLY_MAIN_UPDATE, WS_ID_SHELLY_SYS_UPDATE } from './frontend.js';
24
2
  import { debugStringify } from './logger/export.js';
25
- /**
26
- * Fetches Shelly system updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
27
- *
28
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
29
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
30
- */
31
3
  export async function getShellySysUpdate(matterbridge) {
32
4
  getShelly('/api/updates/sys/check', 60 * 1000)
33
5
  .then(async (data) => {
@@ -46,12 +18,6 @@ export async function getShellySysUpdate(matterbridge) {
46
18
  matterbridge.log.warn(`Error getting Shelly system updates: ${error instanceof Error ? error.message : error}`);
47
19
  });
48
20
  }
49
- /**
50
- * Triggers Shelly system updates.
51
- *
52
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
53
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
54
- */
55
21
  export async function triggerShellySysUpdate(matterbridge) {
56
22
  getShelly('/api/updates/sys/perform', 10 * 1000)
57
23
  .then(async () => {
@@ -68,12 +34,6 @@ export async function triggerShellySysUpdate(matterbridge) {
68
34
  verifyShellyUpdate(matterbridge, '/api/updates/sys/status', 'Shelly system update');
69
35
  });
70
36
  }
71
- /**
72
- * Fetches Shelly main updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
73
- *
74
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
75
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
76
- */
77
37
  export async function getShellyMainUpdate(matterbridge) {
78
38
  getShelly('/api/updates/main/check', 60 * 1000)
79
39
  .then(async (data) => {
@@ -92,15 +52,9 @@ export async function getShellyMainUpdate(matterbridge) {
92
52
  matterbridge.log.warn(`Error getting Shelly main updates: ${error instanceof Error ? error.message : error}`);
93
53
  });
94
54
  }
95
- /**
96
- * Triggers Shelly main updates.
97
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
98
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
99
- */
100
55
  export async function triggerShellyMainUpdate(matterbridge) {
101
56
  getShelly('/api/updates/main/perform', 10 * 1000)
102
57
  .then(async () => {
103
- // {"updatingInProgress":true} or {"updatingInProgress":false}
104
58
  matterbridge.log.debug(`Triggered Shelly main updates`);
105
59
  })
106
60
  .catch((error) => {
@@ -114,20 +68,13 @@ export async function triggerShellyMainUpdate(matterbridge) {
114
68
  verifyShellyUpdate(matterbridge, '/api/updates/main/status', 'Shelly software update');
115
69
  });
116
70
  }
117
- /**
118
- * Verifies Shelly update.
119
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
120
- * @param {string} api - The api to call: /api/updates/sys/status or /api/updates/main/status
121
- * @param {string} name - The name of the update.
122
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
123
- */
124
71
  async function verifyShellyUpdate(matterbridge, api, name) {
125
72
  return new Promise((resolve) => {
126
73
  const timeout = setTimeout(() => {
127
74
  matterbridge.log.warn(`${name} check timed out`);
128
75
  clearInterval(interval);
129
76
  resolve();
130
- }, 600 * 1000); // 10 minutes
77
+ }, 600 * 1000);
131
78
  const interval = setInterval(() => {
132
79
  getShelly(api, 10 * 1000)
133
80
  .then(async (data) => {
@@ -149,15 +96,9 @@ async function verifyShellyUpdate(matterbridge, api, name) {
149
96
  clearTimeout(timeout);
150
97
  resolve();
151
98
  });
152
- }, 15 * 1000); // 15 seconds
99
+ }, 15 * 1000);
153
100
  });
154
101
  }
155
- /**
156
- * Triggers Shelly change network configuration.
157
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
158
- * @param {object} config - The network configuration.
159
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
160
- */
161
102
  export async function triggerShellyChangeIp(matterbridge, config) {
162
103
  const api = config.type === 'static' ? '/api/network/connection/static' : '/api/network/connection/dynamic';
163
104
  const data = { interface: 'end0' };
@@ -180,11 +121,6 @@ export async function triggerShellyChangeIp(matterbridge, config) {
180
121
  matterbridge.frontend.wssSendSnackbarMessage('Changed Shelly network configuration');
181
122
  });
182
123
  }
183
- /**
184
- * Triggers Shelly system reboot.
185
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
186
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
187
- */
188
124
  export async function triggerShellyReboot(matterbridge) {
189
125
  matterbridge.log.debug(`Triggering Shelly system reboot`);
190
126
  postShelly('/api/system/reboot', {}, 60 * 1000)
@@ -199,12 +135,6 @@ export async function triggerShellyReboot(matterbridge) {
199
135
  matterbridge.frontend.wssSendSnackbarMessage('Rebooting Shelly board...');
200
136
  });
201
137
  }
202
- /**
203
- * Fetches Shelly system log and write it to shelly.log.
204
- *
205
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
206
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
207
- */
208
138
  export async function createShellySystemLog(matterbridge) {
209
139
  const { promises: fs } = await import('node:fs');
210
140
  const path = await import('node:path');
@@ -224,23 +154,6 @@ export async function createShellySystemLog(matterbridge) {
224
154
  matterbridge.log.warn(`Error getting Shelly system log: ${error instanceof Error ? error.message : error}`);
225
155
  });
226
156
  }
227
- /**
228
- * Perform a GET to Shelly board apis.
229
- * @param {string} api - The api to call:
230
- *
231
- * /api/updates/sys/check => [{name:string; ...}]
232
- * /api/updates/sys/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
233
- * /api/updates/sys/status => {"updatingInProgress":true} or {"updatingInProgress":false}
234
- * /api/updates/main/check => [{name:string; ...}]
235
- * /api/updates/main/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
236
- * /api/updates/main/status => {"updatingInProgress":true} or {"updatingInProgress":false}
237
- *
238
- * /api/logs/system => text
239
- *
240
- * @param {number} [timeout=5000] - The timeout duration in milliseconds (default is 60000ms).
241
- * @returns {Promise<any>} A promise that resolves to the response.
242
- * @throws {Error} If the request fails.
243
- */
244
157
  async function getShelly(api, timeout = 60000) {
245
158
  const http = await import('node:http');
246
159
  return new Promise((resolve, reject) => {
@@ -254,13 +167,12 @@ async function getShelly(api, timeout = 60000) {
254
167
  let data = '';
255
168
  if (res.statusCode !== 200) {
256
169
  clearTimeout(timeoutId);
257
- res.resume(); // Discard response data to close the socket properly
258
- req.destroy(); // Forcefully close the request
170
+ res.resume();
171
+ req.destroy();
259
172
  reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
260
173
  return;
261
174
  }
262
175
  res.on('data', (chunk) => {
263
- // console.log(chunk);
264
176
  data += chunk;
265
177
  });
266
178
  res.on('end', () => {
@@ -275,7 +187,6 @@ async function getShelly(api, timeout = 60000) {
275
187
  }
276
188
  }
277
189
  else {
278
- // console.log(data);
279
190
  resolve(data);
280
191
  }
281
192
  });
@@ -286,29 +197,6 @@ async function getShelly(api, timeout = 60000) {
286
197
  });
287
198
  });
288
199
  }
289
- /**
290
- * Perform a POST request to Shelly board apis.
291
- * @param {string} api - The api to call:
292
- *
293
- * Set static ip
294
- * /api/network/connection/static -d '{"interface": "end0", "addr": "10.11.12.101", "mask": "255.255.255.0", "gw": "10.11.12.1", "dns": "1.1.1.1"}' => {}
295
- *
296
- * Set dhcp
297
- * /api/network/connection/dynamic -d '{"interface": "end0"}' => {}
298
- *
299
- * Reboot
300
- * /api/system/reboot => {"success":true}
301
- *
302
- * curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/dynamic
303
- * -d '{"interface": "end0"}'
304
- *
305
- * curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/static
306
- * -d '{"interface": "end0", "addr": "192.168.1.64", "mask": "255.255.255.0", "gw": "192.168.1.1", "dns": "192.168.1.1"}'
307
- *
308
- * @param {number} [timeout=5000] - The timeout duration in milliseconds (default is 60000ms).
309
- * @returns {Promise<any>} A promise that resolves to the response.
310
- * @throws {Error} If the request fails.
311
- */
312
200
  async function postShelly(api, data, timeout = 60000) {
313
201
  const http = await import('node:http');
314
202
  return new Promise((resolve, reject) => {
@@ -329,11 +217,10 @@ async function postShelly(api, data, timeout = 60000) {
329
217
  };
330
218
  const req = http.request(url, options, (res) => {
331
219
  let responseData = '';
332
- // Check for non-success status codes (e.g., 300+)
333
220
  if (res.statusCode && res.statusCode >= 300) {
334
221
  clearTimeout(timeoutId);
335
- res.resume(); // Discard response data to free up memory
336
- req.destroy(); // Close the request
222
+ res.resume();
223
+ req.destroy();
337
224
  return reject(new Error(`Failed to post data. Status code: ${res.statusCode}`));
338
225
  }
339
226
  res.on('data', (chunk) => {
@@ -354,9 +241,7 @@ async function postShelly(api, data, timeout = 60000) {
354
241
  clearTimeout(timeoutId);
355
242
  reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
356
243
  });
357
- // Send the JSON data
358
244
  req.write(jsonData);
359
245
  req.end();
360
246
  });
361
247
  }
362
- //# sourceMappingURL=shelly.js.map
@@ -1,2 +1 @@
1
1
  export * from 'node-persist-manager';
2
- //# sourceMappingURL=export.js.map
package/dist/update.js CHANGED
@@ -1,34 +1,5 @@
1
- /**
2
- * This file contains the check updates functions.
3
- *
4
- * @file update.ts
5
- * @author Luca Liguori
6
- * @date 2025-02-24
7
- * @version 1.0.0
8
- *
9
- * Copyright 2025, 2026, 2027 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
1
  import { plg } from './matterbridgeTypes.js';
24
2
  import { db, er, nt } from './logger/export.js';
25
- /**
26
- * Checks for updates for Matterbridge and its plugins.
27
- * If the 'shelly' parameter is present, also checks for Shelly updates.
28
- *
29
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
30
- * @returns {Promise<void>} A promise that resolves when the update checks are complete.
31
- */
32
3
  export async function checkUpdates(matterbridge) {
33
4
  const { hasParameter } = await import('./utils/parameter.js');
34
5
  getMatterbridgeLatestVersion(matterbridge);
@@ -41,13 +12,6 @@ export async function checkUpdates(matterbridge) {
41
12
  getShellyMainUpdate(matterbridge);
42
13
  }
43
14
  }
44
- /**
45
- * Retrieves the latest version of Matterbridge and updates the matterbridgeLatestVersion property.
46
- * If there is an error retrieving the latest version, logs an error message.
47
- *
48
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
49
- * @returns {Promise<void>} A promise that resolves when the latest version is retrieved.
50
- */
51
15
  async function getMatterbridgeLatestVersion(matterbridge) {
52
16
  const { getNpmPackageVersion } = await import('./utils/network.js');
53
17
  getNpmPackageVersion('matterbridge')
@@ -68,14 +32,6 @@ async function getMatterbridgeLatestVersion(matterbridge) {
68
32
  matterbridge.log.warn(`Error getting Matterbridge latest version: ${error.message}`);
69
33
  });
70
34
  }
71
- /**
72
- * Retrieves the latest version of a plugin and updates the plugin's latestVersion property.
73
- * If there is an error retrieving the latest version, logs an error message.
74
- *
75
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
76
- * @param {RegisteredPlugin} plugin - The plugin for which to retrieve the latest version.
77
- * @returns {Promise<void>} A promise that resolves when the latest version is retrieved.
78
- */
79
35
  async function getPluginLatestVersion(matterbridge, plugin) {
80
36
  const { getNpmPackageVersion } = await import('./utils/network.js');
81
37
  getNpmPackageVersion(plugin.name)
@@ -93,4 +49,3 @@ async function getPluginLatestVersion(matterbridge, plugin) {
93
49
  matterbridge.log.warn(`Error getting ${plg}${plugin.name}${er} latest version: ${error.message}`);
94
50
  });
95
51
  }
96
- //# sourceMappingURL=update.js.map
@@ -1,25 +1,3 @@
1
- /**
2
- * This file contains the color utilities.
3
- *
4
- * @file colorUtils.ts
5
- * @author Luca Liguori
6
- * @date 2023-10-05
7
- * @version 1.3.0
8
- *
9
- * Copyright 2023, 2024, 2025 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
1
  import { assert } from 'node:console';
24
2
  export function hslColorToRgbColor(hue, saturation, luminance) {
25
3
  if (hue === 360) {
@@ -32,7 +10,7 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
32
10
  luminance /= 100;
33
11
  let r, g, b;
34
12
  if (saturation === 0) {
35
- r = g = b = luminance; // achromatic
13
+ r = g = b = luminance;
36
14
  }
37
15
  else {
38
16
  const hue2rgb = (p, q, t) => {
@@ -65,27 +43,21 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
65
43
  b: Math.ceil(b * 255),
66
44
  };
67
45
  }
68
- // Converts from RGB to the XY color (CIE 1931 color space)
69
46
  export function rgbColorToXYColor(rgb) {
70
47
  let r = rgb.r / 255;
71
48
  let g = rgb.g / 255;
72
49
  let b = rgb.b / 255;
73
- // Apply gamma correction
74
50
  r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
75
51
  g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
76
52
  b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
77
- // Scale the values to the D65 illuminant
78
53
  r = r * 100;
79
54
  g = g * 100;
80
55
  b = b * 100;
81
- // Convert RGB to XYZ
82
56
  const X = r * 0.664511 + g * 0.154324 + b * 0.162028;
83
57
  const Y = r * 0.283881 + g * 0.668433 + b * 0.047685;
84
58
  const Z = r * 0.000088 + g * 0.07231 + b * 0.986039;
85
- // Normalization
86
59
  let x = X / (X + Y + Z);
87
60
  let y = Y / (X + Y + Z);
88
- // Round to 4 digits
89
61
  x = Math.round(x * 10000) / 10000;
90
62
  y = Math.round(y * 10000) / 10000;
91
63
  return { x, y };
@@ -95,11 +67,9 @@ export function xyColorToRgbColor(x, y, brightness = 254) {
95
67
  const Y = (brightness / 254).toFixed(2);
96
68
  const X = (Number(Y) / y) * x;
97
69
  const Z = (Number(Y) / y) * z;
98
- // Convert to RGB using Wide RGB D65 conversion
99
70
  let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
100
71
  let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
101
72
  let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
102
- // If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
103
73
  if (red > blue && red > green && red > 1.0) {
104
74
  green = green / red;
105
75
  blue = blue / red;
@@ -115,15 +85,12 @@ export function xyColorToRgbColor(x, y, brightness = 254) {
115
85
  green = green / blue;
116
86
  blue = 1.0;
117
87
  }
118
- // Reverse gamma correction
119
88
  red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
120
89
  green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
121
90
  blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
122
- // Convert normalized decimal to decimal
123
91
  red = Math.round(red * 255);
124
92
  green = Math.round(green * 255);
125
93
  blue = Math.round(blue * 255);
126
- // Normalize
127
94
  if (isNaN(red) || red < 0) {
128
95
  red = 0;
129
96
  }
@@ -144,7 +111,7 @@ export function rgbColorToHslColor(rgb) {
144
111
  let h = 0, s = 0;
145
112
  const l = (max + min) / 2;
146
113
  if (max === min) {
147
- h = s = 0; // achromatic
114
+ h = s = 0;
148
115
  }
149
116
  else {
150
117
  const d = max - min;
@@ -179,10 +146,8 @@ export function kelvinToMired(kelvin) {
179
146
  return Math.round(1000000 / kelvin);
180
147
  }
181
148
  export function kelvinToRGB(kelvin) {
182
- // Clamp the temperature to the range 1000K to 40000K
183
149
  kelvin = Math.max(1000, Math.min(40000, kelvin)) / 100;
184
150
  let r, g, b;
185
- // Calculate red
186
151
  if (kelvin <= 66) {
187
152
  r = 255;
188
153
  }
@@ -191,7 +156,6 @@ export function kelvinToRGB(kelvin) {
191
156
  r = 329.698727446 * Math.pow(r, -0.1332047592);
192
157
  r = Math.max(0, Math.min(255, r));
193
158
  }
194
- // Calculate green
195
159
  if (kelvin <= 66) {
196
160
  g = kelvin;
197
161
  g = 99.4708025861 * Math.log(g) - 161.1195681661;
@@ -202,7 +166,6 @@ export function kelvinToRGB(kelvin) {
202
166
  g = 288.1221695283 * Math.pow(g, -0.0755148492);
203
167
  g = Math.max(0, Math.min(255, g));
204
168
  }
205
- // Calculate blue
206
169
  if (kelvin >= 66) {
207
170
  b = 255;
208
171
  }
@@ -216,169 +179,3 @@ export function kelvinToRGB(kelvin) {
216
179
  }
217
180
  return { r: Math.round(r), g: Math.round(g), b: Math.round(b) };
218
181
  }
219
- /*
220
- export function testColors(): void {
221
- // this table has been checked with different apps and sites and is correct 100%
222
- const colors = [
223
- { name: 'Pure Red 0', hsl: { h: 0, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 0 }, xy: { x: 0.7006, y: 0.2993 } },
224
- { name: 'Bright Orange 30', hsl: { h: 30, s: 100, l: 50 }, rgb: { r: 255, g: 128, b: 0 }, xy: { x: 0.6112, y: 0.375 } },
225
- { name: 'Pure Yellow 60', hsl: { h: 60, s: 100, l: 50 }, rgb: { r: 255, g: 255, b: 0 }, xy: { x: 0.4442, y: 0.5166 } },
226
- { name: 'Lime Green 90', hsl: { h: 90, s: 100, l: 50 }, rgb: { r: 128, g: 255, b: 0 }, xy: { x: 0.2707, y: 0.6635 } },
227
- { name: 'Pure Green 120', hsl: { h: 120, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 0 }, xy: { x: 0.1724, y: 0.7468 } },
228
- { name: 'Light Sea Green 150', hsl: { h: 150, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 128 }, xy: { x: 0.1642, y: 0.5886 } },
229
- { name: 'Pure Cyan 180', hsl: { h: 180, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 255 }, xy: { x: 0.1513, y: 0.3425 } },
230
- { name: 'Deep Sky Blue 210', hsl: { h: 210, s: 100, l: 50 }, rgb: { r: 0, g: 128, b: 255 }, xy: { x: 0.1406, y: 0.1382 } },
231
- { name: 'Pure Blue 240', hsl: { h: 240, s: 100, l: 50 }, rgb: { r: 0, g: 0, b: 255 }, xy: { x: 0.1355, y: 0.0399 } },
232
- { name: 'Blue Violet 270', hsl: { h: 270, s: 100, l: 50 }, rgb: { r: 128, g: 0, b: 255 }, xy: { x: 0.2181, y: 0.0778 } },
233
- { name: 'Pure Magenta 300', hsl: { h: 300, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 255 }, xy: { x: 0.3855, y: 0.1546 } },
234
- { name: 'Deep Pink 330', hsl: { h: 330, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 128 }, xy: { x: 0.5797, y: 0.2438 } },
235
-
236
- { name: 'Pure Red 50% 0', hsl: { h: 0, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 64 }, xy: { x: 0.6036, y: 0.3069 } },
237
- { name: 'Bright Orange 50% 30', hsl: { h: 30, s: 50, l: 50 }, rgb: { r: 192, g: 128, b: 64 }, xy: { x: 0.5194, y: 0.3928 } },
238
- { name: 'Pure Yellow 50% 60', hsl: { h: 60, s: 50, l: 50 }, rgb: { r: 192, g: 192, b: 64 }, xy: { x: 0.4258, y: 0.4883 } },
239
- { name: 'Lime Green 50% 90', hsl: { h: 90, s: 50, l: 50 }, rgb: { r: 128, g: 192, b: 64 }, xy: { x: 0.3159, y: 0.5639 } },
240
- { name: 'Pure Green 50% 120', hsl: { h: 120, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 64 }, xy: { x: 0.2127, y: 0.6349 } },
241
- { name: 'Light Sea Green 50% 150', hsl: { h: 150, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 128 }, xy: { x: 0.1932, y: 0.4845 } },
242
- { name: 'Pure Cyan 50% 180', hsl: { h: 180, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 192 }, xy: { x: 0.1745, y: 0.3407 } },
243
- { name: 'Deep Sky Blue 50% 210', hsl: { h: 210, s: 50, l: 50 }, rgb: { r: 64, g: 128, b: 192 }, xy: { x: 0.1752, y: 0.211 } },
244
- { name: 'Pure Blue 50% 240', hsl: { h: 240, s: 50, l: 50 }, rgb: { r: 64, g: 64, b: 192 }, xy: { x: 0.1758, y: 0.102 } },
245
- { name: 'Blue Violet 50% 270', hsl: { h: 270, s: 50, l: 50 }, rgb: { r: 128, g: 64, b: 192 }, xy: { x: 0.2688, y: 0.137 } },
246
- { name: 'Pure Magenta 50% 300', hsl: { h: 300, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 192 }, xy: { x: 0.3772, y: 0.1777 } },
247
- { name: 'Deep Pink 50% 330', hsl: { h: 330, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 128 }, xy: { x: 0.489, y: 0.2416 } },
248
- ];
249
-
250
- colors.forEach((color) => {
251
- // eslint-disable-next-line no-console
252
- console.log(
253
- `\x1b[48;2;${color.rgb.r};${color.rgb.g};${color.rgb.b}mColor: ${color.name}\x1b[0m, hsl: { h: ${color.hsl.h}, s: ${color.hsl.s}, l: ${color.hsl.l} }, rgb: { r: ${color.rgb.r}, g: ${color.rgb.g}, b: ${color.rgb.b} }, xy: { x: ${color.xy.x}, y: ${color.xy.y} }`,
254
- );
255
-
256
- const rgb = hslColorToRgbColor(color.hsl.h, color.hsl.s, color.hsl.l);
257
- assert(rgb.r === color.rgb.r && rgb.g === color.rgb.g && rgb.b === color.rgb.b, `\x1b[48;2;${rgb.r};${rgb.g};${rgb.b}mColor: ${color.name}\x1b[0m hslColorToRgbColor { r: ${rgb.r}, g: ${rgb.g}, b: ${rgb.b} } conversion error`);
258
-
259
- const hsl = rgbColorToHslColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
260
- assert(hsl.h === color.hsl.h && hsl.s === color.hsl.s && hsl.l === color.hsl.l, `Color: ${color.name} rgbColorToHslColor conversion error`);
261
-
262
- const xy = rgbColorToXYColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
263
- assert(xy.x === color.xy.x && xy.y === color.xy.y, `Color: ${color.name} rgbColorToXYColor conversion error got x ${xy.x} y ${xy.y}`);
264
-
265
- const rgb2 = xyColorToRgbColor(color.xy.x, color.xy.y);
266
- assert(
267
- rgb2.r === color.rgb.r && rgb2.g === color.rgb.g && rgb2.b === color.rgb.b,
268
- `\x1b[48;2;${rgb2.r};${rgb2.g};${rgb2.b}mColor: ${color.name}\x1b[0m xyColorToRgbColor(${color.xy.x}, ${color.xy.y}) conversion error -> r: ${rgb2.r} g: ${rgb2.g} b: ${rgb2.g}`,
269
- );
270
- });
271
- }
272
- */
273
- /**
274
- * Converts CIE color space to RGB color space
275
- * @param {Number} x
276
- * @param {Number} y
277
- * @param {Number} brightness - Ranges from 1 to 254
278
- * @return {Array} Array that contains the color values for red, green and blue
279
- * From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
280
- */
281
- /*
282
- export function cie_to_rgb(x: number, y: number, brightness = 254): RGB {
283
- // Set to maximum brightness if no custom value was given (Not the slick ECMAScript 6 way for compatibility reasons)
284
-
285
- const z = 1.0 - x - y;
286
- const Y = (brightness / 254).toFixed(2);
287
- const X = (Number(Y) / y) * x;
288
- const Z = (Number(Y) / y) * z;
289
-
290
- // Convert to RGB using Wide RGB D65 conversion
291
- let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
292
- let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
293
- let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
294
-
295
- // If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
296
- if (red > blue && red > green && red > 1.0) {
297
- green = green / red;
298
- blue = blue / red;
299
- red = 1.0;
300
- } else if (green > blue && green > red && green > 1.0) {
301
- red = red / green;
302
- blue = blue / green;
303
- green = 1.0;
304
- } else if (blue > red && blue > green && blue > 1.0) {
305
- red = red / blue;
306
- green = green / blue;
307
- blue = 1.0;
308
- }
309
-
310
- // Reverse gamma correction
311
- red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
312
- green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
313
- blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
314
-
315
- // Convert normalized decimal to decimal
316
- red = Math.round(red * 255);
317
- green = Math.round(green * 255);
318
- blue = Math.round(blue * 255);
319
-
320
- // Normalize
321
- if (isNaN(red) || red < 0) {
322
- red = 0;
323
- }
324
- if (isNaN(green) || green < 0) {
325
- green = 0;
326
- }
327
- if (isNaN(blue) || blue < 0) {
328
- blue = 0;
329
- }
330
-
331
- return { r: red, g: green, b: blue };
332
- }
333
- */
334
- /**
335
- * Converts RGB color space to CIE color space
336
- * @param {Number} red
337
- * @param {Number} green
338
- * @param {Number} blue
339
- * @return {Array} Array that contains the CIE color values for x and y
340
- * From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
341
- */
342
- /*
343
- export function rgb_to_cie(red: number, green: number, blue: number): XY {
344
- // Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device
345
- red = red > 0.04045 ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : red / 12.92;
346
- green = green > 0.04045 ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : green / 12.92;
347
- blue = blue > 0.04045 ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : blue / 12.92;
348
-
349
- // RGB values to XYZ using the Wide RGB D65 conversion formula
350
- const X = red * 0.664511 + green * 0.154324 + blue * 0.162028;
351
- const Y = red * 0.283881 + green * 0.668433 + blue * 0.047685;
352
- const Z = red * 0.000088 + green * 0.07231 + blue * 0.986039;
353
-
354
- // Calculate the xy values from the XYZ values
355
- let x = (X / (X + Y + Z)).toFixed(4);
356
- let y = (Y / (X + Y + Z)).toFixed(4);
357
-
358
- if (isNaN(Number(x))) {
359
- x = '0';
360
- }
361
-
362
- if (isNaN(Number(y))) {
363
- y = '0';
364
- }
365
-
366
- return { x: Number(x), y: Number(y) };
367
- }
368
- */
369
- /*
370
- testColors();
371
- console.log('rgb_to_cie(0, 128, 255)', rgb_to_cie(0, 128, 255));
372
- console.log('cie_to_rgb(0.1401, 0.1284, 254)', cie_to_rgb(0.1401, 0.1284, 254));
373
- console.log('cie_to_rgb(0.1406, 0.1382, 254)', cie_to_rgb(0.1406, 0.1382, 254));
374
- for (let h = 0; h < 360; h++) {
375
- const rgb = hslColorToRgbColor(h, 100, 50);
376
- const xy = rgbColorToXYColor({ r: rgb.r, g: rgb.g, b: rgb.b });
377
- const rgb2 = cie_to_rgb(xy.x, xy.y, 254);
378
- const hsl = rgbColorToHslColor({ r: rgb2.r, g: rgb2.g, b: rgb2.b });
379
- assert(rgb.r === rgb2.r && rgb.g === rgb2.g && rgb.b === rgb2.b, 'Color rgb conversion error');
380
- assert(h === hsl.h, 'Color hsl conversion error');
381
- console.log(`\x1b[48;2;${rgb.r};${rgb.g};${rgb.b}mColor: r:${rgb.r} g:${rgb.g} b:${rgb.b}\x1b[0m => x:${xy.x} y:${xy.y} => \x1b[48;2;${rgb2.r};${rgb2.g};${rgb2.b}mColor: r:${rgb2.r} g:${rgb2.g} b:${rgb2.b} h:${hsl.h} s:${hsl.s}\x1b[0m\x1b[K`);
382
- }
383
- */
384
- //# sourceMappingURL=colorUtils.js.map
@@ -1,54 +1,19 @@
1
- /**
2
- * This file contains the copyDirectory function.
3
- *
4
- * @file copyDirectory.ts
5
- * @author Luca Liguori
6
- * @date 2025-02-16
7
- * @version 1.0.0
8
- *
9
- * Copyright 2025, 2026, 2027 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
- // AnsiLogger module
24
1
  import { AnsiLogger } from '../logger/export.js';
25
- /**
26
- * Copies a directory and all its subdirectories and files to a new location.
27
- *
28
- * @param {string} srcDir - The path to the source directory.
29
- * @param {string} destDir - The path to the destination directory.
30
- * @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
31
- * @throws {Error} - Throws an error if the copy operation fails.
32
- */
33
2
  export async function copyDirectory(srcDir, destDir) {
34
- const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
3
+ const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4, logLevel: "info" });
35
4
  const fs = await import('node:fs').then((mod) => mod.promises);
36
5
  const path = await import('node:path');
37
6
  log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
38
7
  try {
39
- // Create destination directory if it doesn't exist
40
8
  await fs.mkdir(destDir, { recursive: true });
41
- // Read contents of the source directory
42
9
  const entries = await fs.readdir(srcDir, { withFileTypes: true });
43
10
  for (const entry of entries) {
44
11
  const srcPath = path.join(srcDir, entry.name);
45
12
  const destPath = path.join(destDir, entry.name);
46
13
  if (entry.isDirectory()) {
47
- // Recursive call if entry is a directory
48
14
  await copyDirectory(srcPath, destPath);
49
15
  }
50
16
  else if (entry.isFile()) {
51
- // Copy file if entry is a file
52
17
  await fs.copyFile(srcPath, destPath);
53
18
  }
54
19
  }
@@ -59,4 +24,3 @@ export async function copyDirectory(srcDir, destDir) {
59
24
  return false;
60
25
  }
61
26
  }
62
- //# sourceMappingURL=copyDirectory.js.map