matterbridge 3.1.2-dev-20250707-800ff6d → 3.1.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 +0 -1
- package/dist/cli.d.ts +26 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +91 -2
- package/dist/cli.js.map +1 -0
- package/dist/cliEmitter.d.ts +34 -0
- package/dist/cliEmitter.d.ts.map +1 -0
- package/dist/cliEmitter.js +30 -0
- package/dist/cliEmitter.js.map +1 -0
- package/dist/clusters/export.d.ts +2 -0
- package/dist/clusters/export.d.ts.map +1 -0
- package/dist/clusters/export.js +2 -0
- package/dist/clusters/export.js.map +1 -0
- package/dist/defaultConfigSchema.d.ts +28 -0
- package/dist/defaultConfigSchema.d.ts.map +1 -0
- package/dist/defaultConfigSchema.js +24 -0
- package/dist/defaultConfigSchema.js.map +1 -0
- package/dist/deviceManager.d.ts +112 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +94 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/batteryStorage.d.ts +48 -0
- package/dist/devices/batteryStorage.d.ts.map +1 -0
- package/dist/devices/batteryStorage.js +48 -1
- package/dist/devices/batteryStorage.js.map +1 -0
- package/dist/devices/evse.d.ts +75 -0
- package/dist/devices/evse.d.ts.map +1 -0
- package/dist/devices/evse.js +74 -10
- package/dist/devices/evse.js.map +1 -0
- package/dist/devices/export.d.ts +9 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +2 -0
- package/dist/devices/export.js.map +1 -0
- package/dist/devices/heatPump.d.ts +47 -0
- package/dist/devices/heatPump.d.ts.map +1 -0
- package/dist/devices/heatPump.js +50 -2
- package/dist/devices/heatPump.js.map +1 -0
- package/dist/devices/laundryDryer.d.ts +87 -0
- package/dist/devices/laundryDryer.d.ts.map +1 -0
- package/dist/devices/laundryDryer.js +83 -6
- package/dist/devices/laundryDryer.js.map +1 -0
- package/dist/devices/laundryWasher.d.ts +242 -0
- package/dist/devices/laundryWasher.d.ts.map +1 -0
- package/dist/devices/laundryWasher.js +91 -7
- package/dist/devices/laundryWasher.js.map +1 -0
- package/dist/devices/roboticVacuumCleaner.d.ts +110 -0
- package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
- package/dist/devices/roboticVacuumCleaner.js +89 -6
- package/dist/devices/roboticVacuumCleaner.js.map +1 -0
- package/dist/devices/solarPower.d.ts +40 -0
- package/dist/devices/solarPower.d.ts.map +1 -0
- package/dist/devices/solarPower.js +38 -0
- package/dist/devices/solarPower.js.map +1 -0
- package/dist/devices/waterHeater.d.ts +111 -0
- package/dist/devices/waterHeater.d.ts.map +1 -0
- package/dist/devices/waterHeater.js +82 -2
- package/dist/devices/waterHeater.js.map +1 -0
- package/dist/frontend.d.ts +303 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +417 -16
- package/dist/frontend.js.map +1 -0
- package/dist/globalMatterbridge.d.ts +59 -0
- package/dist/globalMatterbridge.d.ts.map +1 -0
- package/dist/globalMatterbridge.js +47 -0
- package/dist/globalMatterbridge.js.map +1 -0
- package/dist/helpers.d.ts +48 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +53 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -0
- package/dist/logger/export.d.ts +2 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +2 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +2 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +2 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +2 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +5 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +3 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +3 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +3 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterbridge.d.ts +450 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +802 -50
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +42 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +36 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +1340 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +61 -1
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +709 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +579 -15
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +42 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +36 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1196 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1053 -42
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +3198 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +322 -12
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +310 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +233 -0
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +192 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +25 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +291 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +269 -3
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +174 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +168 -7
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +2 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +59 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +54 -0
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +117 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +263 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/commandLine.d.ts +59 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +54 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +33 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +38 -1
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createDirectory.d.ts +34 -0
- package/dist/utils/createDirectory.d.ts.map +1 -0
- package/dist/utils/createDirectory.js +33 -0
- package/dist/utils/createDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +39 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +47 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +32 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +39 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +54 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +72 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/export.d.ts +12 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/hex.d.ts +49 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +58 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/isvalid.d.ts +103 -0
- package/dist/utils/isvalid.d.ts.map +1 -0
- package/dist/utils/isvalid.js +101 -0
- package/dist/utils/isvalid.js.map +1 -0
- package/dist/utils/network.d.ts +76 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +83 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/spawn.d.ts +11 -0
- package/dist/utils/spawn.d.ts.map +1 -0
- package/dist/utils/spawn.js +18 -0
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/wait.d.ts +56 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +62 -9
- package/dist/utils/wait.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
package/dist/pluginManager.js
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the Plugins class.
|
|
3
|
+
*
|
|
4
|
+
* @file plugins.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @created 2024-07-14
|
|
7
|
+
* @version 1.1.2
|
|
8
|
+
* @license Apache-2.0
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
// Node.js import
|
|
1
25
|
import EventEmitter from 'node:events';
|
|
26
|
+
// AnsiLogger module
|
|
2
27
|
import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr } from 'node-ansi-logger';
|
|
3
28
|
import { plg, typ } from './matterbridgeTypes.js';
|
|
4
29
|
export class PluginManager extends EventEmitter {
|
|
@@ -9,8 +34,9 @@ export class PluginManager extends EventEmitter {
|
|
|
9
34
|
constructor(matterbridge) {
|
|
10
35
|
super();
|
|
11
36
|
this.matterbridge = matterbridge;
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
38
|
this.nodeContext = matterbridge.nodeContext;
|
|
13
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
39
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: matterbridge.log.logLevel });
|
|
14
40
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
15
41
|
}
|
|
16
42
|
get length() {
|
|
@@ -47,6 +73,7 @@ export class PluginManager extends EventEmitter {
|
|
|
47
73
|
}
|
|
48
74
|
catch (err) {
|
|
49
75
|
this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
|
|
76
|
+
// throw error;
|
|
50
77
|
}
|
|
51
78
|
});
|
|
52
79
|
await Promise.all(tasks);
|
|
@@ -54,13 +81,31 @@ export class PluginManager extends EventEmitter {
|
|
|
54
81
|
set logLevel(logLevel) {
|
|
55
82
|
this.log.logLevel = logLevel;
|
|
56
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Loads registered plugins from storage.
|
|
86
|
+
*
|
|
87
|
+
* This method retrieves an array of registered plugins from the storage and converts it
|
|
88
|
+
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
89
|
+
*
|
|
90
|
+
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
91
|
+
*/
|
|
57
92
|
async loadFromStorage() {
|
|
93
|
+
// Load the array from storage and convert it to a map
|
|
58
94
|
const pluginsArray = await this.nodeContext.get('plugins', []);
|
|
59
95
|
for (const plugin of pluginsArray)
|
|
60
96
|
this._plugins.set(plugin.name, plugin);
|
|
61
97
|
return pluginsArray;
|
|
62
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Loads registered plugins from storage.
|
|
101
|
+
*
|
|
102
|
+
* This method retrieves an array of registered plugins from the storage and converts it
|
|
103
|
+
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
104
|
+
*
|
|
105
|
+
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
106
|
+
*/
|
|
63
107
|
async saveToStorage() {
|
|
108
|
+
// Convert the map to an array
|
|
64
109
|
const plugins = [];
|
|
65
110
|
const pluginArrayFromMap = Array.from(this._plugins.values());
|
|
66
111
|
for (const plugin of pluginArrayFromMap) {
|
|
@@ -80,13 +125,21 @@ export class PluginManager extends EventEmitter {
|
|
|
80
125
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
81
126
|
return plugins.length;
|
|
82
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
132
|
+
* @returns {Promise<string | null>} A promise that resolves to the path of the plugin's package.json file or null if it could not be resolved.
|
|
133
|
+
*/
|
|
83
134
|
async resolve(pluginPath) {
|
|
84
135
|
const { default: path } = await import('node:path');
|
|
85
136
|
const { promises } = await import('node:fs');
|
|
86
137
|
if (!pluginPath.endsWith('package.json'))
|
|
87
138
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
139
|
+
// Resolve the package.json of the plugin
|
|
88
140
|
let packageJsonPath = path.resolve(pluginPath);
|
|
89
141
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
142
|
+
// Check if the package.json file exists
|
|
90
143
|
try {
|
|
91
144
|
await promises.access(packageJsonPath);
|
|
92
145
|
}
|
|
@@ -96,7 +149,9 @@ export class PluginManager extends EventEmitter {
|
|
|
96
149
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
97
150
|
}
|
|
98
151
|
try {
|
|
152
|
+
// Load the package.json of the plugin
|
|
99
153
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
154
|
+
// Check for main issues
|
|
100
155
|
if (!packageJson.name) {
|
|
101
156
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
102
157
|
return null;
|
|
@@ -109,6 +164,7 @@ export class PluginManager extends EventEmitter {
|
|
|
109
164
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
110
165
|
return null;
|
|
111
166
|
}
|
|
167
|
+
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
112
168
|
const checkForProjectChipPackages = (dependencies) => {
|
|
113
169
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
114
170
|
};
|
|
@@ -130,6 +186,7 @@ export class PluginManager extends EventEmitter {
|
|
|
130
186
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
131
187
|
return null;
|
|
132
188
|
}
|
|
189
|
+
// Check for matterbridge package in dependencies and devDependencies
|
|
133
190
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
134
191
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
135
192
|
};
|
|
@@ -159,6 +216,12 @@ export class PluginManager extends EventEmitter {
|
|
|
159
216
|
return null;
|
|
160
217
|
}
|
|
161
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Get the author of a plugin from its package.json.
|
|
221
|
+
*
|
|
222
|
+
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
223
|
+
* @returns {string} The author of the plugin, or 'Unknown author' if not found.
|
|
224
|
+
*/
|
|
162
225
|
getAuthor(packageJson) {
|
|
163
226
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
164
227
|
return packageJson.author;
|
|
@@ -166,6 +229,12 @@ export class PluginManager extends EventEmitter {
|
|
|
166
229
|
return packageJson.author.name;
|
|
167
230
|
return 'Unknown author';
|
|
168
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Get the homepage of a plugin from its package.json.
|
|
234
|
+
*
|
|
235
|
+
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
236
|
+
* @returns {string | undefined} The homepage of the plugin, or undefined if not found.
|
|
237
|
+
*/
|
|
169
238
|
getHomepage(packageJson) {
|
|
170
239
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
171
240
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -174,7 +243,14 @@ export class PluginManager extends EventEmitter {
|
|
|
174
243
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
175
244
|
}
|
|
176
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Get the help URL of a plugin from its package.json.
|
|
248
|
+
*
|
|
249
|
+
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
250
|
+
* @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
|
|
251
|
+
*/
|
|
177
252
|
getHelp(packageJson) {
|
|
253
|
+
// If there's a help field that looks like a URL, return it.
|
|
178
254
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
179
255
|
return packageJson.help;
|
|
180
256
|
}
|
|
@@ -185,7 +261,14 @@ export class PluginManager extends EventEmitter {
|
|
|
185
261
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
186
262
|
}
|
|
187
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Get the changelog URL of a plugin from its package.json.
|
|
266
|
+
*
|
|
267
|
+
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
268
|
+
* @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
|
|
269
|
+
*/
|
|
188
270
|
getChangelog(packageJson) {
|
|
271
|
+
// If there's a changelog field that looks like a URL, return it.
|
|
189
272
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
190
273
|
return packageJson.changelog;
|
|
191
274
|
}
|
|
@@ -196,6 +279,13 @@ export class PluginManager extends EventEmitter {
|
|
|
196
279
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
197
280
|
}
|
|
198
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Get the first funding URL(s) of a plugin from its package.json.
|
|
284
|
+
*
|
|
285
|
+
* @param {Record<string, any>} packageJson - The package.json object of the plugin.
|
|
286
|
+
* @returns {string | undefined} The first funding URLs, or undefined if not found.
|
|
287
|
+
*/
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
199
289
|
getFunding(packageJson) {
|
|
200
290
|
const funding = packageJson.funding;
|
|
201
291
|
if (!funding)
|
|
@@ -204,16 +294,25 @@ export class PluginManager extends EventEmitter {
|
|
|
204
294
|
return;
|
|
205
295
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
206
296
|
return funding;
|
|
297
|
+
// Normalize funding into an array.
|
|
207
298
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
208
299
|
for (const entry of fundingEntries) {
|
|
209
300
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
301
|
+
// If the funding entry is a string, assume it is a URL.
|
|
210
302
|
return entry;
|
|
211
303
|
}
|
|
212
304
|
else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
|
|
305
|
+
// If it's an object with a 'url' property, use that.
|
|
213
306
|
return entry.url;
|
|
214
307
|
}
|
|
215
308
|
}
|
|
216
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Loads and parse the plugin package.json and returns it.
|
|
312
|
+
*
|
|
313
|
+
* @param {RegisteredPlugin} plugin - The plugin to load the package from.
|
|
314
|
+
* @returns {Promise<Record<string, string | number | object> | null>} A promise that resolves to the parsed package.json object or null if it could not be parsed.
|
|
315
|
+
*/
|
|
217
316
|
async parse(plugin) {
|
|
218
317
|
const { promises } = await import('node:fs');
|
|
219
318
|
try {
|
|
@@ -243,6 +342,7 @@ export class PluginManager extends EventEmitter {
|
|
|
243
342
|
plugin.funding = this.getFunding(packageJson);
|
|
244
343
|
if (!plugin.type)
|
|
245
344
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
345
|
+
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
246
346
|
const checkForProjectChipPackages = (dependencies) => {
|
|
247
347
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
248
348
|
};
|
|
@@ -264,6 +364,7 @@ export class PluginManager extends EventEmitter {
|
|
|
264
364
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
265
365
|
return null;
|
|
266
366
|
}
|
|
367
|
+
// Check for matterbridge package in dependencies and devDependencies
|
|
267
368
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
268
369
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
269
370
|
};
|
|
@@ -293,6 +394,16 @@ export class PluginManager extends EventEmitter {
|
|
|
293
394
|
return null;
|
|
294
395
|
}
|
|
295
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Enables a plugin by its name or path.
|
|
399
|
+
*
|
|
400
|
+
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
401
|
+
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
402
|
+
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
403
|
+
*
|
|
404
|
+
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
405
|
+
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
406
|
+
*/
|
|
296
407
|
async enable(nameOrPath) {
|
|
297
408
|
const { promises } = await import('node:fs');
|
|
298
409
|
if (!nameOrPath)
|
|
@@ -328,6 +439,16 @@ export class PluginManager extends EventEmitter {
|
|
|
328
439
|
return null;
|
|
329
440
|
}
|
|
330
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* Enables a plugin by its name or path.
|
|
444
|
+
*
|
|
445
|
+
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
446
|
+
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
447
|
+
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
448
|
+
*
|
|
449
|
+
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
450
|
+
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
451
|
+
*/
|
|
331
452
|
async disable(nameOrPath) {
|
|
332
453
|
const { promises } = await import('node:fs');
|
|
333
454
|
if (!nameOrPath)
|
|
@@ -363,6 +484,16 @@ export class PluginManager extends EventEmitter {
|
|
|
363
484
|
return null;
|
|
364
485
|
}
|
|
365
486
|
}
|
|
487
|
+
/**
|
|
488
|
+
* Removes a plugin by its name or path.
|
|
489
|
+
*
|
|
490
|
+
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
491
|
+
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
492
|
+
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
493
|
+
*
|
|
494
|
+
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
495
|
+
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
496
|
+
*/
|
|
366
497
|
async remove(nameOrPath) {
|
|
367
498
|
const { promises } = await import('node:fs');
|
|
368
499
|
if (!nameOrPath)
|
|
@@ -398,6 +529,17 @@ export class PluginManager extends EventEmitter {
|
|
|
398
529
|
return null;
|
|
399
530
|
}
|
|
400
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* Adds a plugin by its name or path.
|
|
534
|
+
*
|
|
535
|
+
* This method adds a plugin to the plugins map and saves the updated plugin information to storage.
|
|
536
|
+
* It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
|
|
537
|
+
* registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
|
|
538
|
+
* and saves the updated plugin information to storage.
|
|
539
|
+
*
|
|
540
|
+
* @param {string} nameOrPath - The name or path of the plugin to add.
|
|
541
|
+
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
|
|
542
|
+
*/
|
|
401
543
|
async add(nameOrPath) {
|
|
402
544
|
const { promises } = await import('node:fs');
|
|
403
545
|
if (!nameOrPath)
|
|
@@ -433,6 +575,15 @@ export class PluginManager extends EventEmitter {
|
|
|
433
575
|
return null;
|
|
434
576
|
}
|
|
435
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Installs a plugin by its name.
|
|
580
|
+
*
|
|
581
|
+
* This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
|
|
582
|
+
* It logs the installation process and retrieves the installed version of the plugin.
|
|
583
|
+
*
|
|
584
|
+
* @param {string} name - The name of the plugin to install.
|
|
585
|
+
* @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
|
|
586
|
+
*/
|
|
436
587
|
async install(name) {
|
|
437
588
|
const { exec } = await import('node:child_process');
|
|
438
589
|
await this.uninstall(name);
|
|
@@ -447,11 +598,14 @@ export class PluginManager extends EventEmitter {
|
|
|
447
598
|
else {
|
|
448
599
|
this.log.info(`Installed plugin ${plg}${name}${nf}`);
|
|
449
600
|
this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
|
|
601
|
+
// Get the installed version
|
|
602
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
450
603
|
exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
|
|
451
604
|
if (listError) {
|
|
452
605
|
this.log.error(`List error: ${listError}`);
|
|
453
606
|
resolve(undefined);
|
|
454
607
|
}
|
|
608
|
+
// Clean the output to get only the package name and version
|
|
455
609
|
const lines = listStdout.split('\n');
|
|
456
610
|
const versionLine = lines.find((line) => line.includes(`${name}@`));
|
|
457
611
|
if (versionLine) {
|
|
@@ -468,6 +622,15 @@ export class PluginManager extends EventEmitter {
|
|
|
468
622
|
});
|
|
469
623
|
});
|
|
470
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* Uninstalls a plugin by its name.
|
|
627
|
+
*
|
|
628
|
+
* This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
|
|
629
|
+
* and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
|
|
630
|
+
*
|
|
631
|
+
* @param {string} name - The name of the plugin to uninstall.
|
|
632
|
+
* @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
|
|
633
|
+
*/
|
|
471
634
|
async uninstall(name) {
|
|
472
635
|
const { exec } = await import('node:child_process');
|
|
473
636
|
this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
|
|
@@ -487,6 +650,15 @@ export class PluginManager extends EventEmitter {
|
|
|
487
650
|
});
|
|
488
651
|
});
|
|
489
652
|
}
|
|
653
|
+
/**
|
|
654
|
+
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
655
|
+
*
|
|
656
|
+
* @param {RegisteredPlugin} plugin - The plugin to load.
|
|
657
|
+
* @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
658
|
+
* @param {string} message - Optional message to pass to the plugin when starting.
|
|
659
|
+
* @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
|
|
660
|
+
* @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
|
|
661
|
+
*/
|
|
490
662
|
async load(plugin, start = false, message = '', configure = false) {
|
|
491
663
|
const { promises } = await import('node:fs');
|
|
492
664
|
const { default: path } = await import('node:path');
|
|
@@ -500,15 +672,20 @@ export class PluginManager extends EventEmitter {
|
|
|
500
672
|
}
|
|
501
673
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
502
674
|
try {
|
|
675
|
+
// Load the package.json of the plugin
|
|
503
676
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
677
|
+
// Resolve the main module path relative to package.json
|
|
504
678
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
679
|
+
// Dynamically import the plugin
|
|
505
680
|
const { pathToFileURL } = await import('node:url');
|
|
506
681
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
507
682
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
508
683
|
const pluginInstance = await import(pluginUrl.href);
|
|
509
684
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
685
|
+
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
510
686
|
if (pluginInstance.default) {
|
|
511
687
|
const config = await this.loadConfig(plugin);
|
|
688
|
+
// 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.
|
|
512
689
|
plugin.name = packageJson.name;
|
|
513
690
|
plugin.description = packageJson.description ?? 'No description';
|
|
514
691
|
plugin.version = packageJson.version;
|
|
@@ -517,7 +694,7 @@ export class PluginManager extends EventEmitter {
|
|
|
517
694
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
518
695
|
config.name = plugin.name;
|
|
519
696
|
config.version = packageJson.version;
|
|
520
|
-
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4
|
|
697
|
+
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
|
|
521
698
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
522
699
|
config.type = platform.type;
|
|
523
700
|
platform.name = packageJson.name;
|
|
@@ -536,7 +713,7 @@ export class PluginManager extends EventEmitter {
|
|
|
536
713
|
plugin.loaded = true;
|
|
537
714
|
plugin.registeredDevices = 0;
|
|
538
715
|
plugin.addedDevices = 0;
|
|
539
|
-
await this.saveToStorage();
|
|
716
|
+
await this.saveToStorage(); // Save the plugin to storage
|
|
540
717
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
541
718
|
this.emit('loaded', plugin.name);
|
|
542
719
|
if (start)
|
|
@@ -556,6 +733,14 @@ export class PluginManager extends EventEmitter {
|
|
|
556
733
|
}
|
|
557
734
|
return undefined;
|
|
558
735
|
}
|
|
736
|
+
/**
|
|
737
|
+
* Starts a plugin.
|
|
738
|
+
*
|
|
739
|
+
* @param {RegisteredPlugin} plugin - The plugin to start.
|
|
740
|
+
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
741
|
+
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
742
|
+
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
743
|
+
*/
|
|
559
744
|
async start(plugin, message, configure = false) {
|
|
560
745
|
if (!plugin.loaded) {
|
|
561
746
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -586,6 +771,12 @@ export class PluginManager extends EventEmitter {
|
|
|
586
771
|
}
|
|
587
772
|
return undefined;
|
|
588
773
|
}
|
|
774
|
+
/**
|
|
775
|
+
* Configures a plugin.
|
|
776
|
+
*
|
|
777
|
+
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
778
|
+
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
779
|
+
*/
|
|
589
780
|
async configure(plugin) {
|
|
590
781
|
if (!plugin.loaded) {
|
|
591
782
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -617,6 +808,18 @@ export class PluginManager extends EventEmitter {
|
|
|
617
808
|
}
|
|
618
809
|
return undefined;
|
|
619
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* Shuts down a plugin.
|
|
813
|
+
*
|
|
814
|
+
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
815
|
+
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
816
|
+
*
|
|
817
|
+
* @param {RegisteredPlugin} plugin - The plugin to shut down.
|
|
818
|
+
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
819
|
+
* @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
|
|
820
|
+
* @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
821
|
+
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
822
|
+
*/
|
|
620
823
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
621
824
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
622
825
|
if (!plugin.loaded) {
|
|
@@ -660,6 +863,15 @@ export class PluginManager extends EventEmitter {
|
|
|
660
863
|
}
|
|
661
864
|
return undefined;
|
|
662
865
|
}
|
|
866
|
+
/**
|
|
867
|
+
* Loads the configuration for a plugin.
|
|
868
|
+
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
869
|
+
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
870
|
+
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
871
|
+
*
|
|
872
|
+
* @param {RegisteredPlugin} plugin - The plugin for which to load the configuration.
|
|
873
|
+
* @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
|
|
874
|
+
*/
|
|
663
875
|
async loadConfig(plugin) {
|
|
664
876
|
const { default: path } = await import('node:path');
|
|
665
877
|
const { promises } = await import('node:fs');
|
|
@@ -670,6 +882,8 @@ export class PluginManager extends EventEmitter {
|
|
|
670
882
|
const data = await promises.readFile(configFile, 'utf8');
|
|
671
883
|
const config = JSON.parse(data);
|
|
672
884
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
885
|
+
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
886
|
+
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
673
887
|
config.name = plugin.name;
|
|
674
888
|
config.type = plugin.type;
|
|
675
889
|
if (config.debug === undefined)
|
|
@@ -693,6 +907,7 @@ export class PluginManager extends EventEmitter {
|
|
|
693
907
|
try {
|
|
694
908
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
695
909
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
910
|
+
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
696
911
|
return config;
|
|
697
912
|
}
|
|
698
913
|
catch (err) {
|
|
@@ -706,6 +921,19 @@ export class PluginManager extends EventEmitter {
|
|
|
706
921
|
}
|
|
707
922
|
}
|
|
708
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
* Saves the configuration of a plugin to a file.
|
|
926
|
+
*
|
|
927
|
+
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
928
|
+
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
929
|
+
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
930
|
+
* the error and rejects the promise.
|
|
931
|
+
*
|
|
932
|
+
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
933
|
+
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
934
|
+
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
935
|
+
* @throws {Error} If the plugin's configuration is not found.
|
|
936
|
+
*/
|
|
709
937
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
710
938
|
const { default: path } = await import('node:path');
|
|
711
939
|
const { promises } = await import('node:fs');
|
|
@@ -720,6 +948,7 @@ export class PluginManager extends EventEmitter {
|
|
|
720
948
|
if (restartRequired)
|
|
721
949
|
plugin.restartRequired = true;
|
|
722
950
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
951
|
+
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
723
952
|
return Promise.resolve();
|
|
724
953
|
}
|
|
725
954
|
catch (err) {
|
|
@@ -727,6 +956,20 @@ export class PluginManager extends EventEmitter {
|
|
|
727
956
|
return Promise.reject(err);
|
|
728
957
|
}
|
|
729
958
|
}
|
|
959
|
+
/**
|
|
960
|
+
* Saves the configuration of a plugin from a JSON object to a file.
|
|
961
|
+
*
|
|
962
|
+
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
963
|
+
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
964
|
+
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
965
|
+
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
966
|
+
* during the file write operation, it logs the error and returns.
|
|
967
|
+
*
|
|
968
|
+
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
969
|
+
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
970
|
+
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
971
|
+
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
972
|
+
*/
|
|
730
973
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
731
974
|
const { default: path } = await import('node:path');
|
|
732
975
|
const { promises } = await import('node:fs');
|
|
@@ -745,12 +988,23 @@ export class PluginManager extends EventEmitter {
|
|
|
745
988
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
746
989
|
}
|
|
747
990
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
991
|
+
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
748
992
|
}
|
|
749
993
|
catch (err) {
|
|
750
994
|
this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
|
|
751
995
|
return;
|
|
752
996
|
}
|
|
753
997
|
}
|
|
998
|
+
/**
|
|
999
|
+
* Loads the schema for a plugin.
|
|
1000
|
+
*
|
|
1001
|
+
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
1002
|
+
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
1003
|
+
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
1004
|
+
*
|
|
1005
|
+
* @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
|
|
1006
|
+
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
1007
|
+
*/
|
|
754
1008
|
async loadSchema(plugin) {
|
|
755
1009
|
const { promises } = await import('node:fs');
|
|
756
1010
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -761,6 +1015,7 @@ export class PluginManager extends EventEmitter {
|
|
|
761
1015
|
schema.title = plugin.description;
|
|
762
1016
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
763
1017
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1018
|
+
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
764
1019
|
return schema;
|
|
765
1020
|
}
|
|
766
1021
|
catch (_err) {
|
|
@@ -768,6 +1023,16 @@ export class PluginManager extends EventEmitter {
|
|
|
768
1023
|
return this.getDefaultSchema(plugin);
|
|
769
1024
|
}
|
|
770
1025
|
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Returns the default schema for a plugin.
|
|
1028
|
+
*
|
|
1029
|
+
* This method generates a default schema object for the specified plugin. The schema includes
|
|
1030
|
+
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
1031
|
+
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
1032
|
+
*
|
|
1033
|
+
* @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
|
|
1034
|
+
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
1035
|
+
*/
|
|
771
1036
|
getDefaultSchema(plugin) {
|
|
772
1037
|
return {
|
|
773
1038
|
title: plugin.description,
|
|
@@ -798,3 +1063,4 @@ export class PluginManager extends EventEmitter {
|
|
|
798
1063
|
};
|
|
799
1064
|
}
|
|
800
1065
|
}
|
|
1066
|
+
//# sourceMappingURL=pluginManager.js.map
|