matterbridge 2.1.5 → 2.1.6-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 +17 -0
- package/README-DOCKER.md +17 -7
- package/dist/cli.js +0 -26
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +55 -280
- package/dist/index.js +0 -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 +68 -765
- 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 -117
- package/dist/matterbridgePlatform.js +56 -131
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -230
- package/dist/storage/export.js +0 -1
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/export.js +0 -1
- package/dist/utils/utils.js +10 -264
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.cd192588.js → main.a241d4f0.js} +9 -9
- package/frontend/build/static/js/main.a241d4f0.js.map +1 -0
- package/npm-shrinkwrap.json +50 -50
- package/package.json +2 -3
- package/dist/cli.d.ts +0 -25
- 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 -143
- 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 -409
- 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 -159
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -169
- 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/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/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/export.d.ts +0 -3
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -231
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js.map +0 -1
- package/frontend/build/static/js/main.cd192588.js.map +0 -1
- /package/frontend/build/static/js/{main.cd192588.js.LICENSE.txt → main.a241d4f0.js.LICENSE.txt} +0 -0
package/dist/pluginManager.js
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
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.0
|
|
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
|
-
// NodeStorage and AnsiLogger modules
|
|
24
1
|
import { AnsiLogger, BLUE, db, er, nf, nt, rs, UNDERLINE, UNDERLINEOFF, wr } from './logger/export.js';
|
|
25
|
-
// Node.js modules
|
|
26
2
|
import path from 'path';
|
|
27
3
|
import { promises as fs } from 'fs';
|
|
28
4
|
import { pathToFileURL } from 'url';
|
|
@@ -36,9 +12,8 @@ export class PluginManager {
|
|
|
36
12
|
log;
|
|
37
13
|
constructor(matterbridge) {
|
|
38
14
|
this.matterbridge = matterbridge;
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
15
|
this.nodeContext = matterbridge.nodeContext;
|
|
41
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
16
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
|
|
42
17
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
43
18
|
}
|
|
44
19
|
get length() {
|
|
@@ -75,7 +50,6 @@ export class PluginManager {
|
|
|
75
50
|
}
|
|
76
51
|
catch (error) {
|
|
77
52
|
this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}:`, error);
|
|
78
|
-
// throw error;
|
|
79
53
|
}
|
|
80
54
|
});
|
|
81
55
|
await Promise.all(tasks);
|
|
@@ -83,31 +57,13 @@ export class PluginManager {
|
|
|
83
57
|
set logLevel(logLevel) {
|
|
84
58
|
this.log.logLevel = logLevel;
|
|
85
59
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Loads registered plugins from storage.
|
|
88
|
-
*
|
|
89
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
90
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
91
|
-
*
|
|
92
|
-
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
93
|
-
*/
|
|
94
60
|
async loadFromStorage() {
|
|
95
|
-
// Load the array from storage and convert it to a map
|
|
96
61
|
const pluginsArray = await this.nodeContext.get('plugins', []);
|
|
97
62
|
for (const plugin of pluginsArray)
|
|
98
63
|
this._plugins.set(plugin.name, plugin);
|
|
99
64
|
return pluginsArray;
|
|
100
65
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Loads registered plugins from storage.
|
|
103
|
-
*
|
|
104
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
105
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
106
|
-
*
|
|
107
|
-
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
108
|
-
*/
|
|
109
66
|
async saveToStorage() {
|
|
110
|
-
// Convert the map to an array
|
|
111
67
|
const plugins = [];
|
|
112
68
|
const pluginArrayFromMap = Array.from(this._plugins.values());
|
|
113
69
|
for (const plugin of pluginArrayFromMap) {
|
|
@@ -127,18 +83,11 @@ export class PluginManager {
|
|
|
127
83
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
128
84
|
return plugins.length;
|
|
129
85
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
132
|
-
* @param pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
133
|
-
* @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.
|
|
134
|
-
*/
|
|
135
86
|
async resolve(pluginPath) {
|
|
136
87
|
if (!pluginPath.endsWith('package.json'))
|
|
137
88
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
138
|
-
// Resolve the package.json of the plugin
|
|
139
89
|
let packageJsonPath = path.resolve(pluginPath);
|
|
140
90
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
141
|
-
// Check if the package.json file exists
|
|
142
91
|
try {
|
|
143
92
|
await fs.access(packageJsonPath);
|
|
144
93
|
}
|
|
@@ -148,13 +97,11 @@ export class PluginManager {
|
|
|
148
97
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
149
98
|
}
|
|
150
99
|
try {
|
|
151
|
-
// Load the package.json of the plugin
|
|
152
100
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
|
|
153
101
|
if (!packageJson.name) {
|
|
154
102
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
155
103
|
return null;
|
|
156
104
|
}
|
|
157
|
-
// Check for main issues
|
|
158
105
|
if (!packageJson.type || packageJson.type !== 'module') {
|
|
159
106
|
this.log.error(`Plugin at ${packageJsonPath} is not a module`);
|
|
160
107
|
return null;
|
|
@@ -163,7 +110,6 @@ export class PluginManager {
|
|
|
163
110
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
164
111
|
return null;
|
|
165
112
|
}
|
|
166
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
167
113
|
const checkForProjectChipPackages = (dependencies) => {
|
|
168
114
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
169
115
|
};
|
|
@@ -185,7 +131,6 @@ export class PluginManager {
|
|
|
185
131
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
186
132
|
return null;
|
|
187
133
|
}
|
|
188
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
189
134
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
190
135
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
191
136
|
};
|
|
@@ -215,11 +160,6 @@ export class PluginManager {
|
|
|
215
160
|
return null;
|
|
216
161
|
}
|
|
217
162
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Loads and parse the plugin package.json and returns it.
|
|
220
|
-
* @param plugin - The plugin to load the package from.
|
|
221
|
-
* @returns A Promise that resolves to the package.json object or undefined if the package.json could not be loaded.
|
|
222
|
-
*/
|
|
223
163
|
async parse(plugin) {
|
|
224
164
|
this.log.debug(`Parsing package.json of plugin ${plg}${plugin.name}${db}`);
|
|
225
165
|
try {
|
|
@@ -244,7 +184,6 @@ export class PluginManager {
|
|
|
244
184
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no path`);
|
|
245
185
|
if (!plugin.type)
|
|
246
186
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
247
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
248
187
|
const checkForProjectChipPackages = (dependencies) => {
|
|
249
188
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
250
189
|
};
|
|
@@ -266,7 +205,6 @@ export class PluginManager {
|
|
|
266
205
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
267
206
|
return null;
|
|
268
207
|
}
|
|
269
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
270
208
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
271
209
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
272
210
|
};
|
|
@@ -288,7 +226,6 @@ export class PluginManager {
|
|
|
288
226
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
289
227
|
return null;
|
|
290
228
|
}
|
|
291
|
-
// await this.saveToStorage(); // No need to save the plugin to storage
|
|
292
229
|
return packageJson;
|
|
293
230
|
}
|
|
294
231
|
catch (err) {
|
|
@@ -297,16 +234,6 @@ export class PluginManager {
|
|
|
297
234
|
return null;
|
|
298
235
|
}
|
|
299
236
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Enables a plugin by its name or path.
|
|
302
|
-
*
|
|
303
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
304
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
305
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
306
|
-
*
|
|
307
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
308
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
309
|
-
*/
|
|
310
237
|
async enable(nameOrPath) {
|
|
311
238
|
if (!nameOrPath || nameOrPath === '')
|
|
312
239
|
return null;
|
|
@@ -339,16 +266,6 @@ export class PluginManager {
|
|
|
339
266
|
return null;
|
|
340
267
|
}
|
|
341
268
|
}
|
|
342
|
-
/**
|
|
343
|
-
* Enables a plugin by its name or path.
|
|
344
|
-
*
|
|
345
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
346
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
347
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
348
|
-
*
|
|
349
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
350
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
351
|
-
*/
|
|
352
269
|
async disable(nameOrPath) {
|
|
353
270
|
if (!nameOrPath || nameOrPath === '')
|
|
354
271
|
return null;
|
|
@@ -381,16 +298,6 @@ export class PluginManager {
|
|
|
381
298
|
return null;
|
|
382
299
|
}
|
|
383
300
|
}
|
|
384
|
-
/**
|
|
385
|
-
* Removes a plugin by its name or path.
|
|
386
|
-
*
|
|
387
|
-
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
388
|
-
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
389
|
-
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
390
|
-
*
|
|
391
|
-
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
392
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
393
|
-
*/
|
|
394
301
|
async remove(nameOrPath) {
|
|
395
302
|
if (!nameOrPath || nameOrPath === '')
|
|
396
303
|
return null;
|
|
@@ -423,17 +330,6 @@ export class PluginManager {
|
|
|
423
330
|
return null;
|
|
424
331
|
}
|
|
425
332
|
}
|
|
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
333
|
async add(nameOrPath) {
|
|
438
334
|
if (!nameOrPath || nameOrPath === '')
|
|
439
335
|
return null;
|
|
@@ -459,19 +355,9 @@ export class PluginManager {
|
|
|
459
355
|
return null;
|
|
460
356
|
}
|
|
461
357
|
}
|
|
462
|
-
/**
|
|
463
|
-
* Installs a plugin by its name.
|
|
464
|
-
*
|
|
465
|
-
* This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
|
|
466
|
-
* It logs the installation process and retrieves the installed version of the plugin.
|
|
467
|
-
*
|
|
468
|
-
* @param {string} name - The name of the plugin to install.
|
|
469
|
-
* @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
|
|
470
|
-
*/
|
|
471
358
|
async install(name) {
|
|
472
359
|
await this.uninstall(name);
|
|
473
360
|
this.log.info(`Installing plugin ${plg}${name}${nf}`);
|
|
474
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
475
361
|
return new Promise((resolve, reject) => {
|
|
476
362
|
exec(`npm install -g ${name} --omit=dev --force`, (error, stdout, stderr) => {
|
|
477
363
|
if (error) {
|
|
@@ -482,14 +368,11 @@ export class PluginManager {
|
|
|
482
368
|
else {
|
|
483
369
|
this.log.info(`Installed plugin ${plg}${name}${nf}`);
|
|
484
370
|
this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
|
|
485
|
-
// Get the installed version
|
|
486
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
487
371
|
exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
|
|
488
372
|
if (listError) {
|
|
489
373
|
this.log.error(`List error: ${listError}`);
|
|
490
374
|
resolve(undefined);
|
|
491
375
|
}
|
|
492
|
-
// Clean the output to get only the package name and version
|
|
493
376
|
const lines = listStdout.split('\n');
|
|
494
377
|
const versionLine = lines.find((line) => line.includes(`${name}@`));
|
|
495
378
|
if (versionLine) {
|
|
@@ -505,18 +388,8 @@ export class PluginManager {
|
|
|
505
388
|
});
|
|
506
389
|
});
|
|
507
390
|
}
|
|
508
|
-
/**
|
|
509
|
-
* Uninstalls a plugin by its name.
|
|
510
|
-
*
|
|
511
|
-
* This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
|
|
512
|
-
* and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
|
|
513
|
-
*
|
|
514
|
-
* @param {string} name - The name of the plugin to uninstall.
|
|
515
|
-
* @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
|
|
516
|
-
*/
|
|
517
391
|
async uninstall(name) {
|
|
518
392
|
this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
|
|
519
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
520
393
|
return new Promise((resolve, reject) => {
|
|
521
394
|
exec(`npm uninstall -g ${name} --force`, (error, stdout, stderr) => {
|
|
522
395
|
if (error) {
|
|
@@ -532,14 +405,6 @@ export class PluginManager {
|
|
|
532
405
|
});
|
|
533
406
|
});
|
|
534
407
|
}
|
|
535
|
-
/**
|
|
536
|
-
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
537
|
-
* @param plugin - The plugin to load.
|
|
538
|
-
* @param start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
539
|
-
* @param message - Optional message to pass to the plugin when starting.
|
|
540
|
-
* @returns A Promise that resolves to the loaded MatterbridgePlatform instance.
|
|
541
|
-
* @throws An error if the plugin is not enabled, already loaded, or fails to load.
|
|
542
|
-
*/
|
|
543
408
|
async load(plugin, start = false, message = '', configure = false) {
|
|
544
409
|
if (!plugin.enabled) {
|
|
545
410
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not enabled`);
|
|
@@ -551,19 +416,14 @@ export class PluginManager {
|
|
|
551
416
|
}
|
|
552
417
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
553
418
|
try {
|
|
554
|
-
// Load the package.json of the plugin
|
|
555
419
|
const packageJson = JSON.parse(await fs.readFile(plugin.path, 'utf8'));
|
|
556
|
-
// Resolve the main module path relative to package.json
|
|
557
420
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
558
|
-
// Dynamically import the plugin
|
|
559
421
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
560
422
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
561
423
|
const pluginInstance = await import(pluginUrl.href);
|
|
562
424
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
563
|
-
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
564
425
|
if (pluginInstance.default) {
|
|
565
426
|
const config = await this.loadConfig(plugin);
|
|
566
|
-
// 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.
|
|
567
427
|
plugin.name = packageJson.name;
|
|
568
428
|
plugin.description = packageJson.description ?? 'No description';
|
|
569
429
|
plugin.version = packageJson.version;
|
|
@@ -572,7 +432,7 @@ export class PluginManager {
|
|
|
572
432
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
573
433
|
config.name = plugin.name;
|
|
574
434
|
config.version = packageJson.version;
|
|
575
|
-
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4
|
|
435
|
+
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
576
436
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
577
437
|
config.type = platform.type;
|
|
578
438
|
platform.name = packageJson.name;
|
|
@@ -589,7 +449,7 @@ export class PluginManager {
|
|
|
589
449
|
plugin.addedDevices = 0;
|
|
590
450
|
plugin.configJson = config;
|
|
591
451
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
592
|
-
await this.saveToStorage();
|
|
452
|
+
await this.saveToStorage();
|
|
593
453
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
594
454
|
if (start)
|
|
595
455
|
await this.start(plugin, message, false);
|
|
@@ -608,14 +468,6 @@ export class PluginManager {
|
|
|
608
468
|
}
|
|
609
469
|
return undefined;
|
|
610
470
|
}
|
|
611
|
-
/**
|
|
612
|
-
* Starts a plugin.
|
|
613
|
-
*
|
|
614
|
-
* @param {RegisteredPlugin} plugin - The plugin to start.
|
|
615
|
-
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
616
|
-
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
617
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
618
|
-
*/
|
|
619
471
|
async start(plugin, message, configure = false) {
|
|
620
472
|
if (!plugin.loaded) {
|
|
621
473
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -645,12 +497,6 @@ export class PluginManager {
|
|
|
645
497
|
}
|
|
646
498
|
return undefined;
|
|
647
499
|
}
|
|
648
|
-
/**
|
|
649
|
-
* Configures a plugin.
|
|
650
|
-
*
|
|
651
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
652
|
-
* @returns {Promise<void>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
653
|
-
*/
|
|
654
500
|
async configure(plugin) {
|
|
655
501
|
if (!plugin.loaded) {
|
|
656
502
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -681,18 +527,6 @@ export class PluginManager {
|
|
|
681
527
|
}
|
|
682
528
|
return undefined;
|
|
683
529
|
}
|
|
684
|
-
/**
|
|
685
|
-
* Shuts down a plugin.
|
|
686
|
-
*
|
|
687
|
-
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
688
|
-
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
689
|
-
*
|
|
690
|
-
* @param {RegisteredPlugin} plugin - The plugin to shut down.
|
|
691
|
-
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
692
|
-
* @param {boolean} [removeAllDevices=false] - Whether to remove all devices associated with the plugin.
|
|
693
|
-
* @param {boolean} [force=false] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
694
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
695
|
-
*/
|
|
696
530
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
697
531
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
698
532
|
if (!plugin.loaded) {
|
|
@@ -735,15 +569,6 @@ export class PluginManager {
|
|
|
735
569
|
}
|
|
736
570
|
return undefined;
|
|
737
571
|
}
|
|
738
|
-
/**
|
|
739
|
-
* Loads the configuration for a plugin.
|
|
740
|
-
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
741
|
-
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
742
|
-
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
743
|
-
*
|
|
744
|
-
* @param plugin - The plugin for which to load the configuration.
|
|
745
|
-
* @returns A promise that resolves to the loaded or created configuration.
|
|
746
|
-
*/
|
|
747
572
|
async loadConfig(plugin) {
|
|
748
573
|
const configFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.config.json`);
|
|
749
574
|
try {
|
|
@@ -751,8 +576,6 @@ export class PluginManager {
|
|
|
751
576
|
const data = await fs.readFile(configFile, 'utf8');
|
|
752
577
|
const config = JSON.parse(data);
|
|
753
578
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
754
|
-
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
755
|
-
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
756
579
|
config.name = plugin.name;
|
|
757
580
|
config.type = plugin.type;
|
|
758
581
|
if (config.debug === undefined)
|
|
@@ -777,7 +600,6 @@ export class PluginManager {
|
|
|
777
600
|
try {
|
|
778
601
|
await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
779
602
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
780
|
-
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
781
603
|
return config;
|
|
782
604
|
}
|
|
783
605
|
catch (err) {
|
|
@@ -794,18 +616,6 @@ export class PluginManager {
|
|
|
794
616
|
return { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
|
|
795
617
|
}
|
|
796
618
|
}
|
|
797
|
-
/**
|
|
798
|
-
* Saves the configuration of a plugin to a file.
|
|
799
|
-
*
|
|
800
|
-
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
801
|
-
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
802
|
-
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
803
|
-
* the error and rejects the promise.
|
|
804
|
-
*
|
|
805
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
806
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
807
|
-
* @throws {Error} If the plugin's configuration is not found.
|
|
808
|
-
*/
|
|
809
619
|
async saveConfigFromPlugin(plugin) {
|
|
810
620
|
if (!plugin.platform?.config) {
|
|
811
621
|
this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}: config not found`);
|
|
@@ -815,7 +625,6 @@ export class PluginManager {
|
|
|
815
625
|
try {
|
|
816
626
|
await fs.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
|
|
817
627
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
818
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
819
628
|
return Promise.resolve();
|
|
820
629
|
}
|
|
821
630
|
catch (err) {
|
|
@@ -823,19 +632,6 @@ export class PluginManager {
|
|
|
823
632
|
return Promise.reject(err);
|
|
824
633
|
}
|
|
825
634
|
}
|
|
826
|
-
/**
|
|
827
|
-
* Saves the configuration of a plugin from a JSON object to a file.
|
|
828
|
-
*
|
|
829
|
-
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
830
|
-
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
831
|
-
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
832
|
-
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
833
|
-
* during the file write operation, it logs the error and returns.
|
|
834
|
-
*
|
|
835
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
836
|
-
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
837
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
838
|
-
*/
|
|
839
635
|
async saveConfigFromJson(plugin, config) {
|
|
840
636
|
if (!config.name || !config.type || config.name !== plugin.name) {
|
|
841
637
|
this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}. Wrong config data content:${rs}\n`, config);
|
|
@@ -846,23 +642,12 @@ export class PluginManager {
|
|
|
846
642
|
await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
847
643
|
plugin.configJson = config;
|
|
848
644
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
849
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
850
645
|
}
|
|
851
646
|
catch (err) {
|
|
852
647
|
this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err}`);
|
|
853
648
|
return;
|
|
854
649
|
}
|
|
855
650
|
}
|
|
856
|
-
/**
|
|
857
|
-
* Loads the schema for a plugin.
|
|
858
|
-
*
|
|
859
|
-
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
860
|
-
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
861
|
-
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
862
|
-
*
|
|
863
|
-
* @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
|
|
864
|
-
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
865
|
-
*/
|
|
866
651
|
async loadSchema(plugin) {
|
|
867
652
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
868
653
|
try {
|
|
@@ -872,7 +657,6 @@ export class PluginManager {
|
|
|
872
657
|
schema.title = plugin.description;
|
|
873
658
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
874
659
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
875
|
-
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
876
660
|
return schema;
|
|
877
661
|
}
|
|
878
662
|
catch (error) {
|
|
@@ -880,16 +664,6 @@ export class PluginManager {
|
|
|
880
664
|
return this.getDefaultSchema(plugin);
|
|
881
665
|
}
|
|
882
666
|
}
|
|
883
|
-
/**
|
|
884
|
-
* Returns the default schema for a plugin.
|
|
885
|
-
*
|
|
886
|
-
* This method generates a default schema object for the specified plugin. The schema includes
|
|
887
|
-
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
888
|
-
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
889
|
-
*
|
|
890
|
-
* @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
|
|
891
|
-
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
892
|
-
*/
|
|
893
667
|
getDefaultSchema(plugin) {
|
|
894
668
|
return {
|
|
895
669
|
title: plugin.description,
|
|
@@ -920,4 +694,3 @@ export class PluginManager {
|
|
|
920
694
|
};
|
|
921
695
|
}
|
|
922
696
|
}
|
|
923
|
-
//# sourceMappingURL=pluginManager.js.map
|
package/dist/storage/export.js
CHANGED