matterbridge 3.1.3 → 3.1.4-dev-20250715-075e722
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 +16 -0
- package/README.md +18 -18
- 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 +6 -89
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/waterHeater.js +2 -82
- package/dist/frontend.js +18 -423
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -30
- 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 +55 -788
- 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 -1106
- 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 +16 -96
- package/dist/utils/spawn.js +0 -18
- package/dist/utils/wait.js +9 -62
- package/npm-shrinkwrap.json +3 -3
- package/package.json +2 -3
- 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 -110
- 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 -303
- 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 -33
- 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 -444
- 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 -1250
- 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 -195
- 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/bin/{matterbridge → matterbridge.js} +0 -0
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) {
|
|
@@ -123,21 +78,13 @@ export class PluginManager extends EventEmitter {
|
|
|
123
78
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
124
79
|
return plugins.length;
|
|
125
80
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
128
|
-
*
|
|
129
|
-
* @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
130
|
-
* @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.
|
|
131
|
-
*/
|
|
132
81
|
async resolve(pluginPath) {
|
|
133
82
|
const { default: path } = await import('node:path');
|
|
134
83
|
const { promises } = await import('node:fs');
|
|
135
84
|
if (!pluginPath.endsWith('package.json'))
|
|
136
85
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
137
|
-
// Resolve the package.json of the plugin
|
|
138
86
|
let packageJsonPath = path.resolve(pluginPath);
|
|
139
87
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
140
|
-
// Check if the package.json file exists
|
|
141
88
|
try {
|
|
142
89
|
await promises.access(packageJsonPath);
|
|
143
90
|
}
|
|
@@ -147,9 +94,7 @@ export class PluginManager extends EventEmitter {
|
|
|
147
94
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
148
95
|
}
|
|
149
96
|
try {
|
|
150
|
-
// Load the package.json of the plugin
|
|
151
97
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
152
|
-
// Check for main issues
|
|
153
98
|
if (!packageJson.name) {
|
|
154
99
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
155
100
|
return null;
|
|
@@ -162,7 +107,6 @@ export class PluginManager extends EventEmitter {
|
|
|
162
107
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
163
108
|
return null;
|
|
164
109
|
}
|
|
165
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
166
110
|
const checkForProjectChipPackages = (dependencies) => {
|
|
167
111
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
168
112
|
};
|
|
@@ -184,7 +128,6 @@ export class PluginManager extends EventEmitter {
|
|
|
184
128
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
185
129
|
return null;
|
|
186
130
|
}
|
|
187
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
188
131
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
189
132
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
190
133
|
};
|
|
@@ -214,12 +157,6 @@ export class PluginManager extends EventEmitter {
|
|
|
214
157
|
return null;
|
|
215
158
|
}
|
|
216
159
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Get the author of a plugin from its package.json.
|
|
219
|
-
*
|
|
220
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
221
|
-
* @returns {string} The author of the plugin, or 'Unknown author' if not found.
|
|
222
|
-
*/
|
|
223
160
|
getAuthor(packageJson) {
|
|
224
161
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
225
162
|
return packageJson.author;
|
|
@@ -227,12 +164,6 @@ export class PluginManager extends EventEmitter {
|
|
|
227
164
|
return packageJson.author.name;
|
|
228
165
|
return 'Unknown author';
|
|
229
166
|
}
|
|
230
|
-
/**
|
|
231
|
-
* Get the homepage of a plugin from its package.json.
|
|
232
|
-
*
|
|
233
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
234
|
-
* @returns {string | undefined} The homepage of the plugin, or undefined if not found.
|
|
235
|
-
*/
|
|
236
167
|
getHomepage(packageJson) {
|
|
237
168
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
238
169
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -241,14 +172,7 @@ export class PluginManager extends EventEmitter {
|
|
|
241
172
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
242
173
|
}
|
|
243
174
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Get the help URL of a plugin from its package.json.
|
|
246
|
-
*
|
|
247
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
248
|
-
* @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
|
|
249
|
-
*/
|
|
250
175
|
getHelp(packageJson) {
|
|
251
|
-
// If there's a help field that looks like a URL, return it.
|
|
252
176
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
253
177
|
return packageJson.help;
|
|
254
178
|
}
|
|
@@ -259,14 +183,7 @@ export class PluginManager extends EventEmitter {
|
|
|
259
183
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
260
184
|
}
|
|
261
185
|
}
|
|
262
|
-
/**
|
|
263
|
-
* Get the changelog URL of a plugin from its package.json.
|
|
264
|
-
*
|
|
265
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
266
|
-
* @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
|
|
267
|
-
*/
|
|
268
186
|
getChangelog(packageJson) {
|
|
269
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
270
187
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
271
188
|
return packageJson.changelog;
|
|
272
189
|
}
|
|
@@ -277,13 +194,6 @@ export class PluginManager extends EventEmitter {
|
|
|
277
194
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
278
195
|
}
|
|
279
196
|
}
|
|
280
|
-
/**
|
|
281
|
-
* Get the first funding URL(s) of a plugin from its package.json.
|
|
282
|
-
*
|
|
283
|
-
* @param {Record<string, any>} packageJson - The package.json object of the plugin.
|
|
284
|
-
* @returns {string | undefined} The first funding URLs, or undefined if not found.
|
|
285
|
-
*/
|
|
286
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
287
197
|
getFunding(packageJson) {
|
|
288
198
|
const funding = packageJson.funding;
|
|
289
199
|
if (!funding)
|
|
@@ -292,25 +202,16 @@ export class PluginManager extends EventEmitter {
|
|
|
292
202
|
return;
|
|
293
203
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
294
204
|
return funding;
|
|
295
|
-
// Normalize funding into an array.
|
|
296
205
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
297
206
|
for (const entry of fundingEntries) {
|
|
298
207
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
299
|
-
// If the funding entry is a string, assume it is a URL.
|
|
300
208
|
return entry;
|
|
301
209
|
}
|
|
302
210
|
else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
|
|
303
|
-
// If it's an object with a 'url' property, use that.
|
|
304
211
|
return entry.url;
|
|
305
212
|
}
|
|
306
213
|
}
|
|
307
214
|
}
|
|
308
|
-
/**
|
|
309
|
-
* Loads and parse the plugin package.json and returns it.
|
|
310
|
-
*
|
|
311
|
-
* @param {RegisteredPlugin} plugin - The plugin to load the package from.
|
|
312
|
-
* @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.
|
|
313
|
-
*/
|
|
314
215
|
async parse(plugin) {
|
|
315
216
|
const { promises } = await import('node:fs');
|
|
316
217
|
try {
|
|
@@ -340,7 +241,6 @@ export class PluginManager extends EventEmitter {
|
|
|
340
241
|
plugin.funding = this.getFunding(packageJson);
|
|
341
242
|
if (!plugin.type)
|
|
342
243
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
343
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
344
244
|
const checkForProjectChipPackages = (dependencies) => {
|
|
345
245
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
346
246
|
};
|
|
@@ -362,7 +262,6 @@ export class PluginManager extends EventEmitter {
|
|
|
362
262
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
363
263
|
return null;
|
|
364
264
|
}
|
|
365
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
366
265
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
367
266
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
368
267
|
};
|
|
@@ -392,16 +291,6 @@ export class PluginManager extends EventEmitter {
|
|
|
392
291
|
return null;
|
|
393
292
|
}
|
|
394
293
|
}
|
|
395
|
-
/**
|
|
396
|
-
* Enables a plugin by its name or path.
|
|
397
|
-
*
|
|
398
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
399
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
400
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
401
|
-
*
|
|
402
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
403
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
404
|
-
*/
|
|
405
294
|
async enable(nameOrPath) {
|
|
406
295
|
const { promises } = await import('node:fs');
|
|
407
296
|
if (!nameOrPath)
|
|
@@ -437,16 +326,6 @@ export class PluginManager extends EventEmitter {
|
|
|
437
326
|
return null;
|
|
438
327
|
}
|
|
439
328
|
}
|
|
440
|
-
/**
|
|
441
|
-
* Enables a plugin by its name or path.
|
|
442
|
-
*
|
|
443
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
444
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
445
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
446
|
-
*
|
|
447
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
448
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
449
|
-
*/
|
|
450
329
|
async disable(nameOrPath) {
|
|
451
330
|
const { promises } = await import('node:fs');
|
|
452
331
|
if (!nameOrPath)
|
|
@@ -482,16 +361,6 @@ export class PluginManager extends EventEmitter {
|
|
|
482
361
|
return null;
|
|
483
362
|
}
|
|
484
363
|
}
|
|
485
|
-
/**
|
|
486
|
-
* Removes a plugin by its name or path.
|
|
487
|
-
*
|
|
488
|
-
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
489
|
-
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
490
|
-
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
491
|
-
*
|
|
492
|
-
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
493
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
494
|
-
*/
|
|
495
364
|
async remove(nameOrPath) {
|
|
496
365
|
const { promises } = await import('node:fs');
|
|
497
366
|
if (!nameOrPath)
|
|
@@ -527,17 +396,6 @@ export class PluginManager extends EventEmitter {
|
|
|
527
396
|
return null;
|
|
528
397
|
}
|
|
529
398
|
}
|
|
530
|
-
/**
|
|
531
|
-
* Adds a plugin by its name or path.
|
|
532
|
-
*
|
|
533
|
-
* This method adds a plugin to the plugins map and saves the updated plugin information to storage.
|
|
534
|
-
* It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
|
|
535
|
-
* registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
|
|
536
|
-
* and saves the updated plugin information to storage.
|
|
537
|
-
*
|
|
538
|
-
* @param {string} nameOrPath - The name or path of the plugin to add.
|
|
539
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
|
|
540
|
-
*/
|
|
541
399
|
async add(nameOrPath) {
|
|
542
400
|
const { promises } = await import('node:fs');
|
|
543
401
|
if (!nameOrPath)
|
|
@@ -573,15 +431,6 @@ export class PluginManager extends EventEmitter {
|
|
|
573
431
|
return null;
|
|
574
432
|
}
|
|
575
433
|
}
|
|
576
|
-
/**
|
|
577
|
-
* Installs a plugin by its name.
|
|
578
|
-
*
|
|
579
|
-
* This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
|
|
580
|
-
* It logs the installation process and retrieves the installed version of the plugin.
|
|
581
|
-
*
|
|
582
|
-
* @param {string} name - The name of the plugin to install.
|
|
583
|
-
* @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
|
|
584
|
-
*/
|
|
585
434
|
async install(name) {
|
|
586
435
|
const { exec } = await import('node:child_process');
|
|
587
436
|
await this.uninstall(name);
|
|
@@ -596,14 +445,11 @@ export class PluginManager extends EventEmitter {
|
|
|
596
445
|
else {
|
|
597
446
|
this.log.info(`Installed plugin ${plg}${name}${nf}`);
|
|
598
447
|
this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
|
|
599
|
-
// Get the installed version
|
|
600
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
601
448
|
exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
|
|
602
449
|
if (listError) {
|
|
603
450
|
this.log.error(`List error: ${listError}`);
|
|
604
451
|
resolve(undefined);
|
|
605
452
|
}
|
|
606
|
-
// Clean the output to get only the package name and version
|
|
607
453
|
const lines = listStdout.split('\n');
|
|
608
454
|
const versionLine = lines.find((line) => line.includes(`${name}@`));
|
|
609
455
|
if (versionLine) {
|
|
@@ -620,15 +466,6 @@ export class PluginManager extends EventEmitter {
|
|
|
620
466
|
});
|
|
621
467
|
});
|
|
622
468
|
}
|
|
623
|
-
/**
|
|
624
|
-
* Uninstalls a plugin by its name.
|
|
625
|
-
*
|
|
626
|
-
* This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
|
|
627
|
-
* and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
|
|
628
|
-
*
|
|
629
|
-
* @param {string} name - The name of the plugin to uninstall.
|
|
630
|
-
* @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
|
|
631
|
-
*/
|
|
632
469
|
async uninstall(name) {
|
|
633
470
|
const { exec } = await import('node:child_process');
|
|
634
471
|
this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
|
|
@@ -648,15 +485,6 @@ export class PluginManager extends EventEmitter {
|
|
|
648
485
|
});
|
|
649
486
|
});
|
|
650
487
|
}
|
|
651
|
-
/**
|
|
652
|
-
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
653
|
-
*
|
|
654
|
-
* @param {RegisteredPlugin} plugin - The plugin to load.
|
|
655
|
-
* @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
656
|
-
* @param {string} message - Optional message to pass to the plugin when starting.
|
|
657
|
-
* @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
|
|
658
|
-
* @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
|
|
659
|
-
*/
|
|
660
488
|
async load(plugin, start = false, message = '', configure = false) {
|
|
661
489
|
const { promises } = await import('node:fs');
|
|
662
490
|
const { default: path } = await import('node:path');
|
|
@@ -670,20 +498,15 @@ export class PluginManager extends EventEmitter {
|
|
|
670
498
|
}
|
|
671
499
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
672
500
|
try {
|
|
673
|
-
// Load the package.json of the plugin
|
|
674
501
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
675
|
-
// Resolve the main module path relative to package.json
|
|
676
502
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
677
|
-
// Dynamically import the plugin
|
|
678
503
|
const { pathToFileURL } = await import('node:url');
|
|
679
504
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
680
505
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
681
506
|
const pluginInstance = await import(pluginUrl.href);
|
|
682
507
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
683
|
-
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
684
508
|
if (pluginInstance.default) {
|
|
685
509
|
const config = await this.loadConfig(plugin);
|
|
686
|
-
// 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.
|
|
687
510
|
plugin.name = packageJson.name;
|
|
688
511
|
plugin.description = packageJson.description ?? 'No description';
|
|
689
512
|
plugin.version = packageJson.version;
|
|
@@ -692,7 +515,7 @@ export class PluginManager extends EventEmitter {
|
|
|
692
515
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
693
516
|
config.name = plugin.name;
|
|
694
517
|
config.version = packageJson.version;
|
|
695
|
-
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4
|
|
518
|
+
const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
696
519
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
697
520
|
config.type = platform.type;
|
|
698
521
|
platform.name = packageJson.name;
|
|
@@ -711,7 +534,7 @@ export class PluginManager extends EventEmitter {
|
|
|
711
534
|
plugin.loaded = true;
|
|
712
535
|
plugin.registeredDevices = 0;
|
|
713
536
|
plugin.addedDevices = 0;
|
|
714
|
-
await this.saveToStorage();
|
|
537
|
+
await this.saveToStorage();
|
|
715
538
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
716
539
|
this.emit('loaded', plugin.name);
|
|
717
540
|
if (start)
|
|
@@ -731,14 +554,6 @@ export class PluginManager extends EventEmitter {
|
|
|
731
554
|
}
|
|
732
555
|
return undefined;
|
|
733
556
|
}
|
|
734
|
-
/**
|
|
735
|
-
* Starts a plugin.
|
|
736
|
-
*
|
|
737
|
-
* @param {RegisteredPlugin} plugin - The plugin to start.
|
|
738
|
-
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
739
|
-
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
740
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
741
|
-
*/
|
|
742
557
|
async start(plugin, message, configure = false) {
|
|
743
558
|
if (!plugin.loaded) {
|
|
744
559
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -769,12 +584,6 @@ export class PluginManager extends EventEmitter {
|
|
|
769
584
|
}
|
|
770
585
|
return undefined;
|
|
771
586
|
}
|
|
772
|
-
/**
|
|
773
|
-
* Configures a plugin.
|
|
774
|
-
*
|
|
775
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
776
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
777
|
-
*/
|
|
778
587
|
async configure(plugin) {
|
|
779
588
|
if (!plugin.loaded) {
|
|
780
589
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -806,18 +615,6 @@ export class PluginManager extends EventEmitter {
|
|
|
806
615
|
}
|
|
807
616
|
return undefined;
|
|
808
617
|
}
|
|
809
|
-
/**
|
|
810
|
-
* Shuts down a plugin.
|
|
811
|
-
*
|
|
812
|
-
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
813
|
-
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
814
|
-
*
|
|
815
|
-
* @param {RegisteredPlugin} plugin - The plugin to shut down.
|
|
816
|
-
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
817
|
-
* @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
|
|
818
|
-
* @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
819
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
820
|
-
*/
|
|
821
618
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
822
619
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
823
620
|
if (!plugin.loaded) {
|
|
@@ -861,15 +658,6 @@ export class PluginManager extends EventEmitter {
|
|
|
861
658
|
}
|
|
862
659
|
return undefined;
|
|
863
660
|
}
|
|
864
|
-
/**
|
|
865
|
-
* Loads the configuration for a plugin.
|
|
866
|
-
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
867
|
-
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
868
|
-
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
869
|
-
*
|
|
870
|
-
* @param {RegisteredPlugin} plugin - The plugin for which to load the configuration.
|
|
871
|
-
* @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
|
|
872
|
-
*/
|
|
873
661
|
async loadConfig(plugin) {
|
|
874
662
|
const { default: path } = await import('node:path');
|
|
875
663
|
const { promises } = await import('node:fs');
|
|
@@ -880,8 +668,6 @@ export class PluginManager extends EventEmitter {
|
|
|
880
668
|
const data = await promises.readFile(configFile, 'utf8');
|
|
881
669
|
const config = JSON.parse(data);
|
|
882
670
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
883
|
-
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
884
|
-
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
885
671
|
config.name = plugin.name;
|
|
886
672
|
config.type = plugin.type;
|
|
887
673
|
if (config.debug === undefined)
|
|
@@ -905,7 +691,6 @@ export class PluginManager extends EventEmitter {
|
|
|
905
691
|
try {
|
|
906
692
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
907
693
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
908
|
-
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
909
694
|
return config;
|
|
910
695
|
}
|
|
911
696
|
catch (err) {
|
|
@@ -919,19 +704,6 @@ export class PluginManager extends EventEmitter {
|
|
|
919
704
|
}
|
|
920
705
|
}
|
|
921
706
|
}
|
|
922
|
-
/**
|
|
923
|
-
* Saves the configuration of a plugin to a file.
|
|
924
|
-
*
|
|
925
|
-
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
926
|
-
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
927
|
-
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
928
|
-
* the error and rejects the promise.
|
|
929
|
-
*
|
|
930
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
931
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
932
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
933
|
-
* @throws {Error} If the plugin's configuration is not found.
|
|
934
|
-
*/
|
|
935
707
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
936
708
|
const { default: path } = await import('node:path');
|
|
937
709
|
const { promises } = await import('node:fs');
|
|
@@ -946,7 +718,6 @@ export class PluginManager extends EventEmitter {
|
|
|
946
718
|
if (restartRequired)
|
|
947
719
|
plugin.restartRequired = true;
|
|
948
720
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
949
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
950
721
|
return Promise.resolve();
|
|
951
722
|
}
|
|
952
723
|
catch (err) {
|
|
@@ -954,20 +725,6 @@ export class PluginManager extends EventEmitter {
|
|
|
954
725
|
return Promise.reject(err);
|
|
955
726
|
}
|
|
956
727
|
}
|
|
957
|
-
/**
|
|
958
|
-
* Saves the configuration of a plugin from a JSON object to a file.
|
|
959
|
-
*
|
|
960
|
-
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
961
|
-
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
962
|
-
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
963
|
-
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
964
|
-
* during the file write operation, it logs the error and returns.
|
|
965
|
-
*
|
|
966
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
967
|
-
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
968
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
969
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
970
|
-
*/
|
|
971
728
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
972
729
|
const { default: path } = await import('node:path');
|
|
973
730
|
const { promises } = await import('node:fs');
|
|
@@ -986,23 +743,12 @@ export class PluginManager extends EventEmitter {
|
|
|
986
743
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
987
744
|
}
|
|
988
745
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
989
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
990
746
|
}
|
|
991
747
|
catch (err) {
|
|
992
748
|
this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
|
|
993
749
|
return;
|
|
994
750
|
}
|
|
995
751
|
}
|
|
996
|
-
/**
|
|
997
|
-
* Loads the schema for a plugin.
|
|
998
|
-
*
|
|
999
|
-
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
1000
|
-
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
1001
|
-
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
1002
|
-
*
|
|
1003
|
-
* @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
|
|
1004
|
-
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
1005
|
-
*/
|
|
1006
752
|
async loadSchema(plugin) {
|
|
1007
753
|
const { promises } = await import('node:fs');
|
|
1008
754
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -1013,7 +759,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1013
759
|
schema.title = plugin.description;
|
|
1014
760
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
1015
761
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1016
|
-
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
1017
762
|
return schema;
|
|
1018
763
|
}
|
|
1019
764
|
catch (_err) {
|
|
@@ -1021,16 +766,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1021
766
|
return this.getDefaultSchema(plugin);
|
|
1022
767
|
}
|
|
1023
768
|
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Returns the default schema for a plugin.
|
|
1026
|
-
*
|
|
1027
|
-
* This method generates a default schema object for the specified plugin. The schema includes
|
|
1028
|
-
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
1029
|
-
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
1030
|
-
*
|
|
1031
|
-
* @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
|
|
1032
|
-
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
1033
|
-
*/
|
|
1034
769
|
getDefaultSchema(plugin) {
|
|
1035
770
|
return {
|
|
1036
771
|
title: plugin.description,
|
|
@@ -1061,4 +796,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1061
796
|
};
|
|
1062
797
|
}
|
|
1063
798
|
}
|
|
1064
|
-
//# sourceMappingURL=pluginManager.js.map
|