matterbridge 2.1.6-dev.3 → 2.1.6-dev.4

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.
@@ -1,10 +1,5 @@
1
- import { AnsiLogger, BLUE, db, er, nf, nt, rs, UNDERLINE, UNDERLINEOFF, wr } from './logger/export.js';
2
- import path from 'path';
3
- import { promises as fs } from 'fs';
4
- import { pathToFileURL } from 'url';
5
- import { exec } from 'child_process';
1
+ import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr } from './logger/export.js';
6
2
  import { plg, typ } from './matterbridgeTypes.js';
7
- import { shelly_config, somfytahoma_config, zigbee2mqtt_config } from './defaultConfigSchema.js';
8
3
  export class PluginManager {
9
4
  _plugins = new Map();
10
5
  nodeContext;
@@ -84,12 +79,14 @@ export class PluginManager {
84
79
  return plugins.length;
85
80
  }
86
81
  async resolve(pluginPath) {
82
+ const { default: path } = await import('node:path');
83
+ const { promises } = await import('node:fs');
87
84
  if (!pluginPath.endsWith('package.json'))
88
85
  pluginPath = path.join(pluginPath, 'package.json');
89
86
  let packageJsonPath = path.resolve(pluginPath);
90
87
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
91
88
  try {
92
- await fs.access(packageJsonPath);
89
+ await promises.access(packageJsonPath);
93
90
  }
94
91
  catch {
95
92
  this.log.debug(`Package.json not found at ${plg}${packageJsonPath}${db}`);
@@ -97,7 +94,7 @@ export class PluginManager {
97
94
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
98
95
  }
99
96
  try {
100
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
97
+ const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
101
98
  if (!packageJson.name) {
102
99
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
103
100
  return null;
@@ -161,9 +158,10 @@ export class PluginManager {
161
158
  }
162
159
  }
163
160
  async parse(plugin) {
164
- this.log.debug(`Parsing package.json of plugin ${plg}${plugin.name}${db}`);
161
+ const { promises } = await import('node:fs');
165
162
  try {
166
- const packageJson = JSON.parse(await fs.readFile(plugin.path, 'utf8'));
163
+ this.log.debug(`Parsing package.json of plugin ${plg}${plugin.name}${db}`);
164
+ const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
167
165
  if (!packageJson.name)
168
166
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no name in package.json`);
169
167
  if (!packageJson.version)
@@ -235,6 +233,7 @@ export class PluginManager {
235
233
  }
236
234
  }
237
235
  async enable(nameOrPath) {
236
+ const { promises } = await import('node:fs');
238
237
  if (!nameOrPath || nameOrPath === '')
239
238
  return null;
240
239
  if (this._plugins.has(nameOrPath)) {
@@ -250,7 +249,7 @@ export class PluginManager {
250
249
  return null;
251
250
  }
252
251
  try {
253
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
252
+ const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
254
253
  const plugin = this._plugins.get(packageJson.name);
255
254
  if (!plugin) {
256
255
  this.log.error(`Failed to enable plugin ${plg}${nameOrPath}${er}: plugin not registered`);
@@ -267,6 +266,7 @@ export class PluginManager {
267
266
  }
268
267
  }
269
268
  async disable(nameOrPath) {
269
+ const { promises } = await import('node:fs');
270
270
  if (!nameOrPath || nameOrPath === '')
271
271
  return null;
272
272
  if (this._plugins.has(nameOrPath)) {
@@ -282,7 +282,7 @@ export class PluginManager {
282
282
  return null;
283
283
  }
284
284
  try {
285
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
285
+ const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
286
286
  const plugin = this._plugins.get(packageJson.name);
287
287
  if (!plugin) {
288
288
  this.log.error(`Failed to disable plugin ${plg}${nameOrPath}${er}: plugin not registered`);
@@ -299,6 +299,7 @@ export class PluginManager {
299
299
  }
300
300
  }
301
301
  async remove(nameOrPath) {
302
+ const { promises } = await import('node:fs');
302
303
  if (!nameOrPath || nameOrPath === '')
303
304
  return null;
304
305
  if (this._plugins.has(nameOrPath)) {
@@ -314,7 +315,7 @@ export class PluginManager {
314
315
  return null;
315
316
  }
316
317
  try {
317
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
318
+ const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
318
319
  const plugin = this._plugins.get(packageJson.name);
319
320
  if (!plugin) {
320
321
  this.log.error(`Failed to remove plugin ${plg}${nameOrPath}${er}: plugin not registered`);
@@ -331,6 +332,7 @@ export class PluginManager {
331
332
  }
332
333
  }
333
334
  async add(nameOrPath) {
335
+ const { promises } = await import('node:fs');
334
336
  if (!nameOrPath || nameOrPath === '')
335
337
  return null;
336
338
  const packageJsonPath = await this.resolve(nameOrPath);
@@ -339,7 +341,7 @@ export class PluginManager {
339
341
  return null;
340
342
  }
341
343
  try {
342
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
344
+ const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
343
345
  if (this._plugins.get(packageJson.name)) {
344
346
  this.log.info(`Plugin ${plg}${nameOrPath}${nf} already registered`);
345
347
  return null;
@@ -351,15 +353,16 @@ export class PluginManager {
351
353
  return plugin || null;
352
354
  }
353
355
  catch (err) {
354
- this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err}`);
356
+ this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err instanceof Error ? err.message : err}`);
355
357
  return null;
356
358
  }
357
359
  }
358
360
  async install(name) {
361
+ const { exec } = await import('node:child_process');
359
362
  await this.uninstall(name);
360
363
  this.log.info(`Installing plugin ${plg}${name}${nf}`);
361
- return new Promise((resolve, reject) => {
362
- exec(`npm install -g ${name} --omit=dev --force`, (error, stdout, stderr) => {
364
+ return new Promise((resolve) => {
365
+ exec(`npm install -g ${name} --omit=dev`, (error, stdout, stderr) => {
363
366
  if (error) {
364
367
  this.log.error(`Failed to install plugin ${plg}${name}${er}: ${error}`);
365
368
  this.log.debug(`Failed to install plugin ${plg}${name}${db}: ${stderr}`);
@@ -389,9 +392,10 @@ export class PluginManager {
389
392
  });
390
393
  }
391
394
  async uninstall(name) {
395
+ const { exec } = await import('node:child_process');
392
396
  this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
393
- return new Promise((resolve, reject) => {
394
- exec(`npm uninstall -g ${name} --force`, (error, stdout, stderr) => {
397
+ return new Promise((resolve) => {
398
+ exec(`npm uninstall -g ${name}`, (error, stdout, stderr) => {
395
399
  if (error) {
396
400
  this.log.error(`Failed to uninstall plugin ${plg}${name}${er}: ${error}`);
397
401
  this.log.debug(`Failed to uninstall plugin ${plg}${name}${db}: ${stderr}`);
@@ -406,6 +410,8 @@ export class PluginManager {
406
410
  });
407
411
  }
408
412
  async load(plugin, start = false, message = '', configure = false) {
413
+ const { promises } = await import('node:fs');
414
+ const { default: path } = await import('node:path');
409
415
  if (!plugin.enabled) {
410
416
  this.log.error(`Plugin ${plg}${plugin.name}${er} not enabled`);
411
417
  return undefined;
@@ -416,8 +422,9 @@ export class PluginManager {
416
422
  }
417
423
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
418
424
  try {
419
- const packageJson = JSON.parse(await fs.readFile(plugin.path, 'utf8'));
425
+ const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
420
426
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
427
+ const { pathToFileURL } = await import('node:url');
421
428
  const pluginUrl = pathToFileURL(pluginEntry);
422
429
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
423
430
  const pluginInstance = await import(pluginUrl.href);
@@ -570,10 +577,13 @@ export class PluginManager {
570
577
  return undefined;
571
578
  }
572
579
  async loadConfig(plugin) {
580
+ const { default: path } = await import('node:path');
581
+ const { promises } = await import('node:fs');
582
+ const { shelly_config, somfytahoma_config, zigbee2mqtt_config } = await import('./defaultConfigSchema.js');
573
583
  const configFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.config.json`);
574
584
  try {
575
- await fs.access(configFile);
576
- const data = await fs.readFile(configFile, 'utf8');
585
+ await promises.access(configFile);
586
+ const data = await promises.readFile(configFile, 'utf8');
577
587
  const config = JSON.parse(data);
578
588
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
579
589
  config.name = plugin.name;
@@ -597,7 +607,7 @@ export class PluginManager {
597
607
  else
598
608
  config = { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
599
609
  try {
600
- await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
610
+ await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
601
611
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
602
612
  return config;
603
613
  }
@@ -613,13 +623,15 @@ export class PluginManager {
613
623
  }
614
624
  }
615
625
  async saveConfigFromPlugin(plugin) {
626
+ const { default: path } = await import('node:path');
627
+ const { promises } = await import('node:fs');
616
628
  if (!plugin.platform?.config) {
617
629
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}: config not found`);
618
630
  return Promise.reject(new Error(`Error saving config file for plugin ${plg}${plugin.name}${er}: config not found`));
619
631
  }
620
632
  const configFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.config.json`);
621
633
  try {
622
- await fs.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
634
+ await promises.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
623
635
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
624
636
  return Promise.resolve();
625
637
  }
@@ -629,13 +641,15 @@ export class PluginManager {
629
641
  }
630
642
  }
631
643
  async saveConfigFromJson(plugin, config) {
644
+ const { default: path } = await import('node:path');
645
+ const { promises } = await import('node:fs');
632
646
  if (!config.name || !config.type || config.name !== plugin.name) {
633
647
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}. Wrong config data content:${rs}\n`, config);
634
648
  return;
635
649
  }
636
650
  const configFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.config.json`);
637
651
  try {
638
- await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
652
+ await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
639
653
  plugin.configJson = config;
640
654
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
641
655
  }
@@ -645,10 +659,11 @@ export class PluginManager {
645
659
  }
646
660
  }
647
661
  async loadSchema(plugin) {
662
+ const { promises } = await import('node:fs');
648
663
  const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
649
664
  try {
650
- await fs.access(schemaFile);
651
- const data = await fs.readFile(schemaFile, 'utf8');
665
+ await promises.access(schemaFile);
666
+ const data = await promises.readFile(schemaFile, 'utf8');
652
667
  const schema = JSON.parse(data);
653
668
  schema.title = plugin.description;
654
669
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.cf25d33e.css",
4
- "main.js": "./static/js/main.a241d4f0.js",
4
+ "main.js": "./static/js/main.257513e8.js",
5
5
  "static/js/453.abd36b29.chunk.js": "./static/js/453.abd36b29.chunk.js",
6
6
  "static/media/roboto-latin-700-normal.woff2": "./static/media/roboto-latin-700-normal.4535474e1cf8598695ad.woff2",
7
7
  "static/media/roboto-latin-500-normal.woff2": "./static/media/roboto-latin-500-normal.7077203b1982951ecf76.woff2",
@@ -61,11 +61,11 @@
61
61
  "static/media/roboto-greek-ext-400-normal.woff": "./static/media/roboto-greek-ext-400-normal.16eb83b4a3b1ea994243.woff",
62
62
  "index.html": "./index.html",
63
63
  "main.cf25d33e.css.map": "./static/css/main.cf25d33e.css.map",
64
- "main.a241d4f0.js.map": "./static/js/main.a241d4f0.js.map",
64
+ "main.257513e8.js.map": "./static/js/main.257513e8.js.map",
65
65
  "453.abd36b29.chunk.js.map": "./static/js/453.abd36b29.chunk.js.map"
66
66
  },
67
67
  "entrypoints": [
68
68
  "static/css/main.cf25d33e.css",
69
- "static/js/main.a241d4f0.js"
69
+ "static/js/main.257513e8.js"
70
70
  ]
71
71
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.a241d4f0.js"></script><link href="./static/css/main.cf25d33e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.257513e8.js"></script><link href="./static/css/main.cf25d33e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>