matterbridge 3.1.1 → 3.1.2-dev-20250706-6c6481e
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 +19 -0
- package/README-DEV.md +6 -2
- package/dist/cli.js +2 -91
- package/dist/cliEmitter.js +0 -30
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -94
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -2
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +6 -83
- package/dist/devices/laundryWasher.js +7 -91
- package/dist/devices/roboticVacuumCleaner.js +8 -84
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/waterHeater.js +2 -82
- package/dist/frontend.js +53 -474
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -39
- 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 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +52 -804
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +1 -61
- package/dist/matterbridgeDeviceTypes.js +15 -579
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +42 -1027
- package/dist/matterbridgeEndpointHelpers.js +12 -322
- package/dist/matterbridgePlatform.js +0 -233
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +3 -269
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -54
- package/dist/utils/colorUtils.js +2 -263
- package/dist/utils/commandLine.js +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -58
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +5 -83
- package/dist/utils/spawn.js +0 -18
- package/dist/utils/wait.js +9 -62
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -112
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -9
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -87
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -242
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -103
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/frontend.d.ts +0 -302
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -41
- 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 -450
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1340
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -709
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1179
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -3198
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -310
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -192
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -291
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- 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 -59
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -117
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/export.d.ts +0 -12
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -49
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -76
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -11
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -56
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
package/dist/pluginManager.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
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
|
|
25
1
|
import EventEmitter from 'node:events';
|
|
26
|
-
// AnsiLogger module
|
|
27
2
|
import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr } from 'node-ansi-logger';
|
|
28
3
|
import { plg, typ } from './matterbridgeTypes.js';
|
|
29
4
|
export class PluginManager extends EventEmitter {
|
|
@@ -34,9 +9,8 @@ export class PluginManager extends EventEmitter {
|
|
|
34
9
|
constructor(matterbridge) {
|
|
35
10
|
super();
|
|
36
11
|
this.matterbridge = matterbridge;
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
12
|
this.nodeContext = matterbridge.nodeContext;
|
|
39
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
13
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
|
|
40
14
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
41
15
|
}
|
|
42
16
|
get length() {
|
|
@@ -73,7 +47,6 @@ export class PluginManager extends EventEmitter {
|
|
|
73
47
|
}
|
|
74
48
|
catch (err) {
|
|
75
49
|
this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
|
|
76
|
-
// throw error;
|
|
77
50
|
}
|
|
78
51
|
});
|
|
79
52
|
await Promise.all(tasks);
|
|
@@ -81,31 +54,13 @@ export class PluginManager extends EventEmitter {
|
|
|
81
54
|
set logLevel(logLevel) {
|
|
82
55
|
this.log.logLevel = logLevel;
|
|
83
56
|
}
|
|
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
|
-
*/
|
|
92
57
|
async loadFromStorage() {
|
|
93
|
-
// Load the array from storage and convert it to a map
|
|
94
58
|
const pluginsArray = await this.nodeContext.get('plugins', []);
|
|
95
59
|
for (const plugin of pluginsArray)
|
|
96
60
|
this._plugins.set(plugin.name, plugin);
|
|
97
61
|
return pluginsArray;
|
|
98
62
|
}
|
|
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
|
-
*/
|
|
107
63
|
async saveToStorage() {
|
|
108
|
-
// Convert the map to an array
|
|
109
64
|
const plugins = [];
|
|
110
65
|
const pluginArrayFromMap = Array.from(this._plugins.values());
|
|
111
66
|
for (const plugin of pluginArrayFromMap) {
|
|
@@ -125,21 +80,13 @@ export class PluginManager extends EventEmitter {
|
|
|
125
80
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
126
81
|
return plugins.length;
|
|
127
82
|
}
|
|
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
|
-
*/
|
|
134
83
|
async resolve(pluginPath) {
|
|
135
84
|
const { default: path } = await import('node:path');
|
|
136
85
|
const { promises } = await import('node:fs');
|
|
137
86
|
if (!pluginPath.endsWith('package.json'))
|
|
138
87
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
139
|
-
// Resolve the package.json of the plugin
|
|
140
88
|
let packageJsonPath = path.resolve(pluginPath);
|
|
141
89
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
142
|
-
// Check if the package.json file exists
|
|
143
90
|
try {
|
|
144
91
|
await promises.access(packageJsonPath);
|
|
145
92
|
}
|
|
@@ -149,9 +96,7 @@ export class PluginManager extends EventEmitter {
|
|
|
149
96
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
150
97
|
}
|
|
151
98
|
try {
|
|
152
|
-
// Load the package.json of the plugin
|
|
153
99
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
154
|
-
// Check for main issues
|
|
155
100
|
if (!packageJson.name) {
|
|
156
101
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
157
102
|
return null;
|
|
@@ -164,7 +109,6 @@ export class PluginManager extends EventEmitter {
|
|
|
164
109
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
165
110
|
return null;
|
|
166
111
|
}
|
|
167
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
168
112
|
const checkForProjectChipPackages = (dependencies) => {
|
|
169
113
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
170
114
|
};
|
|
@@ -186,7 +130,6 @@ export class PluginManager extends EventEmitter {
|
|
|
186
130
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
187
131
|
return null;
|
|
188
132
|
}
|
|
189
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
190
133
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
191
134
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
192
135
|
};
|
|
@@ -216,12 +159,6 @@ export class PluginManager extends EventEmitter {
|
|
|
216
159
|
return null;
|
|
217
160
|
}
|
|
218
161
|
}
|
|
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
|
-
*/
|
|
225
162
|
getAuthor(packageJson) {
|
|
226
163
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
227
164
|
return packageJson.author;
|
|
@@ -229,12 +166,6 @@ export class PluginManager extends EventEmitter {
|
|
|
229
166
|
return packageJson.author.name;
|
|
230
167
|
return 'Unknown author';
|
|
231
168
|
}
|
|
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
|
-
*/
|
|
238
169
|
getHomepage(packageJson) {
|
|
239
170
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
240
171
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -243,14 +174,7 @@ export class PluginManager extends EventEmitter {
|
|
|
243
174
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
244
175
|
}
|
|
245
176
|
}
|
|
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
|
-
*/
|
|
252
177
|
getHelp(packageJson) {
|
|
253
|
-
// If there's a help field that looks like a URL, return it.
|
|
254
178
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
255
179
|
return packageJson.help;
|
|
256
180
|
}
|
|
@@ -261,14 +185,7 @@ export class PluginManager extends EventEmitter {
|
|
|
261
185
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
262
186
|
}
|
|
263
187
|
}
|
|
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
|
-
*/
|
|
270
188
|
getChangelog(packageJson) {
|
|
271
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
272
189
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
273
190
|
return packageJson.changelog;
|
|
274
191
|
}
|
|
@@ -279,13 +196,6 @@ export class PluginManager extends EventEmitter {
|
|
|
279
196
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
280
197
|
}
|
|
281
198
|
}
|
|
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
|
|
289
199
|
getFunding(packageJson) {
|
|
290
200
|
const funding = packageJson.funding;
|
|
291
201
|
if (!funding)
|
|
@@ -294,25 +204,16 @@ export class PluginManager extends EventEmitter {
|
|
|
294
204
|
return;
|
|
295
205
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
296
206
|
return funding;
|
|
297
|
-
// Normalize funding into an array.
|
|
298
207
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
299
208
|
for (const entry of fundingEntries) {
|
|
300
209
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
301
|
-
// If the funding entry is a string, assume it is a URL.
|
|
302
210
|
return entry;
|
|
303
211
|
}
|
|
304
212
|
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.
|
|
306
213
|
return entry.url;
|
|
307
214
|
}
|
|
308
215
|
}
|
|
309
216
|
}
|
|
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
|
-
*/
|
|
316
217
|
async parse(plugin) {
|
|
317
218
|
const { promises } = await import('node:fs');
|
|
318
219
|
try {
|
|
@@ -342,7 +243,6 @@ export class PluginManager extends EventEmitter {
|
|
|
342
243
|
plugin.funding = this.getFunding(packageJson);
|
|
343
244
|
if (!plugin.type)
|
|
344
245
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
345
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
346
246
|
const checkForProjectChipPackages = (dependencies) => {
|
|
347
247
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
348
248
|
};
|
|
@@ -364,7 +264,6 @@ export class PluginManager extends EventEmitter {
|
|
|
364
264
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
365
265
|
return null;
|
|
366
266
|
}
|
|
367
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
368
267
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
369
268
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
370
269
|
};
|
|
@@ -394,16 +293,6 @@ export class PluginManager extends EventEmitter {
|
|
|
394
293
|
return null;
|
|
395
294
|
}
|
|
396
295
|
}
|
|
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
|
-
*/
|
|
407
296
|
async enable(nameOrPath) {
|
|
408
297
|
const { promises } = await import('node:fs');
|
|
409
298
|
if (!nameOrPath)
|
|
@@ -439,16 +328,6 @@ export class PluginManager extends EventEmitter {
|
|
|
439
328
|
return null;
|
|
440
329
|
}
|
|
441
330
|
}
|
|
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
|
-
*/
|
|
452
331
|
async disable(nameOrPath) {
|
|
453
332
|
const { promises } = await import('node:fs');
|
|
454
333
|
if (!nameOrPath)
|
|
@@ -484,16 +363,6 @@ export class PluginManager extends EventEmitter {
|
|
|
484
363
|
return null;
|
|
485
364
|
}
|
|
486
365
|
}
|
|
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
|
-
*/
|
|
497
366
|
async remove(nameOrPath) {
|
|
498
367
|
const { promises } = await import('node:fs');
|
|
499
368
|
if (!nameOrPath)
|
|
@@ -529,17 +398,6 @@ export class PluginManager extends EventEmitter {
|
|
|
529
398
|
return null;
|
|
530
399
|
}
|
|
531
400
|
}
|
|
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
|
-
*/
|
|
543
401
|
async add(nameOrPath) {
|
|
544
402
|
const { promises } = await import('node:fs');
|
|
545
403
|
if (!nameOrPath)
|
|
@@ -575,15 +433,6 @@ export class PluginManager extends EventEmitter {
|
|
|
575
433
|
return null;
|
|
576
434
|
}
|
|
577
435
|
}
|
|
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
|
-
*/
|
|
587
436
|
async install(name) {
|
|
588
437
|
const { exec } = await import('node:child_process');
|
|
589
438
|
await this.uninstall(name);
|
|
@@ -598,14 +447,11 @@ export class PluginManager extends EventEmitter {
|
|
|
598
447
|
else {
|
|
599
448
|
this.log.info(`Installed plugin ${plg}${name}${nf}`);
|
|
600
449
|
this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
|
|
601
|
-
// Get the installed version
|
|
602
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
603
450
|
exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
|
|
604
451
|
if (listError) {
|
|
605
452
|
this.log.error(`List error: ${listError}`);
|
|
606
453
|
resolve(undefined);
|
|
607
454
|
}
|
|
608
|
-
// Clean the output to get only the package name and version
|
|
609
455
|
const lines = listStdout.split('\n');
|
|
610
456
|
const versionLine = lines.find((line) => line.includes(`${name}@`));
|
|
611
457
|
if (versionLine) {
|
|
@@ -622,15 +468,6 @@ export class PluginManager extends EventEmitter {
|
|
|
622
468
|
});
|
|
623
469
|
});
|
|
624
470
|
}
|
|
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
|
-
*/
|
|
634
471
|
async uninstall(name) {
|
|
635
472
|
const { exec } = await import('node:child_process');
|
|
636
473
|
this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
|
|
@@ -650,15 +487,6 @@ export class PluginManager extends EventEmitter {
|
|
|
650
487
|
});
|
|
651
488
|
});
|
|
652
489
|
}
|
|
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
|
-
*/
|
|
662
490
|
async load(plugin, start = false, message = '', configure = false) {
|
|
663
491
|
const { promises } = await import('node:fs');
|
|
664
492
|
const { default: path } = await import('node:path');
|
|
@@ -672,20 +500,15 @@ export class PluginManager extends EventEmitter {
|
|
|
672
500
|
}
|
|
673
501
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
674
502
|
try {
|
|
675
|
-
// Load the package.json of the plugin
|
|
676
503
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
677
|
-
// Resolve the main module path relative to package.json
|
|
678
504
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
679
|
-
// Dynamically import the plugin
|
|
680
505
|
const { pathToFileURL } = await import('node:url');
|
|
681
506
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
682
507
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
683
508
|
const pluginInstance = await import(pluginUrl.href);
|
|
684
509
|
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
|
|
686
510
|
if (pluginInstance.default) {
|
|
687
511
|
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.
|
|
689
512
|
plugin.name = packageJson.name;
|
|
690
513
|
plugin.description = packageJson.description ?? 'No description';
|
|
691
514
|
plugin.version = packageJson.version;
|
|
@@ -694,7 +517,7 @@ export class PluginManager extends EventEmitter {
|
|
|
694
517
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
695
518
|
config.name = plugin.name;
|
|
696
519
|
config.version = packageJson.version;
|
|
697
|
-
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4
|
|
520
|
+
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
698
521
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
699
522
|
config.type = platform.type;
|
|
700
523
|
platform.name = packageJson.name;
|
|
@@ -713,7 +536,7 @@ export class PluginManager extends EventEmitter {
|
|
|
713
536
|
plugin.loaded = true;
|
|
714
537
|
plugin.registeredDevices = 0;
|
|
715
538
|
plugin.addedDevices = 0;
|
|
716
|
-
await this.saveToStorage();
|
|
539
|
+
await this.saveToStorage();
|
|
717
540
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
718
541
|
this.emit('loaded', plugin.name);
|
|
719
542
|
if (start)
|
|
@@ -733,14 +556,6 @@ export class PluginManager extends EventEmitter {
|
|
|
733
556
|
}
|
|
734
557
|
return undefined;
|
|
735
558
|
}
|
|
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
|
-
*/
|
|
744
559
|
async start(plugin, message, configure = false) {
|
|
745
560
|
if (!plugin.loaded) {
|
|
746
561
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -771,12 +586,6 @@ export class PluginManager extends EventEmitter {
|
|
|
771
586
|
}
|
|
772
587
|
return undefined;
|
|
773
588
|
}
|
|
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
|
-
*/
|
|
780
589
|
async configure(plugin) {
|
|
781
590
|
if (!plugin.loaded) {
|
|
782
591
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -808,18 +617,6 @@ export class PluginManager extends EventEmitter {
|
|
|
808
617
|
}
|
|
809
618
|
return undefined;
|
|
810
619
|
}
|
|
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
|
-
*/
|
|
823
620
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
824
621
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
825
622
|
if (!plugin.loaded) {
|
|
@@ -863,15 +660,6 @@ export class PluginManager extends EventEmitter {
|
|
|
863
660
|
}
|
|
864
661
|
return undefined;
|
|
865
662
|
}
|
|
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
|
-
*/
|
|
875
663
|
async loadConfig(plugin) {
|
|
876
664
|
const { default: path } = await import('node:path');
|
|
877
665
|
const { promises } = await import('node:fs');
|
|
@@ -882,8 +670,6 @@ export class PluginManager extends EventEmitter {
|
|
|
882
670
|
const data = await promises.readFile(configFile, 'utf8');
|
|
883
671
|
const config = JSON.parse(data);
|
|
884
672
|
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".
|
|
887
673
|
config.name = plugin.name;
|
|
888
674
|
config.type = plugin.type;
|
|
889
675
|
if (config.debug === undefined)
|
|
@@ -907,7 +693,6 @@ export class PluginManager extends EventEmitter {
|
|
|
907
693
|
try {
|
|
908
694
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
909
695
|
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);
|
|
911
696
|
return config;
|
|
912
697
|
}
|
|
913
698
|
catch (err) {
|
|
@@ -921,19 +706,6 @@ export class PluginManager extends EventEmitter {
|
|
|
921
706
|
}
|
|
922
707
|
}
|
|
923
708
|
}
|
|
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
|
-
*/
|
|
937
709
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
938
710
|
const { default: path } = await import('node:path');
|
|
939
711
|
const { promises } = await import('node:fs');
|
|
@@ -948,7 +720,6 @@ export class PluginManager extends EventEmitter {
|
|
|
948
720
|
if (restartRequired)
|
|
949
721
|
plugin.restartRequired = true;
|
|
950
722
|
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);
|
|
952
723
|
return Promise.resolve();
|
|
953
724
|
}
|
|
954
725
|
catch (err) {
|
|
@@ -956,20 +727,6 @@ export class PluginManager extends EventEmitter {
|
|
|
956
727
|
return Promise.reject(err);
|
|
957
728
|
}
|
|
958
729
|
}
|
|
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
|
-
*/
|
|
973
730
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
974
731
|
const { default: path } = await import('node:path');
|
|
975
732
|
const { promises } = await import('node:fs');
|
|
@@ -988,23 +745,12 @@ export class PluginManager extends EventEmitter {
|
|
|
988
745
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
989
746
|
}
|
|
990
747
|
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);
|
|
992
748
|
}
|
|
993
749
|
catch (err) {
|
|
994
750
|
this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
|
|
995
751
|
return;
|
|
996
752
|
}
|
|
997
753
|
}
|
|
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
|
-
*/
|
|
1008
754
|
async loadSchema(plugin) {
|
|
1009
755
|
const { promises } = await import('node:fs');
|
|
1010
756
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -1015,7 +761,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1015
761
|
schema.title = plugin.description;
|
|
1016
762
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
1017
763
|
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);
|
|
1019
764
|
return schema;
|
|
1020
765
|
}
|
|
1021
766
|
catch (_err) {
|
|
@@ -1023,16 +768,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1023
768
|
return this.getDefaultSchema(plugin);
|
|
1024
769
|
}
|
|
1025
770
|
}
|
|
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
|
-
*/
|
|
1036
771
|
getDefaultSchema(plugin) {
|
|
1037
772
|
return {
|
|
1038
773
|
title: plugin.description,
|
|
@@ -1063,4 +798,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1063
798
|
};
|
|
1064
799
|
}
|
|
1065
800
|
}
|
|
1066
|
-
//# sourceMappingURL=pluginManager.js.map
|