@iobroker/js-controller-cli 7.0.2 → 7.0.3
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/build/cjs/index.js +2 -1
- package/build/cjs/index.js.map +2 -2
- package/build/cjs/lib/_Types.d.ts +0 -1
- package/build/cjs/lib/cli/cliCert.js +17 -0
- package/build/cjs/lib/cli/cliCert.js.map +1 -1
- package/build/cjs/lib/cli/cliCommand.d.ts +0 -1
- package/build/cjs/lib/cli/cliCommand.js +6 -0
- package/build/cjs/lib/cli/cliCommand.js.map +1 -1
- package/build/cjs/lib/cli/cliCompact.js +30 -1
- package/build/cjs/lib/cli/cliCompact.js.map +1 -1
- package/build/cjs/lib/cli/cliDebug.js +16 -0
- package/build/cjs/lib/cli/cliDebug.js.map +1 -1
- package/build/cjs/lib/cli/cliHost.js +35 -0
- package/build/cjs/lib/cli/cliHost.js.map +1 -1
- package/build/cjs/lib/cli/cliLogs.js +33 -3
- package/build/cjs/lib/cli/cliLogs.js.map +3 -3
- package/build/cjs/lib/cli/cliMessage.js +10 -0
- package/build/cjs/lib/cli/cliMessage.js.map +1 -1
- package/build/cjs/lib/cli/cliObjects.d.ts +0 -1
- package/build/cjs/lib/cli/cliObjects.js +85 -0
- package/build/cjs/lib/cli/cliObjects.js.map +1 -1
- package/build/cjs/lib/cli/cliPlugin.js +23 -2
- package/build/cjs/lib/cli/cliPlugin.js.map +3 -3
- package/build/cjs/lib/cli/cliProcess.js +65 -2
- package/build/cjs/lib/cli/cliProcess.js.map +1 -1
- package/build/cjs/lib/cli/cliStates.d.ts +0 -1
- package/build/cjs/lib/cli/cliStates.js +38 -0
- package/build/cjs/lib/cli/cliStates.js.map +1 -1
- package/build/cjs/lib/cli/cliTools.js.map +1 -1
- package/build/cjs/lib/cli/messages.d.ts +27 -23
- package/build/cjs/lib/cli/messages.js.map +1 -1
- package/build/cjs/lib/setup/dbConnection.js +9 -0
- package/build/cjs/lib/setup/dbConnection.js.map +1 -1
- package/build/cjs/lib/setup/formatters.js.map +1 -1
- package/build/cjs/lib/setup/multihostClient.d.ts +0 -1
- package/build/cjs/lib/setup/multihostClient.js +36 -0
- package/build/cjs/lib/setup/multihostClient.js.map +1 -1
- package/build/cjs/lib/setup/setupBackup.js +112 -2
- package/build/cjs/lib/setup/setupBackup.js.map +1 -1
- package/build/cjs/lib/setup/setupInstall.d.ts +6 -6
- package/build/cjs/lib/setup/setupInstall.js +198 -57
- package/build/cjs/lib/setup/setupInstall.js.map +4 -4
- package/build/cjs/lib/setup/setupLicense.js +9 -0
- package/build/cjs/lib/setup/setupLicense.js.map +1 -1
- package/build/cjs/lib/setup/setupList.d.ts +0 -1
- package/build/cjs/lib/setup/setupList.js +4 -0
- package/build/cjs/lib/setup/setupList.js.map +1 -1
- package/build/cjs/lib/setup/setupMultihost.d.ts +2 -5
- package/build/cjs/lib/setup/setupMultihost.js +58 -33
- package/build/cjs/lib/setup/setupMultihost.js.map +3 -3
- package/build/cjs/lib/setup/setupPacketManager.js +41 -0
- package/build/cjs/lib/setup/setupPacketManager.js.map +1 -1
- package/build/cjs/lib/setup/setupRepo.js +60 -0
- package/build/cjs/lib/setup/setupRepo.js.map +1 -1
- package/build/cjs/lib/setup/setupSetup.d.ts +0 -1
- package/build/cjs/lib/setup/setupSetup.js +79 -5
- package/build/cjs/lib/setup/setupSetup.js.map +3 -3
- package/build/cjs/lib/setup/setupUpgrade.js +34 -0
- package/build/cjs/lib/setup/setupUpgrade.js.map +1 -1
- package/build/cjs/lib/setup/setupUpload.d.ts +0 -3
- package/build/cjs/lib/setup/setupUpload.js +43 -0
- package/build/cjs/lib/setup/setupUpload.js.map +1 -1
- package/build/cjs/lib/setup/setupUsers.d.ts +0 -1
- package/build/cjs/lib/setup/setupUsers.js +109 -0
- package/build/cjs/lib/setup/setupUsers.js.map +1 -1
- package/build/cjs/lib/setup/setupVendor.js +18 -1
- package/build/cjs/lib/setup/setupVendor.js.map +1 -1
- package/build/cjs/lib/setup/setupVisDebug.js +16 -0
- package/build/cjs/lib/setup/setupVisDebug.js.map +1 -1
- package/build/cjs/lib/setup/utils.d.ts +1 -1
- package/build/cjs/lib/setup/utils.js +8 -4
- package/build/cjs/lib/setup/utils.js.map +2 -2
- package/build/cjs/lib/setup.js +17 -6
- package/build/cjs/lib/setup.js.map +3 -3
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/lib/_Types.d.ts +0 -1
- package/build/esm/lib/_Types.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCommand.d.ts +0 -1
- package/build/esm/lib/cli/cliCommand.d.ts.map +1 -1
- package/build/esm/lib/cli/cliObjects.d.ts +0 -1
- package/build/esm/lib/cli/cliObjects.d.ts.map +1 -1
- package/build/esm/lib/cli/cliStates.d.ts +0 -1
- package/build/esm/lib/cli/cliStates.d.ts.map +1 -1
- package/build/esm/lib/cli/messages.d.ts +27 -23
- package/build/esm/lib/cli/messages.d.ts.map +1 -1
- package/build/esm/lib/setup/multihostClient.d.ts +0 -1
- package/build/esm/lib/setup/multihostClient.d.ts.map +1 -1
- package/build/esm/lib/setup/setupInstall.d.ts +6 -6
- package/build/esm/lib/setup/setupInstall.d.ts.map +1 -1
- package/build/esm/lib/setup/setupInstall.js +37 -70
- package/build/esm/lib/setup/setupInstall.js.map +1 -1
- package/build/esm/lib/setup/setupList.d.ts +0 -1
- package/build/esm/lib/setup/setupList.d.ts.map +1 -1
- package/build/esm/lib/setup/setupMultihost.d.ts +2 -5
- package/build/esm/lib/setup/setupMultihost.d.ts.map +1 -1
- package/build/esm/lib/setup/setupMultihost.js +12 -37
- package/build/esm/lib/setup/setupMultihost.js.map +1 -1
- package/build/esm/lib/setup/setupSetup.d.ts +0 -1
- package/build/esm/lib/setup/setupSetup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpload.d.ts +0 -3
- package/build/esm/lib/setup/setupUpload.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUsers.d.ts +0 -1
- package/build/esm/lib/setup/setupUsers.d.ts.map +1 -1
- package/build/esm/lib/setup/utils.d.ts +1 -1
- package/build/esm/lib/setup/utils.d.ts.map +1 -1
- package/build/esm/lib/setup/utils.js +3 -3
- package/build/esm/lib/setup/utils.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -27,6 +31,7 @@ __export(setupInstall_exports, {
|
|
|
27
31
|
Install: () => Install
|
|
28
32
|
});
|
|
29
33
|
module.exports = __toCommonJS(setupInstall_exports);
|
|
34
|
+
var __import_meta_url = typeof document === "undefined" ? new (require("url".replace("", ""))).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
30
35
|
var import_js_controller_common = require("@iobroker/js-controller-common");
|
|
31
36
|
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
32
37
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
@@ -40,8 +45,7 @@ var import_utils = require("../../lib/setup/utils.js");
|
|
|
40
45
|
var import_customError = require("../../lib/setup/customError.js");
|
|
41
46
|
var import_constants = require("@iobroker/js-controller-common-db/constants");
|
|
42
47
|
var import_node_module = require("node:module");
|
|
43
|
-
const
|
|
44
|
-
const require2 = (0, import_node_module.createRequire)(import_meta.url || `file://${__filename}`);
|
|
48
|
+
const require2 = (0, import_node_module.createRequire)(__import_meta_url || `file://${__filename}`);
|
|
45
49
|
const hostname = import_js_controller_common.tools.getHostName();
|
|
46
50
|
const osPlatform = process.platform;
|
|
47
51
|
const RECOMMENDED_NPM_VERSION = 8;
|
|
@@ -73,6 +77,12 @@ class Install {
|
|
|
73
77
|
this.tarballRegex = /\/tarball\/[^/]+$/;
|
|
74
78
|
this.upload = new import_setupUpload.Upload(options);
|
|
75
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Enables or disables given instances
|
|
82
|
+
*
|
|
83
|
+
* @param instances all instance objects
|
|
84
|
+
* @param enabled if enable or disable
|
|
85
|
+
*/
|
|
76
86
|
async enableInstances(instances, enabled) {
|
|
77
87
|
if (instances?.length) {
|
|
78
88
|
const ts = Date.now();
|
|
@@ -89,17 +99,24 @@ class Install {
|
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Download given packet
|
|
104
|
+
*
|
|
105
|
+
* @param repoUrlOrRepo repository url or already the repository object
|
|
106
|
+
* @param packetName name of the package to install
|
|
107
|
+
* @param options options.stopDb will stop the db before upgrade ONLY use it for controller upgrade - db is gone afterwards, does not work with stoppedList
|
|
108
|
+
* @param stoppedList list of stopped instances (as instance objects)
|
|
109
|
+
*/
|
|
110
|
+
async downloadPacket(repoUrlOrRepo, packetName, options, stoppedList) {
|
|
94
111
|
if (!options || typeof options !== "object") {
|
|
95
112
|
options = {};
|
|
96
113
|
}
|
|
97
114
|
stoppedList = stoppedList || [];
|
|
98
115
|
let sources;
|
|
99
|
-
if (!
|
|
100
|
-
sources = await (0, import_utils.getRepository)({ repoName:
|
|
116
|
+
if (!repoUrlOrRepo || !import_js_controller_common.tools.isObject(repoUrlOrRepo)) {
|
|
117
|
+
sources = await (0, import_utils.getRepository)({ repoName: repoUrlOrRepo, objects: this.objects });
|
|
101
118
|
} else {
|
|
102
|
-
sources =
|
|
119
|
+
sources = repoUrlOrRepo;
|
|
103
120
|
}
|
|
104
121
|
if (options.stopDb && stoppedList.length) {
|
|
105
122
|
console.warn("[downloadPacket] stoppedList cannot be used if stopping of databases is requested");
|
|
@@ -118,61 +135,42 @@ class Install {
|
|
|
118
135
|
version = "";
|
|
119
136
|
}
|
|
120
137
|
}
|
|
138
|
+
const source = sources[packetName];
|
|
139
|
+
if (!source) {
|
|
140
|
+
const errMessage = `Unknown packet name ${packetName}. Please install packages from outside the repository using "${import_js_controller_common.tools.appNameLowerCase} url <url-or-package>"!`;
|
|
141
|
+
console.error(`host.${hostname} ${errMessage}`);
|
|
142
|
+
throw new import_customError.IoBrokerError({
|
|
143
|
+
code: import_js_controller_common.EXIT_CODES.UNKNOWN_PACKET_NAME,
|
|
144
|
+
message: errMessage
|
|
145
|
+
});
|
|
146
|
+
}
|
|
121
147
|
options.packetName = packetName;
|
|
122
|
-
options.unsafePerm =
|
|
123
|
-
if ((
|
|
148
|
+
options.unsafePerm = source.unsafePerm;
|
|
149
|
+
if ((source.stopBeforeUpdate || osPlatform === "win32") && !stoppedList.length) {
|
|
124
150
|
stoppedList = await this._getInstancesOfAdapter(packetName);
|
|
125
151
|
await this.enableInstances(stoppedList, false);
|
|
126
152
|
}
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
} catch {
|
|
153
|
+
if (options.stopDb) {
|
|
154
|
+
if (this.objects.destroy) {
|
|
155
|
+
await this.objects.destroy();
|
|
156
|
+
console.log("Stopped Objects DB");
|
|
132
157
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (url && packetName === "js-controller" && import_fs_extra.default.pathExistsSync(`${import_js_controller_common.tools.getControllerDir()}/../../node_modules/${import_js_controller_common.tools.appName.toLowerCase()}.js-controller`)) {
|
|
137
|
-
url = null;
|
|
138
|
-
}
|
|
139
|
-
if (!url && packetName !== "example") {
|
|
140
|
-
if (options.stopDb) {
|
|
141
|
-
if (this.objects.destroy) {
|
|
142
|
-
await this.objects.destroy();
|
|
143
|
-
console.log("Stopped Objects DB");
|
|
144
|
-
}
|
|
145
|
-
if (this.states.destroy) {
|
|
146
|
-
await this.states.destroy();
|
|
147
|
-
console.log("Stopped States DB");
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
await this._npmInstallWithCheck(`${import_js_controller_common.tools.appName.toLowerCase()}.${packetName}${version ? `@${version}` : ""}`, options, debug);
|
|
151
|
-
return { packetName, stoppedList };
|
|
152
|
-
} else if (url && url.match(this.tarballRegex)) {
|
|
153
|
-
if (options.stopDb) {
|
|
154
|
-
if (this.objects.destroy) {
|
|
155
|
-
await this.objects.destroy();
|
|
156
|
-
console.log("Stopped Objects DB");
|
|
157
|
-
}
|
|
158
|
-
if (this.states.destroy) {
|
|
159
|
-
await this.states.destroy();
|
|
160
|
-
console.log("Stopped States DB");
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
await this._npmInstallWithCheck(url, options, debug);
|
|
164
|
-
return { packetName, stoppedList };
|
|
165
|
-
} else if (!url) {
|
|
166
|
-
console.warn(`host.${hostname} Adapter "${packetName}" can be updated only together with ${import_js_controller_common.tools.appName.toLowerCase()}.js-controller`);
|
|
167
|
-
return { packetName, stoppedList };
|
|
158
|
+
if (this.states.destroy) {
|
|
159
|
+
await this.states.destroy();
|
|
160
|
+
console.log("Stopped States DB");
|
|
168
161
|
}
|
|
169
162
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
message: `Unknown packetName ${packetName}. Please install packages from outside the repository using npm!`
|
|
174
|
-
});
|
|
163
|
+
const npmPacketName = source.packetName ? `${import_js_controller_common.tools.appName.toLowerCase()}.${packetName}@npm:${source.packetName}` : `${import_js_controller_common.tools.appName.toLowerCase()}.${packetName}`;
|
|
164
|
+
await this._npmInstallWithCheck(`${npmPacketName}${version ? `@${version}` : ""}`, options, debug);
|
|
165
|
+
return { packetName, stoppedList };
|
|
175
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Install npm module from url
|
|
169
|
+
*
|
|
170
|
+
* @param npmUrl parameter passed to `npm install <npmUrl>`
|
|
171
|
+
* @param options additional packet download options
|
|
172
|
+
* @param debug if debug output should be printed
|
|
173
|
+
*/
|
|
176
174
|
async _npmInstallWithCheck(npmUrl, options, debug) {
|
|
177
175
|
try {
|
|
178
176
|
let npmVersion;
|
|
@@ -208,10 +206,15 @@ class Install {
|
|
|
208
206
|
}
|
|
209
207
|
try {
|
|
210
208
|
return await this._npmInstall({ npmUrl, options, debug, isRetry: false });
|
|
211
|
-
} catch (
|
|
212
|
-
console.error(`Could not install ${npmUrl}: ${
|
|
209
|
+
} catch (e) {
|
|
210
|
+
console.error(`Could not install ${npmUrl}: ${e.message}`);
|
|
213
211
|
}
|
|
214
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Extract the adapterName e.g. `hm-rpc` from url
|
|
215
|
+
*
|
|
216
|
+
* @param npmUrl url of the npm packet
|
|
217
|
+
*/
|
|
215
218
|
getAdapterNameFromUrl(npmUrl) {
|
|
216
219
|
npmUrl = npmUrl.replace(/\\/g, "/").replace(/\.git$/, "").toLowerCase();
|
|
217
220
|
if (npmUrl.includes("#")) {
|
|
@@ -225,10 +228,15 @@ class Install {
|
|
|
225
228
|
}
|
|
226
229
|
return npmUrl;
|
|
227
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Perform npm installation of given package
|
|
233
|
+
*
|
|
234
|
+
* @param installOptions options of package to install
|
|
235
|
+
*/
|
|
228
236
|
async _npmInstall(installOptions) {
|
|
229
237
|
const { npmUrl, debug, isRetry } = installOptions;
|
|
230
238
|
let { options } = installOptions;
|
|
231
|
-
if (
|
|
239
|
+
if (!import_js_controller_common.tools.isObject(options)) {
|
|
232
240
|
options = {};
|
|
233
241
|
}
|
|
234
242
|
if (this.isRootOnUnix) {
|
|
@@ -278,6 +286,11 @@ class Install {
|
|
|
278
286
|
console.error(`host.${hostname} Cannot install ${npmUrl}: ${result.exitCode}`);
|
|
279
287
|
return this.processExit(import_js_controller_common.EXIT_CODES.CANNOT_INSTALL_NPM_PACKET);
|
|
280
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Handle the NPM `ENOTEMPTY` error, by deleting different affected directories and retrying installation
|
|
291
|
+
*
|
|
292
|
+
* @param notEmptyErrorOptions options of package to install
|
|
293
|
+
*/
|
|
281
294
|
handleNpmNotEmptyError(notEmptyErrorOptions) {
|
|
282
295
|
const { debug, npmUrl, options, result } = notEmptyErrorOptions;
|
|
283
296
|
console.info("Try to solve ENOTEMPTY error automatically");
|
|
@@ -310,6 +323,7 @@ class Install {
|
|
|
310
323
|
throw new Error(`host.${hostname}: Cannot uninstall ${packageName}: ${result.exitCode}`);
|
|
311
324
|
}
|
|
312
325
|
}
|
|
326
|
+
// this command is executed always on THIS host
|
|
313
327
|
async _checkDependencies(deps, globalDeps, _options) {
|
|
314
328
|
if (!deps && !globalDeps) {
|
|
315
329
|
return;
|
|
@@ -427,6 +441,13 @@ class Install {
|
|
|
427
441
|
}
|
|
428
442
|
}
|
|
429
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* Installs given adapter
|
|
446
|
+
*
|
|
447
|
+
* @param adapter The adapter name
|
|
448
|
+
* @param repoUrl
|
|
449
|
+
* @param _installCount
|
|
450
|
+
*/
|
|
430
451
|
async installAdapter(adapter, repoUrl, _installCount) {
|
|
431
452
|
_installCount = _installCount || 0;
|
|
432
453
|
const fullName = adapter;
|
|
@@ -516,6 +537,12 @@ class Install {
|
|
|
516
537
|
});
|
|
517
538
|
}
|
|
518
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* Create adapter instance
|
|
542
|
+
*
|
|
543
|
+
* @param adapter The adapter name
|
|
544
|
+
* @param options Additional instance creation options
|
|
545
|
+
*/
|
|
519
546
|
async createInstance(adapter, options) {
|
|
520
547
|
let ignoreIfExists = false;
|
|
521
548
|
options = options || {};
|
|
@@ -710,6 +737,14 @@ class Install {
|
|
|
710
737
|
console.error(`host.${hostname} error: ${err2.message}`);
|
|
711
738
|
}
|
|
712
739
|
}
|
|
740
|
+
/**
|
|
741
|
+
* Enumerate all instances of an adapter
|
|
742
|
+
*
|
|
743
|
+
* @param knownObjIDs
|
|
744
|
+
* @param notDeleted
|
|
745
|
+
* @param adapter
|
|
746
|
+
* @param instance
|
|
747
|
+
*/
|
|
713
748
|
async _enumerateAdapterInstances(knownObjIDs, notDeleted, adapter, instance) {
|
|
714
749
|
if (!notDeleted) {
|
|
715
750
|
notDeleted = [];
|
|
@@ -737,6 +772,13 @@ class Install {
|
|
|
737
772
|
err !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && err.message !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && console.error(`host.${hostname} error: ${err.message}`);
|
|
738
773
|
}
|
|
739
774
|
}
|
|
775
|
+
/**
|
|
776
|
+
* Enumerate all meta objects of an adapter
|
|
777
|
+
*
|
|
778
|
+
* @param knownObjIDs
|
|
779
|
+
* @param adapter
|
|
780
|
+
* @param metaFilesToDelete
|
|
781
|
+
*/
|
|
740
782
|
async _enumerateAdapterMeta(knownObjIDs, adapter, metaFilesToDelete) {
|
|
741
783
|
try {
|
|
742
784
|
const doc = await this.objects.getObjectViewAsync("system", "meta", {
|
|
@@ -776,6 +818,13 @@ class Install {
|
|
|
776
818
|
console.error(`host.${hostname} Cannot enumerate adapters: ${err.message}`);
|
|
777
819
|
}
|
|
778
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Enumerates the devices of an adapter (or instance)
|
|
823
|
+
*
|
|
824
|
+
* @param knownObjIDs The already known object ids
|
|
825
|
+
* @param adapter The adapter to enumerate the devices for
|
|
826
|
+
* @param instance The instance to enumerate the devices for (optional)
|
|
827
|
+
*/
|
|
779
828
|
async _enumerateAdapterDevices(knownObjIDs, adapter, instance) {
|
|
780
829
|
const adapterRegex = new RegExp(`^${adapter}${instance !== void 0 ? `\\.${instance}` : ""}\\.`);
|
|
781
830
|
try {
|
|
@@ -794,6 +843,13 @@ class Install {
|
|
|
794
843
|
err !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && err.message !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && console.error(`host.${hostname} error: ${err.message}`);
|
|
795
844
|
}
|
|
796
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
* Enumerates the channels of an adapter (or instance)
|
|
848
|
+
*
|
|
849
|
+
* @param knownObjIDs The already known object ids
|
|
850
|
+
* @param adapter The adapter to enumerate the channels for
|
|
851
|
+
* @param instance The instance to enumerate the channels for (optional)
|
|
852
|
+
*/
|
|
797
853
|
async _enumerateAdapterChannels(knownObjIDs, adapter, instance) {
|
|
798
854
|
const adapterRegex = new RegExp(`^${adapter}${instance !== void 0 ? `\\.${instance}` : ""}\\.`);
|
|
799
855
|
try {
|
|
@@ -812,6 +868,13 @@ class Install {
|
|
|
812
868
|
err !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && err.message !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && console.error(`host.${hostname} error: ${err.message}`);
|
|
813
869
|
}
|
|
814
870
|
}
|
|
871
|
+
/**
|
|
872
|
+
* Enumerates the states of an adapter (or instance)
|
|
873
|
+
*
|
|
874
|
+
* @param knownObjIDs The already known object ids
|
|
875
|
+
* @param adapter The adapter to enumerate the states for
|
|
876
|
+
* @param instance The instance to enumerate the states for (optional)
|
|
877
|
+
*/
|
|
815
878
|
async _enumerateAdapterStateObjects(knownObjIDs, adapter, instance) {
|
|
816
879
|
const adapterRegex = new RegExp(`^${adapter}${instance !== void 0 ? `\\.${instance}` : ""}\\.`);
|
|
817
880
|
const sysAdapterRegex = new RegExp(`^system\\.adapter\\.${adapter}${instance !== void 0 ? `\\.${instance}` : ""}\\.`);
|
|
@@ -842,6 +905,13 @@ class Install {
|
|
|
842
905
|
err !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && err.message !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && console.error(`host.${hostname} error: ${err.message}`);
|
|
843
906
|
}
|
|
844
907
|
}
|
|
908
|
+
/**
|
|
909
|
+
* Enumerates the docs of an adapter (or instance)
|
|
910
|
+
*
|
|
911
|
+
* @param knownObjIDs The already known object ids
|
|
912
|
+
* @param adapter The adapter to enumerate the states for
|
|
913
|
+
* @param instance The instance to enumerate the states for (optional)
|
|
914
|
+
*/
|
|
845
915
|
async _enumerateAdapterDocs(knownObjIDs, adapter, instance) {
|
|
846
916
|
const adapterRegex = new RegExp(`^${adapter}${instance !== void 0 ? `\\.${instance}` : ""}\\.`);
|
|
847
917
|
const sysAdapterRegex = new RegExp(`^system\\.adapter\\.${adapter}${instance !== void 0 ? `\\.${instance}` : ""}\\.`);
|
|
@@ -861,6 +931,13 @@ class Install {
|
|
|
861
931
|
err !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && err.message !== import_js_controller_common.tools.ERRORS.ERROR_NOT_FOUND && console.error(`host.${hostname} error: ${err.message}`);
|
|
862
932
|
}
|
|
863
933
|
}
|
|
934
|
+
/**
|
|
935
|
+
* Enumerate all state IDs of an adapter (or instance)
|
|
936
|
+
*
|
|
937
|
+
* @param knownStateIDs
|
|
938
|
+
* @param adapter
|
|
939
|
+
* @param instance
|
|
940
|
+
*/
|
|
864
941
|
async _enumerateAdapterStates(knownStateIDs, adapter, instance) {
|
|
865
942
|
for (const pattern of [
|
|
866
943
|
`io.${adapter}.${instance !== void 0 ? `${instance}.` : ""}*`,
|
|
@@ -883,6 +960,12 @@ class Install {
|
|
|
883
960
|
}
|
|
884
961
|
}
|
|
885
962
|
}
|
|
963
|
+
/**
|
|
964
|
+
* delete WWW pages, objects and meta files
|
|
965
|
+
*
|
|
966
|
+
* @param adapter
|
|
967
|
+
* @param metaFilesToDelete
|
|
968
|
+
*/
|
|
886
969
|
async _deleteAdapterFiles(adapter, metaFilesToDelete) {
|
|
887
970
|
const filesToDelete = [
|
|
888
971
|
{ id: "vis", name: `widgets/${adapter}` },
|
|
@@ -957,6 +1040,11 @@ class Install {
|
|
|
957
1040
|
}
|
|
958
1041
|
}
|
|
959
1042
|
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Deletes given adapter from filesystem and removes all instances
|
|
1045
|
+
*
|
|
1046
|
+
* @param adapter adapter name
|
|
1047
|
+
*/
|
|
960
1048
|
async deleteAdapter(adapter) {
|
|
961
1049
|
const knownObjectIDs = [];
|
|
962
1050
|
const metaFilesToDelete = [];
|
|
@@ -1042,6 +1130,12 @@ class Install {
|
|
|
1042
1130
|
}
|
|
1043
1131
|
return resultCode;
|
|
1044
1132
|
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Deletes given instance of an adapter
|
|
1135
|
+
*
|
|
1136
|
+
* @param adapter adapter name like hm-rpc
|
|
1137
|
+
* @param instance e.g. 1, if undefined deletes all instances
|
|
1138
|
+
*/
|
|
1045
1139
|
async deleteInstance(adapter, instance) {
|
|
1046
1140
|
const knownObjectIDs = [];
|
|
1047
1141
|
const knownStateIDs = [];
|
|
@@ -1063,6 +1157,12 @@ class Install {
|
|
|
1063
1157
|
await this._removeCustomFromObjects([`${adapter}.${instance}`]);
|
|
1064
1158
|
}
|
|
1065
1159
|
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Remove all node modules that has been installed by this instance
|
|
1162
|
+
*
|
|
1163
|
+
* @param adapter adapter name like hm-rpc
|
|
1164
|
+
* @param instance e.g. 1, if undefined deletes all instances
|
|
1165
|
+
*/
|
|
1066
1166
|
async _removeInstancesInstalledNodeModules(adapter, instance) {
|
|
1067
1167
|
const packJson = import_fs_extra.default.readJSONSync(import_node_path.default.join(import_js_controller_common.tools.getRootDir(), "package.json"));
|
|
1068
1168
|
const regex = new RegExp(`^@${import_js_controller_common.tools.appNameLowerCase}-${adapter}.${instance !== void 0 ? instance : "\\d+"}\\/.*`, "g");
|
|
@@ -1073,6 +1173,11 @@ class Install {
|
|
|
1073
1173
|
}
|
|
1074
1174
|
}
|
|
1075
1175
|
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Removes the custom attribute of the provided adapter/instance
|
|
1178
|
+
*
|
|
1179
|
+
* @param ids - id of the adapter/instance to check for
|
|
1180
|
+
*/
|
|
1076
1181
|
async _removeCustomFromObjects(ids) {
|
|
1077
1182
|
const res = await this.objects.getObjectViewAsync("system", "custom", {
|
|
1078
1183
|
startkey: "",
|
|
@@ -1097,6 +1202,12 @@ class Install {
|
|
|
1097
1202
|
}
|
|
1098
1203
|
}
|
|
1099
1204
|
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Installs an adapter from given url
|
|
1207
|
+
*
|
|
1208
|
+
* @param url url to install adapter from
|
|
1209
|
+
* @param name package name
|
|
1210
|
+
*/
|
|
1100
1211
|
async installAdapterFromUrl(url, name) {
|
|
1101
1212
|
let parsedUrl;
|
|
1102
1213
|
try {
|
|
@@ -1114,6 +1225,7 @@ class Install {
|
|
|
1114
1225
|
const result = await (0, import_axios.default)(`http://api.github.com/repos/${user}/${repo}/commits`, {
|
|
1115
1226
|
headers: {
|
|
1116
1227
|
"User-Agent": "ioBroker Adapter install",
|
|
1228
|
+
// @ts-expect-error should be okay...
|
|
1117
1229
|
validateStatus: (status) => status === 200
|
|
1118
1230
|
}
|
|
1119
1231
|
});
|
|
@@ -1179,6 +1291,13 @@ class Install {
|
|
|
1179
1291
|
await this.upload.upgradeAdapterObjects(name);
|
|
1180
1292
|
await this.enableInstances(stoppedList, true);
|
|
1181
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Checks if other adapters depend on this adapter
|
|
1296
|
+
*
|
|
1297
|
+
* @param adapter adapter name
|
|
1298
|
+
* @param instance instance, like 1
|
|
1299
|
+
* @returns if dependent exists, returns adapter name
|
|
1300
|
+
*/
|
|
1182
1301
|
async _hasDependentInstances(adapter, instance) {
|
|
1183
1302
|
try {
|
|
1184
1303
|
const doc = await this.objects.getObjectViewAsync("system", "instance", {
|
|
@@ -1228,6 +1347,14 @@ class Install {
|
|
|
1228
1347
|
console.error(`Could not check dependent instances for "${adapter}": ${e.message}`);
|
|
1229
1348
|
}
|
|
1230
1349
|
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Checks if adapter can also be found on another host than this
|
|
1352
|
+
*
|
|
1353
|
+
* @param adapter adapter name
|
|
1354
|
+
* @param instancesRows all instances objects view rows
|
|
1355
|
+
* @param scopedHostname hostname which should be assumed as local
|
|
1356
|
+
* @returns true if an instance is present on another host
|
|
1357
|
+
*/
|
|
1231
1358
|
_checkDependencyFulfilledForeignHosts(adapter, instancesRows, scopedHostname) {
|
|
1232
1359
|
for (const row of instancesRows) {
|
|
1233
1360
|
if (row.value && row.value.common.name === adapter && row.value.common.host !== scopedHostname) {
|
|
@@ -1236,6 +1363,15 @@ class Install {
|
|
|
1236
1363
|
}
|
|
1237
1364
|
return false;
|
|
1238
1365
|
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Checks if another instance then the given is present on this host
|
|
1368
|
+
*
|
|
1369
|
+
* @param adapter adapter name
|
|
1370
|
+
* @param instance instance number like 1
|
|
1371
|
+
* @param instancesRows all instances objects view rows
|
|
1372
|
+
* @param scopedHostname hostname which should be assumed as local
|
|
1373
|
+
* @returns true if another instance is present on this host
|
|
1374
|
+
*/
|
|
1239
1375
|
_checkDependencyFulfilledThisHost(adapter, instance, instancesRows, scopedHostname) {
|
|
1240
1376
|
for (const row of instancesRows) {
|
|
1241
1377
|
if (row.value && row.value.common.name === adapter && row.value.common.host === scopedHostname && parseInt(row.value._id.split(".").pop()) !== instance) {
|
|
@@ -1244,6 +1380,11 @@ class Install {
|
|
|
1244
1380
|
}
|
|
1245
1381
|
return false;
|
|
1246
1382
|
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Get all instances of an adapter which are on the current host
|
|
1385
|
+
*
|
|
1386
|
+
* @param adapter adapter name
|
|
1387
|
+
*/
|
|
1247
1388
|
async _getInstancesOfAdapter(adapter) {
|
|
1248
1389
|
const instances = [];
|
|
1249
1390
|
const doc = await this.objects.getObjectListAsync({
|