matterbridge 3.0.7-dev-20250618-fb768ee → 3.0.7
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 +3 -2
- package/README-DEV.md +4 -4
- package/dist/cli.d.ts +29 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +62 -2
- package/dist/cli.js.map +1 -0
- package/dist/clusters/export.d.ts +2 -0
- package/dist/clusters/export.d.ts.map +1 -0
- package/dist/clusters/export.js +2 -0
- package/dist/clusters/export.js.map +1 -0
- package/dist/defaultConfigSchema.d.ts +27 -0
- package/dist/defaultConfigSchema.d.ts.map +1 -0
- package/dist/defaultConfigSchema.js +23 -0
- package/dist/defaultConfigSchema.js.map +1 -0
- package/dist/deviceManager.d.ts +114 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +94 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/export.d.ts +5 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +2 -0
- package/dist/devices/export.js.map +1 -0
- package/dist/evse.d.ts +67 -0
- package/dist/evse.d.ts.map +1 -0
- package/dist/evse.js +65 -9
- package/dist/evse.js.map +1 -0
- package/dist/frontend.d.ts +256 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +374 -16
- package/dist/frontend.js.map +1 -0
- package/dist/globalMatterbridge.d.ts +32 -0
- package/dist/globalMatterbridge.d.ts.map +1 -0
- package/dist/globalMatterbridge.js +20 -0
- package/dist/globalMatterbridge.js.map +1 -0
- package/dist/helpers.d.ts +47 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +51 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -0
- package/dist/laundryWasher.d.ts +243 -0
- package/dist/laundryWasher.d.ts.map +1 -0
- package/dist/laundryWasher.js +92 -7
- package/dist/laundryWasher.js.map +1 -0
- package/dist/logger/export.d.ts +2 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +2 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +2 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +2 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +2 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +5 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +2 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +3 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +2 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterbridge.d.ts +445 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +748 -46
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +40 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +34 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +1333 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +54 -1
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +644 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +578 -15
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +40 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +34 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1145 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +995 -40
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +3083 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +204 -10
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +290 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +221 -6
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +196 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +24 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +273 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +269 -3
- package/dist/pluginManager.js.map +1 -0
- package/dist/roboticVacuumCleaner.d.ts +102 -0
- package/dist/roboticVacuumCleaner.d.ts.map +1 -0
- package/dist/roboticVacuumCleaner.js +81 -6
- package/dist/roboticVacuumCleaner.js.map +1 -0
- package/dist/shelly.d.ts +161 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +155 -7
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +2 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +58 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +53 -0
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +61 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +205 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/commandLine.d.ts +58 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +53 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +32 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +37 -1
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createDirectory.d.ts +32 -0
- package/dist/utils/createDirectory.d.ts.map +1 -0
- package/dist/utils/createDirectory.js +31 -0
- package/dist/utils/createDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +38 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +42 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +31 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +38 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +53 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +71 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/export.d.ts +12 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/hex.d.ts +48 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +57 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/isvalid.d.ts +102 -0
- package/dist/utils/isvalid.d.ts.map +1 -0
- package/dist/utils/isvalid.js +100 -0
- package/dist/utils/isvalid.js.map +1 -0
- package/dist/utils/network.d.ts +69 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +76 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/spawn.d.ts +12 -0
- package/dist/utils/spawn.d.ts.map +1 -0
- package/dist/utils/spawn.js +16 -0
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/wait.d.ts +52 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +58 -9
- package/dist/utils/wait.js.map +1 -0
- package/dist/waterHeater.d.ts +90 -0
- package/dist/waterHeater.d.ts.map +1 -0
- package/dist/waterHeater.js +62 -2
- package/dist/waterHeater.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the validation functions.
|
|
3
|
+
*
|
|
4
|
+
* @file isvalid.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License. *
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a given string is a valid IPv4 address.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} ipv4Address - The string to be checked.
|
|
27
|
+
* @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isValidIpv4Address(ipv4Address: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if a value is a valid number within the specified range.
|
|
32
|
+
*
|
|
33
|
+
* @param {any} value - The value to be checked.
|
|
34
|
+
* @param {number} min - The minimum value allowed (optional).
|
|
35
|
+
* @param {number} max - The maximum value allowed (optional).
|
|
36
|
+
* @returns {value is number} Returns true if the value is a valid number within the specified range, otherwise false.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isValidNumber(value: any, min?: number, max?: number): value is number;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a value is a valid boolean.
|
|
41
|
+
*
|
|
42
|
+
* @param {any} value - The value to be checked.
|
|
43
|
+
* @returns {value is boolean} `true` if the value is a valid boolean, `false` otherwise.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isValidBoolean(value: any): value is boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a value is a valid string.
|
|
48
|
+
*
|
|
49
|
+
* @param {any} value - The value to be checked.
|
|
50
|
+
* @param {number} minLength - The min string length (optional).
|
|
51
|
+
* @param {number} maxLength - The max string length (optional).
|
|
52
|
+
* @returns {value is string} A boolean indicating whether the value is a valid string.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isValidString(value: any, minLength?: number, maxLength?: number): value is string;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a value is a valid RegExp.
|
|
57
|
+
*
|
|
58
|
+
* @param {any} value - The value to be checked.
|
|
59
|
+
* @returns {value is RegExp} A boolean indicating whether the value is a valid RegExp.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isValidRegExp(value: any): value is RegExp;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a value is a valid object.
|
|
64
|
+
*
|
|
65
|
+
* @param {any} value - The value to be checked.
|
|
66
|
+
* @param {number} minLength - The min number of keys (optional).
|
|
67
|
+
* @param {number} maxLength - The max number of keys (optional).
|
|
68
|
+
* @returns {value is object} A boolean indicating whether the value is a valid object.
|
|
69
|
+
*/
|
|
70
|
+
export declare function isValidObject(value: any, minLength?: number, maxLength?: number): value is object;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if a value is a valid array.
|
|
73
|
+
*
|
|
74
|
+
* @param {any} value - The value to be checked.
|
|
75
|
+
* @param {number} minLength - The min number of elements (optional).
|
|
76
|
+
* @param {number} maxLength - The max number of elements (optional).
|
|
77
|
+
* @returns {value is unknown[]} A boolean indicating whether the value is a valid array.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isValidArray(value: any, minLength?: number, maxLength?: number): value is unknown[];
|
|
80
|
+
/**
|
|
81
|
+
* Checks if the given value is null.
|
|
82
|
+
*
|
|
83
|
+
* @param {any} value - The value to check.
|
|
84
|
+
* @returns {value is null} `true` if the value is null, `false` otherwise.
|
|
85
|
+
*/
|
|
86
|
+
export declare function isValidNull(value: any): value is null;
|
|
87
|
+
/**
|
|
88
|
+
* Checks if a value is undefined.
|
|
89
|
+
*
|
|
90
|
+
* @param {any} value - The value to check.
|
|
91
|
+
* @returns {value is undefined} `true` if the value is undefined, `false` otherwise.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isValidUndefined(value: any): value is undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Converts a semantic version string like "6.11.0-1011-raspi" to a numeric version code like 61100.
|
|
96
|
+
* Format: major * 10000 + minor * 100 + patch
|
|
97
|
+
*
|
|
98
|
+
* @param {string} versionString The version string to parse
|
|
99
|
+
* @returns {number | undefined} A numeric version code or undefined if parsing fails
|
|
100
|
+
*/
|
|
101
|
+
export declare function parseVersionString(versionString: string): number | undefined;
|
|
102
|
+
//# sourceMappingURL=isvalid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isvalid.d.ts","sourceRoot":"","sources":["../../src/utils/isvalid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAG/D;AAED;;;;;;;GAOG;AAEH,wBAAgB,aAAa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
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License. *
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a given string is a valid IPv4 address.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} ipv4Address - The string to be checked.
|
|
27
|
+
* @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
|
|
28
|
+
*/
|
|
1
29
|
export function isValidIpv4Address(ipv4Address) {
|
|
2
30
|
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
3
31
|
return ipv4Regex.test(ipv4Address);
|
|
4
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a value is a valid number within the specified range.
|
|
35
|
+
*
|
|
36
|
+
* @param {any} value - The value to be checked.
|
|
37
|
+
* @param {number} min - The minimum value allowed (optional).
|
|
38
|
+
* @param {number} max - The maximum value allowed (optional).
|
|
39
|
+
* @returns {value is number} Returns true if the value is a valid number within the specified range, otherwise false.
|
|
40
|
+
*/
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
42
|
export function isValidNumber(value, min, max) {
|
|
6
43
|
if (value === undefined || value === null || typeof value !== 'number' || Number.isNaN(value) || !Number.isFinite(value))
|
|
7
44
|
return false;
|
|
@@ -11,9 +48,25 @@ export function isValidNumber(value, min, max) {
|
|
|
11
48
|
return false;
|
|
12
49
|
return true;
|
|
13
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a value is a valid boolean.
|
|
53
|
+
*
|
|
54
|
+
* @param {any} value - The value to be checked.
|
|
55
|
+
* @returns {value is boolean} `true` if the value is a valid boolean, `false` otherwise.
|
|
56
|
+
*/
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
58
|
export function isValidBoolean(value) {
|
|
15
59
|
return value !== undefined && value !== null && typeof value === 'boolean';
|
|
16
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a value is a valid string.
|
|
63
|
+
*
|
|
64
|
+
* @param {any} value - The value to be checked.
|
|
65
|
+
* @param {number} minLength - The min string length (optional).
|
|
66
|
+
* @param {number} maxLength - The max string length (optional).
|
|
67
|
+
* @returns {value is string} A boolean indicating whether the value is a valid string.
|
|
68
|
+
*/
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
70
|
export function isValidString(value, minLength, maxLength) {
|
|
18
71
|
if (value === undefined || value === null || typeof value !== 'string')
|
|
19
72
|
return false;
|
|
@@ -23,9 +76,25 @@ export function isValidString(value, minLength, maxLength) {
|
|
|
23
76
|
return false;
|
|
24
77
|
return true;
|
|
25
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a value is a valid RegExp.
|
|
81
|
+
*
|
|
82
|
+
* @param {any} value - The value to be checked.
|
|
83
|
+
* @returns {value is RegExp} A boolean indicating whether the value is a valid RegExp.
|
|
84
|
+
*/
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
86
|
export function isValidRegExp(value) {
|
|
27
87
|
return value !== undefined && value !== null && value instanceof RegExp;
|
|
28
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Checks if a value is a valid object.
|
|
91
|
+
*
|
|
92
|
+
* @param {any} value - The value to be checked.
|
|
93
|
+
* @param {number} minLength - The min number of keys (optional).
|
|
94
|
+
* @param {number} maxLength - The max number of keys (optional).
|
|
95
|
+
* @returns {value is object} A boolean indicating whether the value is a valid object.
|
|
96
|
+
*/
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
98
|
export function isValidObject(value, minLength, maxLength) {
|
|
30
99
|
if (value === undefined || value === null || typeof value !== 'object' || Array.isArray(value))
|
|
31
100
|
return false;
|
|
@@ -36,6 +105,15 @@ export function isValidObject(value, minLength, maxLength) {
|
|
|
36
105
|
return false;
|
|
37
106
|
return true;
|
|
38
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Checks if a value is a valid array.
|
|
110
|
+
*
|
|
111
|
+
* @param {any} value - The value to be checked.
|
|
112
|
+
* @param {number} minLength - The min number of elements (optional).
|
|
113
|
+
* @param {number} maxLength - The max number of elements (optional).
|
|
114
|
+
* @returns {value is unknown[]} A boolean indicating whether the value is a valid array.
|
|
115
|
+
*/
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
117
|
export function isValidArray(value, minLength, maxLength) {
|
|
40
118
|
if (value === undefined || value === null || !Array.isArray(value))
|
|
41
119
|
return false;
|
|
@@ -45,12 +123,33 @@ export function isValidArray(value, minLength, maxLength) {
|
|
|
45
123
|
return false;
|
|
46
124
|
return true;
|
|
47
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if the given value is null.
|
|
128
|
+
*
|
|
129
|
+
* @param {any} value - The value to check.
|
|
130
|
+
* @returns {value is null} `true` if the value is null, `false` otherwise.
|
|
131
|
+
*/
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
133
|
export function isValidNull(value) {
|
|
49
134
|
return value === null;
|
|
50
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Checks if a value is undefined.
|
|
138
|
+
*
|
|
139
|
+
* @param {any} value - The value to check.
|
|
140
|
+
* @returns {value is undefined} `true` if the value is undefined, `false` otherwise.
|
|
141
|
+
*/
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
143
|
export function isValidUndefined(value) {
|
|
52
144
|
return value === undefined;
|
|
53
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Converts a semantic version string like "6.11.0-1011-raspi" to a numeric version code like 61100.
|
|
148
|
+
* Format: major * 10000 + minor * 100 + patch
|
|
149
|
+
*
|
|
150
|
+
* @param {string} versionString The version string to parse
|
|
151
|
+
* @returns {number | undefined} A numeric version code or undefined if parsing fails
|
|
152
|
+
*/
|
|
54
153
|
export function parseVersionString(versionString) {
|
|
55
154
|
if (!isValidString(versionString))
|
|
56
155
|
return undefined;
|
|
@@ -67,3 +166,4 @@ export function parseVersionString(versionString) {
|
|
|
67
166
|
}
|
|
68
167
|
return major * 10000 + minor * 100 + patch;
|
|
69
168
|
}
|
|
169
|
+
//# sourceMappingURL=isvalid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isvalid.js","sourceRoot":"","sources":["../../src/utils/isvalid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,MAAM,SAAS,GAAG,kKAAkK,CAAC;IACrL,OAAO,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAAC,KAAU,EAAE,GAAY,EAAE,GAAY;IAClE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC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E,OAAO,SAAS,CAAC;IAE7B,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC/C,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAErC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QACrG,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the network functions.
|
|
3
|
+
*
|
|
4
|
+
* @file network.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2024-02-17
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License. *
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
25
|
+
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getIpv4InterfaceAddress(): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
30
|
+
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getIpv6InterfaceAddress(): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves the mac address of the first non-internal network interface.
|
|
35
|
+
* @returns {string | undefined} The mac address, or undefined if not found.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getMacAddress(): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Logs the available network interfaces and their details.
|
|
40
|
+
* @param {boolean} log - Whether to enable logging of network interface details (default is true).
|
|
41
|
+
*/
|
|
42
|
+
export declare function logInterfaces(debug?: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves the given hostname to an IP address.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} hostname - The hostname to resolve.
|
|
47
|
+
* @param {0 | 4 | 6} [family=4] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
48
|
+
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveHostname(hostname: string, family?: 0 | 4 | 6): Promise<string | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the version of an npm package from the npm registry.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} packageName - The name of the npm package.
|
|
58
|
+
* @param {string} [tag='latest'] - The tag of the package version to retrieve (default is 'latest').
|
|
59
|
+
* @param {number} [timeout=10000] - The timeout duration in milliseconds (default is 10000ms).
|
|
60
|
+
* @returns {Promise<string>} A promise that resolves to the version string of the package.
|
|
61
|
+
* @throws {Error} If the request fails or the tag is not found.
|
|
62
|
+
*/
|
|
63
|
+
export declare function getNpmPackageVersion(packageName: string, tag?: string, timeout?: number): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves the path to the global Node.js modules directory.
|
|
66
|
+
* @returns A promise that resolves to the path of the global Node.js modules directory.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getGlobalNodeModules(): Promise<string>;
|
|
69
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAWH;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAmB5D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAmB5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAkBlD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,UAAO,GAAG,IAAI,CAehD;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,CAAC,GAAG,CAAC,GAAG,CAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASrG;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,SAAW,EAAE,OAAO,SAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CA+ChH;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAW5D"}
|
package/dist/utils/network.js
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the network functions.
|
|
3
|
+
*
|
|
4
|
+
* @file network.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2024-02-17
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License. *
|
|
22
|
+
*/
|
|
23
|
+
// Node.js modules
|
|
1
24
|
import os from 'node:os';
|
|
25
|
+
// AnsiLogger module
|
|
2
26
|
import { AnsiLogger, idn, rs } from '../logger/export.js';
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
29
|
+
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
30
|
+
*/
|
|
3
31
|
export function getIpv4InterfaceAddress() {
|
|
4
32
|
let ipv4Address;
|
|
5
33
|
const networkInterfaces = os.networkInterfaces();
|
|
34
|
+
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
6
35
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
7
36
|
if (!interfaceDetails) {
|
|
8
37
|
break;
|
|
@@ -16,11 +45,17 @@ export function getIpv4InterfaceAddress() {
|
|
|
16
45
|
break;
|
|
17
46
|
}
|
|
18
47
|
}
|
|
48
|
+
// console.log('Selected Network Interfaces:', ipv4Address);
|
|
19
49
|
return ipv4Address;
|
|
20
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
53
|
+
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
54
|
+
*/
|
|
21
55
|
export function getIpv6InterfaceAddress() {
|
|
22
56
|
let ipv6Address;
|
|
23
57
|
const networkInterfaces = os.networkInterfaces();
|
|
58
|
+
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
24
59
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
25
60
|
if (!interfaceDetails) {
|
|
26
61
|
break;
|
|
@@ -34,11 +69,17 @@ export function getIpv6InterfaceAddress() {
|
|
|
34
69
|
break;
|
|
35
70
|
}
|
|
36
71
|
}
|
|
72
|
+
// console.log('Selected Network Interfaces:', ipv6Address);
|
|
37
73
|
return ipv6Address;
|
|
38
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves the mac address of the first non-internal network interface.
|
|
77
|
+
* @returns {string | undefined} The mac address, or undefined if not found.
|
|
78
|
+
*/
|
|
39
79
|
export function getMacAddress() {
|
|
40
80
|
let macAddress;
|
|
41
81
|
const networkInterfaces = os.networkInterfaces();
|
|
82
|
+
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
42
83
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
43
84
|
if (!interfaceDetails) {
|
|
44
85
|
break;
|
|
@@ -54,9 +95,13 @@ export function getMacAddress() {
|
|
|
54
95
|
}
|
|
55
96
|
return macAddress;
|
|
56
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Logs the available network interfaces and their details.
|
|
100
|
+
* @param {boolean} log - Whether to enable logging of network interface details (default is true).
|
|
101
|
+
*/
|
|
57
102
|
export function logInterfaces(debug = true) {
|
|
58
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4
|
|
59
|
-
log.logLevel = "info"
|
|
103
|
+
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
|
|
104
|
+
log.logLevel = "info" /* LogLevel.INFO */;
|
|
60
105
|
log.logName = 'LogInterfaces';
|
|
61
106
|
const networkInterfaces = os.networkInterfaces();
|
|
62
107
|
if (debug)
|
|
@@ -72,16 +117,36 @@ export function logInterfaces(debug = true) {
|
|
|
72
117
|
}
|
|
73
118
|
}
|
|
74
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Resolves the given hostname to an IP address.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} hostname - The hostname to resolve.
|
|
124
|
+
* @param {0 | 4 | 6} [family=4] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
125
|
+
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
129
|
+
*/
|
|
75
130
|
export async function resolveHostname(hostname, family = 4) {
|
|
76
131
|
const dns = await import('node:dns');
|
|
77
132
|
try {
|
|
78
|
-
const addresses = await dns.promises.lookup(hostname.toLowerCase()
|
|
133
|
+
const addresses = await dns.promises.lookup(hostname.toLowerCase() /* + '.local'*/, { family });
|
|
79
134
|
return addresses.address;
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
136
|
}
|
|
81
137
|
catch (error) {
|
|
82
138
|
return null;
|
|
83
139
|
}
|
|
84
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves the version of an npm package from the npm registry.
|
|
143
|
+
*
|
|
144
|
+
* @param {string} packageName - The name of the npm package.
|
|
145
|
+
* @param {string} [tag='latest'] - The tag of the package version to retrieve (default is 'latest').
|
|
146
|
+
* @param {number} [timeout=10000] - The timeout duration in milliseconds (default is 10000ms).
|
|
147
|
+
* @returns {Promise<string>} A promise that resolves to the version string of the package.
|
|
148
|
+
* @throws {Error} If the request fails or the tag is not found.
|
|
149
|
+
*/
|
|
85
150
|
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
|
|
86
151
|
const https = await import('node:https');
|
|
87
152
|
return new Promise((resolve, reject) => {
|
|
@@ -95,8 +160,8 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
95
160
|
let data = '';
|
|
96
161
|
if (res.statusCode !== 200) {
|
|
97
162
|
clearTimeout(timeoutId);
|
|
98
|
-
res.resume();
|
|
99
|
-
req.destroy();
|
|
163
|
+
res.resume(); // Discard response data to close the socket properly
|
|
164
|
+
req.destroy(); // Forcefully close the request
|
|
100
165
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
101
166
|
return;
|
|
102
167
|
}
|
|
@@ -107,6 +172,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
107
172
|
clearTimeout(timeoutId);
|
|
108
173
|
try {
|
|
109
174
|
const jsonData = JSON.parse(data);
|
|
175
|
+
// console.log(`Package ${packageName} tag ${tag}`, jsonData);
|
|
110
176
|
const version = jsonData['dist-tags']?.[tag];
|
|
111
177
|
if (version) {
|
|
112
178
|
resolve(version);
|
|
@@ -126,6 +192,10 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
126
192
|
});
|
|
127
193
|
});
|
|
128
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Retrieves the path to the global Node.js modules directory.
|
|
197
|
+
* @returns A promise that resolves to the path of the global Node.js modules directory.
|
|
198
|
+
*/
|
|
129
199
|
export async function getGlobalNodeModules() {
|
|
130
200
|
const { exec } = await import('node:child_process');
|
|
131
201
|
return new Promise((resolve, reject) => {
|
|
@@ -139,3 +209,4 @@ export async function getGlobalNodeModules() {
|
|
|
139
209
|
});
|
|
140
210
|
});
|
|
141
211
|
}
|
|
212
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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,WAAW,GAAG,CAAC,CAAC,CAAC;oBAC3E,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACxG,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACxB,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACpD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,CAAC,aAAa,EAAE,CAAC,KAA2B,EAAE,MAAc,EAAE,EAAE;YAClE,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Matterbridge } from '../matterbridge.js';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
/**
|
|
4
|
+
* Spawns a child process with the given command and arguments.
|
|
5
|
+
* @param {string} command - The command to execute.
|
|
6
|
+
* @param {string[]} args - The arguments to pass to the command (default: []).
|
|
7
|
+
* @returns {Promise<boolean>} A promise that resolves when the child process exits successfully, or rejects if there is an error.
|
|
8
|
+
*/
|
|
9
|
+
spawnCommand(matterbridge: Matterbridge, command: string, args: string[]): Promise<boolean>;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
12
|
+
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/utils/spawn.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;;IAGhD;;;;;OAKG;+BAC8B,YAAY,WAAW,MAAM,QAAQ,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;;AAPnG,wBAqFE"}
|
package/dist/utils/spawn.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { hasParameter } from './commandLine.js';
|
|
2
2
|
export default {
|
|
3
|
+
/**
|
|
4
|
+
* Spawns a child process with the given command and arguments.
|
|
5
|
+
* @param {string} command - The command to execute.
|
|
6
|
+
* @param {string[]} args - The arguments to pass to the command (default: []).
|
|
7
|
+
* @returns {Promise<boolean>} A promise that resolves when the child process exits successfully, or rejects if there is an error.
|
|
8
|
+
*/
|
|
3
9
|
async spawnCommand(matterbridge, command, args) {
|
|
4
10
|
const { spawn } = await import('node:child_process');
|
|
11
|
+
/*
|
|
12
|
+
npm > npm.cmd on windows
|
|
13
|
+
cmd.exe ['dir'] on windows
|
|
14
|
+
await this.spawnCommand('npm', ['install', '-g', 'matterbridge']);
|
|
15
|
+
*/
|
|
5
16
|
const cmdLine = command + ' ' + args.join(' ');
|
|
6
17
|
if (process.platform === 'win32' && command === 'npm') {
|
|
18
|
+
// Must be spawn('cmd.exe', ['/c', 'npm -g install <package>']);
|
|
7
19
|
const argstring = 'npm ' + args.join(' ');
|
|
8
20
|
args.splice(0, args.length, '/c', argstring);
|
|
9
21
|
command = 'cmd.exe';
|
|
10
22
|
}
|
|
23
|
+
// Decide when using sudo on linux and macOS
|
|
24
|
+
// When you need sudo: Spawn stderr: npm error Error: EACCES: permission denied
|
|
25
|
+
// When you don't need sudo: Failed to start child process "npm install -g matterbridge-eve-door": spawn sudo ENOENT
|
|
11
26
|
if (hasParameter('sudo') || (process.platform !== 'win32' && command === 'npm' && !hasParameter('docker') && !hasParameter('nosudo'))) {
|
|
12
27
|
args.unshift(command);
|
|
13
28
|
command = 'sudo';
|
|
@@ -66,3 +81,4 @@ export default {
|
|
|
66
81
|
});
|
|
67
82
|
},
|
|
68
83
|
};
|
|
84
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../src/utils/spawn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,eAAe;IACb;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,YAA0B,EAAE,OAAe,EAAE,IAAc;QAC5E,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;QAErD;;;;UAIE;QACF,MAAM,OAAO,GAAG,OAAO,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YACtD,gEAAgE;YAChE,MAAM,SAAS,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;YAC7C,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC;QACD,4CAA4C;QAC5C,+EAA+E;QAC/E,oHAAoH;QACpH,I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
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2025-02-16
|
|
7
|
+
* @version 1.0.1
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License. *
|
|
22
|
+
*/
|
|
23
|
+
import { AnsiLogger } from '../logger/export.js';
|
|
24
|
+
export declare const log: AnsiLogger;
|
|
25
|
+
/**
|
|
26
|
+
* Asynchronous waiter function that resolves when the provided condition is met or rejects on timeout.
|
|
27
|
+
* @param {string} name - The name of the waiter.
|
|
28
|
+
* @param {() => boolean} check - A function that checks the condition. Should return a boolean.
|
|
29
|
+
* @param {boolean} [exitWithReject=false] - Optional. If true, the promise will be rejected on timeout. Default is false.
|
|
30
|
+
* @param {number} [resolveTimeout=5000] - Optional. The timeout duration in milliseconds. Default is 5000ms.
|
|
31
|
+
* @param {number} [resolveInterval=500] - Optional. The interval duration in milliseconds between condition checks. Default is 500ms.
|
|
32
|
+
* @param {boolean} [debug=false] - Optional. If true, debug messages will be logged to the console. Default is false.
|
|
33
|
+
* @returns {Promise<boolean>} A promise that resolves to true when the condition is met, or false if the timeout occurs.
|
|
34
|
+
*/
|
|
35
|
+
export declare function waiter(name: string, check: () => boolean, exitWithReject?: boolean, resolveTimeout?: number, resolveInterval?: number, debug?: boolean): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Asynchronously waits for a specified amount of time.
|
|
38
|
+
* @param {number} timeout - The duration to wait in milliseconds. Default is 1000ms.
|
|
39
|
+
* @param {string} name - The name of the wait operation. Default is undefined.
|
|
40
|
+
* @param {boolean} debug - Whether to enable debug logging. Default is false.
|
|
41
|
+
* @returns {Promise<void>} A Promise that resolves after the specified timeout.
|
|
42
|
+
*/
|
|
43
|
+
export declare function wait(timeout?: number, name?: string, debug?: boolean): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Wraps a promise with a timeout. If the promise does not resolve or reject within the specified time, it will be rejected.
|
|
46
|
+
* @param {Promise<T>} promise - The promise to wrap.
|
|
47
|
+
* @param {number} [timeoutMillisecs=10000] - The timeout duration in milliseconds. Default is 10000ms.
|
|
48
|
+
* @param {boolean} [reThrow=true] - Optional. If true, the promise will rethrow the original promise and will reject on timeout. Default is true.
|
|
49
|
+
* @returns {Promise<T>} A new promise that resolves or rejects based on the original promise and the timeout.
|
|
50
|
+
*/
|
|
51
|
+
export declare function withTimeout<T>(promise: Promise<T>, timeoutMillisecs?: number, reThrow?: boolean): Promise<T>;
|
|
52
|
+
//# sourceMappingURL=wait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../../src/utils/wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,UAAU,EAA6B,MAAM,qBAAqB,CAAC;AAE5E,eAAO,MAAM,GAAG,YAA6H,CAAC;AAE9I;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,OAAO,EAAE,cAAc,UAAQ,EAAE,cAAc,SAAO,EAAE,eAAe,SAAM,EAAE,KAAK,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBtK;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,OAAO,SAAO,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAYtF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,gBAAgB,SAAQ,EAAE,OAAO,UAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAuBxG"}
|