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.
- package/CHANGELOG.md +15 -0
- package/dist/cli.js +2 -37
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +33 -306
- package/dist/index.js +1 -28
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -2
- package/dist/matter/types.js +0 -2
- package/dist/matterbridge.js +65 -725
- package/dist/matterbridgeAccessoryPlatform.js +0 -33
- package/dist/matterbridgeBehaviors.js +1 -32
- package/dist/matterbridgeDeviceTypes.js +11 -112
- package/dist/matterbridgeDynamicPlatform.js +0 -33
- package/dist/matterbridgeEndpoint.js +6 -690
- package/dist/matterbridgeEndpointHelpers.js +9 -118
- package/dist/matterbridgePlatform.js +7 -185
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -229
- package/dist/shelly.js +6 -121
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -45
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/copyDirectory.js +1 -37
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +0 -40
- package/dist/utils/deepEqual.js +1 -65
- package/dist/utils/export.js +0 -1
- package/dist/utils/isvalid.js +0 -86
- package/dist/utils/network.js +5 -77
- package/dist/utils/parameter.js +0 -41
- package/dist/utils/wait.js +5 -48
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.6ffd2c31.js → main.819c0908.js} +4 -4
- package/frontend/build/static/js/{main.6ffd2c31.js.map → main.819c0908.js.map} +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/cli.d.ts +0 -29
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts +0 -2
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -27
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -114
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/frontend.d.ts +0 -201
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/index.d.ts +0 -35
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -412
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1056
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -177
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -835
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -251
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -178
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -236
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -77
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -32
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -61
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -32
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -38
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -31
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -53
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/export.d.ts +0 -10
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -87
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -70
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/parameter.d.ts +0 -44
- package/dist/utils/parameter.d.ts.map +0 -1
- package/dist/utils/parameter.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -43
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- /package/frontend/build/static/js/{main.6ffd2c31.js.LICENSE.txt → main.819c0908.js.LICENSE.txt} +0 -0
package/dist/pluginManager.js
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the Plugins class.
|
|
3
|
-
*
|
|
4
|
-
* @file plugins.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-07-14
|
|
7
|
-
* @version 1.1.1
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2024, 2025, 2026 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, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr } from './logger/export.js';
|
|
25
2
|
import { plg, typ } from './matterbridgeTypes.js';
|
|
26
3
|
export class PluginManager {
|
|
@@ -30,9 +7,8 @@ export class PluginManager {
|
|
|
30
7
|
log;
|
|
31
8
|
constructor(matterbridge) {
|
|
32
9
|
this.matterbridge = matterbridge;
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
10
|
this.nodeContext = matterbridge.nodeContext;
|
|
35
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
11
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
|
|
36
12
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
37
13
|
}
|
|
38
14
|
get length() {
|
|
@@ -69,7 +45,6 @@ export class PluginManager {
|
|
|
69
45
|
}
|
|
70
46
|
catch (error) {
|
|
71
47
|
this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}:`, error);
|
|
72
|
-
// throw error;
|
|
73
48
|
}
|
|
74
49
|
});
|
|
75
50
|
await Promise.all(tasks);
|
|
@@ -77,31 +52,13 @@ export class PluginManager {
|
|
|
77
52
|
set logLevel(logLevel) {
|
|
78
53
|
this.log.logLevel = logLevel;
|
|
79
54
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Loads registered plugins from storage.
|
|
82
|
-
*
|
|
83
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
84
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
85
|
-
*
|
|
86
|
-
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
87
|
-
*/
|
|
88
55
|
async loadFromStorage() {
|
|
89
|
-
// Load the array from storage and convert it to a map
|
|
90
56
|
const pluginsArray = await this.nodeContext.get('plugins', []);
|
|
91
57
|
for (const plugin of pluginsArray)
|
|
92
58
|
this._plugins.set(plugin.name, plugin);
|
|
93
59
|
return pluginsArray;
|
|
94
60
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Loads registered plugins from storage.
|
|
97
|
-
*
|
|
98
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
99
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
100
|
-
*
|
|
101
|
-
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
102
|
-
*/
|
|
103
61
|
async saveToStorage() {
|
|
104
|
-
// Convert the map to an array
|
|
105
62
|
const plugins = [];
|
|
106
63
|
const pluginArrayFromMap = Array.from(this._plugins.values());
|
|
107
64
|
for (const plugin of pluginArrayFromMap) {
|
|
@@ -121,20 +78,13 @@ export class PluginManager {
|
|
|
121
78
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
122
79
|
return plugins.length;
|
|
123
80
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
126
|
-
* @param pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
127
|
-
* @returns The path to the resolved package.json file, or null if the package.json file is not found or does not contain a name.
|
|
128
|
-
*/
|
|
129
81
|
async resolve(pluginPath) {
|
|
130
82
|
const { default: path } = await import('node:path');
|
|
131
83
|
const { promises } = await import('node:fs');
|
|
132
84
|
if (!pluginPath.endsWith('package.json'))
|
|
133
85
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
134
|
-
// Resolve the package.json of the plugin
|
|
135
86
|
let packageJsonPath = path.resolve(pluginPath);
|
|
136
87
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
137
|
-
// Check if the package.json file exists
|
|
138
88
|
try {
|
|
139
89
|
await promises.access(packageJsonPath);
|
|
140
90
|
}
|
|
@@ -144,13 +94,11 @@ export class PluginManager {
|
|
|
144
94
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
145
95
|
}
|
|
146
96
|
try {
|
|
147
|
-
// Load the package.json of the plugin
|
|
148
97
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
149
98
|
if (!packageJson.name) {
|
|
150
99
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
151
100
|
return null;
|
|
152
101
|
}
|
|
153
|
-
// Check for main issues
|
|
154
102
|
if (!packageJson.type || packageJson.type !== 'module') {
|
|
155
103
|
this.log.error(`Plugin at ${packageJsonPath} is not a module`);
|
|
156
104
|
return null;
|
|
@@ -159,7 +107,6 @@ export class PluginManager {
|
|
|
159
107
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
160
108
|
return null;
|
|
161
109
|
}
|
|
162
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
163
110
|
const checkForProjectChipPackages = (dependencies) => {
|
|
164
111
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
165
112
|
};
|
|
@@ -181,7 +128,6 @@ export class PluginManager {
|
|
|
181
128
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
182
129
|
return null;
|
|
183
130
|
}
|
|
184
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
185
131
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
186
132
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
187
133
|
};
|
|
@@ -211,11 +157,6 @@ export class PluginManager {
|
|
|
211
157
|
return null;
|
|
212
158
|
}
|
|
213
159
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Loads and parse the plugin package.json and returns it.
|
|
216
|
-
* @param plugin - The plugin to load the package from.
|
|
217
|
-
* @returns A Promise that resolves to the package.json object or undefined if the package.json could not be loaded.
|
|
218
|
-
*/
|
|
219
160
|
async parse(plugin) {
|
|
220
161
|
const { promises } = await import('node:fs');
|
|
221
162
|
try {
|
|
@@ -241,7 +182,6 @@ export class PluginManager {
|
|
|
241
182
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no path`);
|
|
242
183
|
if (!plugin.type)
|
|
243
184
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
244
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
245
185
|
const checkForProjectChipPackages = (dependencies) => {
|
|
246
186
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
247
187
|
};
|
|
@@ -263,7 +203,6 @@ export class PluginManager {
|
|
|
263
203
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
264
204
|
return null;
|
|
265
205
|
}
|
|
266
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
267
206
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
268
207
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
269
208
|
};
|
|
@@ -285,7 +224,6 @@ export class PluginManager {
|
|
|
285
224
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
286
225
|
return null;
|
|
287
226
|
}
|
|
288
|
-
// await this.saveToStorage(); // No need to save the plugin to storage
|
|
289
227
|
return packageJson;
|
|
290
228
|
}
|
|
291
229
|
catch (err) {
|
|
@@ -294,16 +232,6 @@ export class PluginManager {
|
|
|
294
232
|
return null;
|
|
295
233
|
}
|
|
296
234
|
}
|
|
297
|
-
/**
|
|
298
|
-
* Enables a plugin by its name or path.
|
|
299
|
-
*
|
|
300
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
301
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
302
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
303
|
-
*
|
|
304
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
305
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
306
|
-
*/
|
|
307
235
|
async enable(nameOrPath) {
|
|
308
236
|
const { promises } = await import('node:fs');
|
|
309
237
|
if (!nameOrPath || nameOrPath === '')
|
|
@@ -337,16 +265,6 @@ export class PluginManager {
|
|
|
337
265
|
return null;
|
|
338
266
|
}
|
|
339
267
|
}
|
|
340
|
-
/**
|
|
341
|
-
* Enables a plugin by its name or path.
|
|
342
|
-
*
|
|
343
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
344
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
345
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
346
|
-
*
|
|
347
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
348
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
349
|
-
*/
|
|
350
268
|
async disable(nameOrPath) {
|
|
351
269
|
const { promises } = await import('node:fs');
|
|
352
270
|
if (!nameOrPath || nameOrPath === '')
|
|
@@ -380,16 +298,6 @@ export class PluginManager {
|
|
|
380
298
|
return null;
|
|
381
299
|
}
|
|
382
300
|
}
|
|
383
|
-
/**
|
|
384
|
-
* Removes a plugin by its name or path.
|
|
385
|
-
*
|
|
386
|
-
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
387
|
-
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
388
|
-
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
389
|
-
*
|
|
390
|
-
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
391
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
392
|
-
*/
|
|
393
301
|
async remove(nameOrPath) {
|
|
394
302
|
const { promises } = await import('node:fs');
|
|
395
303
|
if (!nameOrPath || nameOrPath === '')
|
|
@@ -423,17 +331,6 @@ export class PluginManager {
|
|
|
423
331
|
return null;
|
|
424
332
|
}
|
|
425
333
|
}
|
|
426
|
-
/**
|
|
427
|
-
* Adds a plugin by its name or path.
|
|
428
|
-
*
|
|
429
|
-
* This method adds a plugin to the `_plugins` map and saves the updated plugin information to storage.
|
|
430
|
-
* It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
|
|
431
|
-
* registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
|
|
432
|
-
* and saves the updated plugin information to storage.
|
|
433
|
-
*
|
|
434
|
-
* @param {string} nameOrPath - The name or path of the plugin to add.
|
|
435
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
|
|
436
|
-
*/
|
|
437
334
|
async add(nameOrPath) {
|
|
438
335
|
const { promises } = await import('node:fs');
|
|
439
336
|
if (!nameOrPath || nameOrPath === '')
|
|
@@ -460,15 +357,6 @@ export class PluginManager {
|
|
|
460
357
|
return null;
|
|
461
358
|
}
|
|
462
359
|
}
|
|
463
|
-
/**
|
|
464
|
-
* Installs a plugin by its name.
|
|
465
|
-
*
|
|
466
|
-
* This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
|
|
467
|
-
* It logs the installation process and retrieves the installed version of the plugin.
|
|
468
|
-
*
|
|
469
|
-
* @param {string} name - The name of the plugin to install.
|
|
470
|
-
* @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
|
|
471
|
-
*/
|
|
472
360
|
async install(name) {
|
|
473
361
|
const { exec } = await import('node:child_process');
|
|
474
362
|
await this.uninstall(name);
|
|
@@ -483,14 +371,11 @@ export class PluginManager {
|
|
|
483
371
|
else {
|
|
484
372
|
this.log.info(`Installed plugin ${plg}${name}${nf}`);
|
|
485
373
|
this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
|
|
486
|
-
// Get the installed version
|
|
487
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
488
374
|
exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
|
|
489
375
|
if (listError) {
|
|
490
376
|
this.log.error(`List error: ${listError}`);
|
|
491
377
|
resolve(undefined);
|
|
492
378
|
}
|
|
493
|
-
// Clean the output to get only the package name and version
|
|
494
379
|
const lines = listStdout.split('\n');
|
|
495
380
|
const versionLine = lines.find((line) => line.includes(`${name}@`));
|
|
496
381
|
if (versionLine) {
|
|
@@ -506,15 +391,6 @@ export class PluginManager {
|
|
|
506
391
|
});
|
|
507
392
|
});
|
|
508
393
|
}
|
|
509
|
-
/**
|
|
510
|
-
* Uninstalls a plugin by its name.
|
|
511
|
-
*
|
|
512
|
-
* This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
|
|
513
|
-
* and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
|
|
514
|
-
*
|
|
515
|
-
* @param {string} name - The name of the plugin to uninstall.
|
|
516
|
-
* @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
|
|
517
|
-
*/
|
|
518
394
|
async uninstall(name) {
|
|
519
395
|
const { exec } = await import('node:child_process');
|
|
520
396
|
this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
|
|
@@ -533,14 +409,6 @@ export class PluginManager {
|
|
|
533
409
|
});
|
|
534
410
|
});
|
|
535
411
|
}
|
|
536
|
-
/**
|
|
537
|
-
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
538
|
-
* @param plugin - The plugin to load.
|
|
539
|
-
* @param start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
540
|
-
* @param message - Optional message to pass to the plugin when starting.
|
|
541
|
-
* @returns A Promise that resolves to the loaded MatterbridgePlatform instance.
|
|
542
|
-
* @throws An error if the plugin is not enabled, already loaded, or fails to load.
|
|
543
|
-
*/
|
|
544
412
|
async load(plugin, start = false, message = '', configure = false) {
|
|
545
413
|
const { promises } = await import('node:fs');
|
|
546
414
|
const { default: path } = await import('node:path');
|
|
@@ -554,20 +422,15 @@ export class PluginManager {
|
|
|
554
422
|
}
|
|
555
423
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
556
424
|
try {
|
|
557
|
-
// Load the package.json of the plugin
|
|
558
425
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
559
|
-
// Resolve the main module path relative to package.json
|
|
560
426
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
561
|
-
// Dynamically import the plugin
|
|
562
427
|
const { pathToFileURL } = await import('node:url');
|
|
563
428
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
564
429
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
565
430
|
const pluginInstance = await import(pluginUrl.href);
|
|
566
431
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
567
|
-
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
568
432
|
if (pluginInstance.default) {
|
|
569
433
|
const config = await this.loadConfig(plugin);
|
|
570
|
-
// Preset the plugin properties here in case the plugin throws an error during loading. In this case the user can change the config and restart the plugin.
|
|
571
434
|
plugin.name = packageJson.name;
|
|
572
435
|
plugin.description = packageJson.description ?? 'No description';
|
|
573
436
|
plugin.version = packageJson.version;
|
|
@@ -576,7 +439,7 @@ export class PluginManager {
|
|
|
576
439
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
577
440
|
config.name = plugin.name;
|
|
578
441
|
config.version = packageJson.version;
|
|
579
|
-
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4
|
|
442
|
+
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
580
443
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
581
444
|
config.type = platform.type;
|
|
582
445
|
platform.name = packageJson.name;
|
|
@@ -591,9 +454,7 @@ export class PluginManager {
|
|
|
591
454
|
plugin.loaded = true;
|
|
592
455
|
plugin.registeredDevices = 0;
|
|
593
456
|
plugin.addedDevices = 0;
|
|
594
|
-
|
|
595
|
-
// plugin.schemaJson = await this.loadSchema(plugin);
|
|
596
|
-
await this.saveToStorage(); // Save the plugin to storage
|
|
457
|
+
await this.saveToStorage();
|
|
597
458
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
598
459
|
if (start)
|
|
599
460
|
await this.start(plugin, message, false);
|
|
@@ -612,14 +473,6 @@ export class PluginManager {
|
|
|
612
473
|
}
|
|
613
474
|
return undefined;
|
|
614
475
|
}
|
|
615
|
-
/**
|
|
616
|
-
* Starts a plugin.
|
|
617
|
-
*
|
|
618
|
-
* @param {RegisteredPlugin} plugin - The plugin to start.
|
|
619
|
-
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
620
|
-
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
621
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
622
|
-
*/
|
|
623
476
|
async start(plugin, message, configure = false) {
|
|
624
477
|
if (!plugin.loaded) {
|
|
625
478
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -649,12 +502,6 @@ export class PluginManager {
|
|
|
649
502
|
}
|
|
650
503
|
return undefined;
|
|
651
504
|
}
|
|
652
|
-
/**
|
|
653
|
-
* Configures a plugin.
|
|
654
|
-
*
|
|
655
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
656
|
-
* @returns {Promise<void>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
657
|
-
*/
|
|
658
505
|
async configure(plugin) {
|
|
659
506
|
if (!plugin.loaded) {
|
|
660
507
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -685,18 +532,6 @@ export class PluginManager {
|
|
|
685
532
|
}
|
|
686
533
|
return undefined;
|
|
687
534
|
}
|
|
688
|
-
/**
|
|
689
|
-
* Shuts down a plugin.
|
|
690
|
-
*
|
|
691
|
-
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
692
|
-
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
693
|
-
*
|
|
694
|
-
* @param {RegisteredPlugin} plugin - The plugin to shut down.
|
|
695
|
-
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
696
|
-
* @param {boolean} [removeAllDevices=false] - Whether to remove all devices associated with the plugin.
|
|
697
|
-
* @param {boolean} [force=false] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
698
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
699
|
-
*/
|
|
700
535
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
701
536
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
702
537
|
if (!plugin.loaded) {
|
|
@@ -739,15 +574,6 @@ export class PluginManager {
|
|
|
739
574
|
}
|
|
740
575
|
return undefined;
|
|
741
576
|
}
|
|
742
|
-
/**
|
|
743
|
-
* Loads the configuration for a plugin.
|
|
744
|
-
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
745
|
-
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
746
|
-
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
747
|
-
*
|
|
748
|
-
* @param plugin - The plugin for which to load the configuration.
|
|
749
|
-
* @returns A promise that resolves to the loaded or created configuration.
|
|
750
|
-
*/
|
|
751
577
|
async loadConfig(plugin) {
|
|
752
578
|
const { default: path } = await import('node:path');
|
|
753
579
|
const { promises } = await import('node:fs');
|
|
@@ -758,8 +584,6 @@ export class PluginManager {
|
|
|
758
584
|
const data = await promises.readFile(configFile, 'utf8');
|
|
759
585
|
const config = JSON.parse(data);
|
|
760
586
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
761
|
-
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
762
|
-
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
763
587
|
config.name = plugin.name;
|
|
764
588
|
config.type = plugin.type;
|
|
765
589
|
if (config.debug === undefined)
|
|
@@ -783,7 +607,6 @@ export class PluginManager {
|
|
|
783
607
|
try {
|
|
784
608
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
785
609
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
786
|
-
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
787
610
|
return config;
|
|
788
611
|
}
|
|
789
612
|
catch (err) {
|
|
@@ -797,18 +620,6 @@ export class PluginManager {
|
|
|
797
620
|
}
|
|
798
621
|
}
|
|
799
622
|
}
|
|
800
|
-
/**
|
|
801
|
-
* Saves the configuration of a plugin to a file.
|
|
802
|
-
*
|
|
803
|
-
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
804
|
-
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
805
|
-
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
806
|
-
* the error and rejects the promise.
|
|
807
|
-
*
|
|
808
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
809
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
810
|
-
* @throws {Error} If the plugin's configuration is not found.
|
|
811
|
-
*/
|
|
812
623
|
async saveConfigFromPlugin(plugin) {
|
|
813
624
|
const { default: path } = await import('node:path');
|
|
814
625
|
const { promises } = await import('node:fs');
|
|
@@ -821,7 +632,6 @@ export class PluginManager {
|
|
|
821
632
|
await promises.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
|
|
822
633
|
plugin.configJson = plugin.platform.config;
|
|
823
634
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
824
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
825
635
|
return Promise.resolve();
|
|
826
636
|
}
|
|
827
637
|
catch (err) {
|
|
@@ -829,19 +639,6 @@ export class PluginManager {
|
|
|
829
639
|
return Promise.reject(err);
|
|
830
640
|
}
|
|
831
641
|
}
|
|
832
|
-
/**
|
|
833
|
-
* Saves the configuration of a plugin from a JSON object to a file.
|
|
834
|
-
*
|
|
835
|
-
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
836
|
-
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
837
|
-
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
838
|
-
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
839
|
-
* during the file write operation, it logs the error and returns.
|
|
840
|
-
*
|
|
841
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
842
|
-
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
843
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
844
|
-
*/
|
|
845
642
|
async saveConfigFromJson(plugin, config) {
|
|
846
643
|
const { default: path } = await import('node:path');
|
|
847
644
|
const { promises } = await import('node:fs');
|
|
@@ -856,23 +653,12 @@ export class PluginManager {
|
|
|
856
653
|
if (plugin.platform)
|
|
857
654
|
plugin.platform.config = config;
|
|
858
655
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
859
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
860
656
|
}
|
|
861
657
|
catch (err) {
|
|
862
658
|
this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err}`);
|
|
863
659
|
return;
|
|
864
660
|
}
|
|
865
661
|
}
|
|
866
|
-
/**
|
|
867
|
-
* Loads the schema for a plugin.
|
|
868
|
-
*
|
|
869
|
-
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
870
|
-
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
871
|
-
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
872
|
-
*
|
|
873
|
-
* @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
|
|
874
|
-
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
875
|
-
*/
|
|
876
662
|
async loadSchema(plugin) {
|
|
877
663
|
const { promises } = await import('node:fs');
|
|
878
664
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -883,7 +669,6 @@ export class PluginManager {
|
|
|
883
669
|
schema.title = plugin.description;
|
|
884
670
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
885
671
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
886
|
-
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
887
672
|
return schema;
|
|
888
673
|
}
|
|
889
674
|
catch (error) {
|
|
@@ -891,16 +676,6 @@ export class PluginManager {
|
|
|
891
676
|
return this.getDefaultSchema(plugin);
|
|
892
677
|
}
|
|
893
678
|
}
|
|
894
|
-
/**
|
|
895
|
-
* Returns the default schema for a plugin.
|
|
896
|
-
*
|
|
897
|
-
* This method generates a default schema object for the specified plugin. The schema includes
|
|
898
|
-
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
899
|
-
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
900
|
-
*
|
|
901
|
-
* @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
|
|
902
|
-
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
903
|
-
*/
|
|
904
679
|
getDefaultSchema(plugin) {
|
|
905
680
|
return {
|
|
906
681
|
title: plugin.description,
|
|
@@ -931,4 +706,3 @@ export class PluginManager {
|
|
|
931
706
|
};
|
|
932
707
|
}
|
|
933
708
|
}
|
|
934
|
-
//# sourceMappingURL=pluginManager.js.map
|