@iobroker/js-controller-cli 7.0.3 → 7.0.4-alpha.1-20241120-1e3f92f91
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/lib/setup/setupRepo.d.ts +28 -6
- package/build/cjs/lib/setup/setupRepo.js +117 -60
- package/build/cjs/lib/setup/setupRepo.js.map +2 -2
- package/build/cjs/lib/setup/utils.d.ts +10 -0
- package/build/cjs/lib/setup/utils.js +11 -0
- package/build/cjs/lib/setup/utils.js.map +2 -2
- package/build/cjs/lib/setup.js +109 -101
- package/build/cjs/lib/setup.js.map +2 -2
- package/build/esm/lib/setup/setupRepo.d.ts +28 -6
- package/build/esm/lib/setup/setupRepo.d.ts.map +1 -1
- package/build/esm/lib/setup/setupRepo.js +127 -73
- package/build/esm/lib/setup/setupRepo.js.map +1 -1
- package/build/esm/lib/setup/utils.d.ts +10 -0
- package/build/esm/lib/setup/utils.d.ts.map +1 -1
- package/build/esm/lib/setup/utils.js +12 -0
- package/build/esm/lib/setup/utils.js.map +1 -1
- package/build/esm/lib/setup.d.ts.map +1 -1
- package/build/esm/lib/setup.js +122 -114
- package/build/esm/lib/setup.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';
|
|
2
2
|
import type { Client as StatesRedisClient } from '@iobroker/db-states-redis';
|
|
3
|
+
/** The options passed to the Repo constructor */
|
|
3
4
|
export interface CLIRepoOptions {
|
|
5
|
+
/** Instance of objects DB */
|
|
4
6
|
objects: ObjectsRedisClient;
|
|
7
|
+
/** Instance of states DB */
|
|
5
8
|
states: StatesRedisClient;
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* All possible Repo Flags which can be passed to the `show` method
|
|
12
|
+
*/
|
|
7
13
|
export interface RepoFlags {
|
|
8
14
|
/** Also list not installed adapters */
|
|
9
15
|
a?: boolean;
|
|
16
|
+
/** Also list not installed adapters */
|
|
10
17
|
all?: boolean;
|
|
11
18
|
/** Only list updatable adapters */
|
|
12
19
|
u?: boolean;
|
|
20
|
+
/** Only list updatable adapters */
|
|
13
21
|
updatable?: boolean;
|
|
14
22
|
/** Force update even if hash hasn't changed */
|
|
15
23
|
f?: boolean;
|
|
24
|
+
/** Force update even if hash hasn't changed */
|
|
16
25
|
force?: boolean;
|
|
17
26
|
}
|
|
18
27
|
export declare class Repo {
|
|
@@ -21,13 +30,20 @@ export declare class Repo {
|
|
|
21
30
|
private readonly states;
|
|
22
31
|
private readonly controllerVersion;
|
|
23
32
|
constructor(options: CLIRepoOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Get the repository name by index
|
|
35
|
+
* Throws if the index does not exist
|
|
36
|
+
*
|
|
37
|
+
* @param repoIndex repo name or index
|
|
38
|
+
*/
|
|
39
|
+
getNameByIndex(repoIndex: number): Promise<string>;
|
|
24
40
|
/**
|
|
25
41
|
* Update the given repository and returns new repo content
|
|
26
42
|
*
|
|
27
43
|
* @param repoName name of the repository
|
|
28
44
|
* @param force force update even if same hash
|
|
29
|
-
* @param systemConfig content of system.config object
|
|
30
|
-
* @param systemRepos content of system.repositories object
|
|
45
|
+
* @param systemConfig content of `system.config` object
|
|
46
|
+
* @param systemRepos content of `system.repositories` object
|
|
31
47
|
*/
|
|
32
48
|
private updateRepo;
|
|
33
49
|
/**
|
|
@@ -40,7 +56,7 @@ export declare class Repo {
|
|
|
40
56
|
/**
|
|
41
57
|
* Show the repo result on CLI
|
|
42
58
|
*
|
|
43
|
-
* @param sources Repo
|
|
59
|
+
* @param sources Repo JSON sources
|
|
44
60
|
* @param flags CLI flags
|
|
45
61
|
*/
|
|
46
62
|
private showRepoResult;
|
|
@@ -51,7 +67,7 @@ export declare class Repo {
|
|
|
51
67
|
*/
|
|
52
68
|
private updateInfo;
|
|
53
69
|
/**
|
|
54
|
-
* Show current status of Repo on CLI
|
|
70
|
+
* Show the current status of Repo on CLI
|
|
55
71
|
*/
|
|
56
72
|
showRepoStatus(): Promise<number>;
|
|
57
73
|
/**
|
|
@@ -67,10 +83,16 @@ export declare class Repo {
|
|
|
67
83
|
* @param repoName name of repository to remove
|
|
68
84
|
*/
|
|
69
85
|
del(repoName: string): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Checks if stable repo is active
|
|
88
|
+
*
|
|
89
|
+
* @param options the system config object and the repository object
|
|
90
|
+
*/
|
|
91
|
+
private getRepoActiveInfo;
|
|
70
92
|
/**
|
|
71
93
|
* Set specific repo as active one
|
|
72
94
|
*
|
|
73
|
-
* @param repoName name of the
|
|
95
|
+
* @param repoName name of the repository to activate
|
|
74
96
|
*/
|
|
75
97
|
setActive(repoName: string): Promise<void>;
|
|
76
98
|
/**
|
|
@@ -80,7 +102,7 @@ export declare class Repo {
|
|
|
80
102
|
*/
|
|
81
103
|
setInactive(repoName: string): Promise<void>;
|
|
82
104
|
/**
|
|
83
|
-
* Renames existing repository if old name and link matches, renaming will not be performed if
|
|
105
|
+
* Renames existing repository if old name and link matches, renaming will not be performed if a repo with the new name already exists
|
|
84
106
|
*
|
|
85
107
|
* @param oldName - name of the current repository
|
|
86
108
|
* @param newName - target name
|
|
@@ -36,6 +36,7 @@ var import_axios = __toESM(require("axios"), 1);
|
|
|
36
36
|
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
37
37
|
var import_utils = require("../../lib/setup/utils.js");
|
|
38
38
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
39
|
+
var import_constants = require("@iobroker/js-controller-common-db/constants");
|
|
39
40
|
class Repo {
|
|
40
41
|
defaultSystemRepo;
|
|
41
42
|
objects;
|
|
@@ -60,35 +61,52 @@ class Repo {
|
|
|
60
61
|
native: {
|
|
61
62
|
repositories: {
|
|
62
63
|
stable: {
|
|
63
|
-
link:
|
|
64
|
+
link: import_utils.STABLE_REPO_URL,
|
|
64
65
|
json: null
|
|
65
66
|
},
|
|
66
67
|
beta: {
|
|
67
|
-
link:
|
|
68
|
+
link: import_utils.BETA_REPO_URL,
|
|
68
69
|
json: null
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
},
|
|
72
|
-
_id:
|
|
73
|
+
_id: import_constants.SYSTEM_REPOSITORIES_ID,
|
|
73
74
|
type: "config"
|
|
74
75
|
};
|
|
75
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the repository name by index
|
|
79
|
+
* Throws if the index does not exist
|
|
80
|
+
*
|
|
81
|
+
* @param repoIndex repo name or index
|
|
82
|
+
*/
|
|
83
|
+
async getNameByIndex(repoIndex) {
|
|
84
|
+
const obj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
85
|
+
if (!obj?.native?.repositories) {
|
|
86
|
+
throw new Error("No repositories setup!");
|
|
87
|
+
}
|
|
88
|
+
const repoNames = Object.keys(obj.native.repositories);
|
|
89
|
+
if (!repoNames[repoIndex]) {
|
|
90
|
+
throw new Error(`No repository for index "${repoIndex}" found`);
|
|
91
|
+
}
|
|
92
|
+
return repoNames[repoIndex];
|
|
93
|
+
}
|
|
76
94
|
/**
|
|
77
95
|
* Update the given repository and returns new repo content
|
|
78
96
|
*
|
|
79
97
|
* @param repoName name of the repository
|
|
80
98
|
* @param force force update even if same hash
|
|
81
|
-
* @param systemConfig content of system.config object
|
|
82
|
-
* @param systemRepos content of system.repositories object
|
|
99
|
+
* @param systemConfig content of `system.config` object
|
|
100
|
+
* @param systemRepos content of `system.repositories` object
|
|
83
101
|
*/
|
|
84
102
|
async updateRepo(repoName, force, systemConfig, systemRepos) {
|
|
85
103
|
if (!repoName) {
|
|
86
|
-
const sysConfig = systemConfig || await this.objects.getObject(
|
|
104
|
+
const sysConfig = systemConfig || await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID);
|
|
87
105
|
repoName = sysConfig.common.activeRepo;
|
|
88
106
|
}
|
|
89
|
-
const oldRepos = systemRepos || await this.objects.getObject(
|
|
107
|
+
const oldRepos = systemRepos || await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
90
108
|
if (!oldRepos?.native.repositories?.[repoName]) {
|
|
91
|
-
console.log(`Error: repository "${repoName}" not found in the "
|
|
109
|
+
console.log(`Error: repository "${repoName}" not found in the "${import_constants.SYSTEM_REPOSITORIES_ID}"`);
|
|
92
110
|
return null;
|
|
93
111
|
}
|
|
94
112
|
const urlOrPath = oldRepos.native.repositories[repoName].link;
|
|
@@ -152,7 +170,7 @@ class Repo {
|
|
|
152
170
|
if (changed) {
|
|
153
171
|
oldRepos.from = `system.host.${import_js_controller_common.tools.getHostName()}.cli`;
|
|
154
172
|
oldRepos.ts = Date.now();
|
|
155
|
-
await this.objects.setObject(
|
|
173
|
+
await this.objects.setObject(import_constants.SYSTEM_REPOSITORIES_ID, oldRepos);
|
|
156
174
|
}
|
|
157
175
|
return oldRepos.native.repositories[repoName].json;
|
|
158
176
|
}
|
|
@@ -163,14 +181,14 @@ class Repo {
|
|
|
163
181
|
* @param flags CLI flags
|
|
164
182
|
*/
|
|
165
183
|
async showRepo(repoUrl, flags) {
|
|
166
|
-
const systemConfig = await this.objects.getObject(
|
|
167
|
-
const systemRepos = await this.objects.getObject(
|
|
184
|
+
const systemConfig = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID);
|
|
185
|
+
const systemRepos = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
168
186
|
if (!systemConfig) {
|
|
169
|
-
console.error(
|
|
187
|
+
console.error(`Error: Object "${import_constants.SYSTEM_CONFIG_ID}" not found`);
|
|
170
188
|
} else if (!systemRepos) {
|
|
171
|
-
console.error(
|
|
189
|
+
console.error(`Error: Object "${import_constants.SYSTEM_REPOSITORIES_ID}" not found`);
|
|
172
190
|
} else if (!systemRepos.native || !systemRepos.native.repositories) {
|
|
173
|
-
console.error(
|
|
191
|
+
console.error(`Error: no repositories found in the "${import_constants.SYSTEM_REPOSITORIES_ID}"`);
|
|
174
192
|
} else {
|
|
175
193
|
repoUrl = repoUrl || systemConfig.common.activeRepo;
|
|
176
194
|
if (!Array.isArray(repoUrl)) {
|
|
@@ -204,7 +222,7 @@ class Repo {
|
|
|
204
222
|
/**
|
|
205
223
|
* Show the repo result on CLI
|
|
206
224
|
*
|
|
207
|
-
* @param sources Repo
|
|
225
|
+
* @param sources Repo JSON sources
|
|
208
226
|
* @param flags CLI flags
|
|
209
227
|
*/
|
|
210
228
|
async showRepoResult(sources, flags) {
|
|
@@ -280,12 +298,12 @@ class Repo {
|
|
|
280
298
|
}
|
|
281
299
|
}
|
|
282
300
|
/**
|
|
283
|
-
* Show current status of Repo on CLI
|
|
301
|
+
* Show the current status of Repo on CLI
|
|
284
302
|
*/
|
|
285
303
|
async showRepoStatus() {
|
|
286
304
|
try {
|
|
287
|
-
const obj = await this.objects.getObject(
|
|
288
|
-
const objCfg = await this.objects.getObject(
|
|
305
|
+
const obj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
306
|
+
const objCfg = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID);
|
|
289
307
|
if (!obj) {
|
|
290
308
|
console.error("List is empty");
|
|
291
309
|
return import_js_controller_common.EXIT_CODES.CANNOT_GET_REPO_LIST;
|
|
@@ -322,18 +340,21 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
322
340
|
* @param repoUrl url of new repo
|
|
323
341
|
*/
|
|
324
342
|
async add(repoName, repoUrl) {
|
|
325
|
-
const sysRepoObj = await this.objects.
|
|
343
|
+
const sysRepoObj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
326
344
|
const obj = sysRepoObj || this.defaultSystemRepo;
|
|
327
345
|
if (obj.native.repositories[repoName]) {
|
|
328
346
|
throw new Error(`Repository "${repoName}" yet exists: ${obj.native.repositories[repoName].link}`);
|
|
329
347
|
} else {
|
|
348
|
+
if ((0, import_utils.isIntegerLikeInput)(repoName)) {
|
|
349
|
+
throw new Error(`Invalid name "${repoName}"! A repository name is not allowed to contain only numbers.`);
|
|
350
|
+
}
|
|
330
351
|
obj.native.repositories[repoName] = {
|
|
331
352
|
link: repoUrl,
|
|
332
353
|
json: null
|
|
333
354
|
};
|
|
334
355
|
obj.from = `system.host.${import_js_controller_common.tools.getHostName()}.cli`;
|
|
335
356
|
obj.ts = Date.now();
|
|
336
|
-
await this.objects.
|
|
357
|
+
await this.objects.setObject(import_constants.SYSTEM_REPOSITORIES_ID, obj);
|
|
337
358
|
}
|
|
338
359
|
}
|
|
339
360
|
/**
|
|
@@ -342,11 +363,11 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
342
363
|
* @param repoName name of repository to remove
|
|
343
364
|
*/
|
|
344
365
|
async del(repoName) {
|
|
345
|
-
const obj = await this.objects.
|
|
366
|
+
const obj = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID);
|
|
346
367
|
if (obj?.common.activeRepo && typeof obj.common.activeRepo === "string" && obj.common.activeRepo === repoName || obj?.common.activeRepo && Array.isArray(obj.common.activeRepo) && obj.common.activeRepo.includes(repoName)) {
|
|
347
368
|
throw new Error(`Cannot delete active repository: ${repoName}`);
|
|
348
369
|
} else {
|
|
349
|
-
const repoObj = await this.objects.
|
|
370
|
+
const repoObj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
350
371
|
if (repoObj) {
|
|
351
372
|
if (!repoObj.native.repositories[repoName]) {
|
|
352
373
|
throw new Error(`Repository "${repoName}" not found.`);
|
|
@@ -354,33 +375,65 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
354
375
|
delete repoObj.native.repositories[repoName];
|
|
355
376
|
repoObj.from = `system.host.${import_js_controller_common.tools.getHostName()}.cli`;
|
|
356
377
|
repoObj.ts = Date.now();
|
|
357
|
-
await this.objects.setObject(
|
|
378
|
+
await this.objects.setObject(import_constants.SYSTEM_REPOSITORIES_ID, repoObj);
|
|
358
379
|
}
|
|
359
380
|
}
|
|
360
381
|
}
|
|
361
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Checks if stable repo is active
|
|
385
|
+
*
|
|
386
|
+
* @param options the system config object and the repository object
|
|
387
|
+
*/
|
|
388
|
+
getRepoActiveInfo(options) {
|
|
389
|
+
const { repoObj, sysConfObj, url } = options;
|
|
390
|
+
const name = sysConfObj.common.activeRepo.find((activeRepo) => repoObj.native.repositories[activeRepo].link === url);
|
|
391
|
+
return name ? { isActive: true, name } : { isActive: false };
|
|
392
|
+
}
|
|
362
393
|
/**
|
|
363
394
|
* Set specific repo as active one
|
|
364
395
|
*
|
|
365
|
-
* @param repoName name of the
|
|
396
|
+
* @param repoName name of the repository to activate
|
|
366
397
|
*/
|
|
367
398
|
async setActive(repoName) {
|
|
368
|
-
const sysRepoObj = await this.objects.
|
|
399
|
+
const sysRepoObj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
369
400
|
const obj = sysRepoObj || this.defaultSystemRepo;
|
|
370
401
|
if (!obj.native.repositories[repoName]) {
|
|
371
402
|
throw new Error(`Repository "${repoName}" not found.`);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
403
|
+
}
|
|
404
|
+
const confObj = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID);
|
|
405
|
+
if (typeof confObj?.common.activeRepo === "string") {
|
|
406
|
+
confObj.common.activeRepo = [confObj.common.activeRepo];
|
|
407
|
+
}
|
|
408
|
+
if (!confObj || confObj.common.activeRepo.includes(repoName)) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
confObj.common.activeRepo.push(repoName);
|
|
412
|
+
const stableInfo = this.getRepoActiveInfo({
|
|
413
|
+
url: import_utils.STABLE_REPO_URL,
|
|
414
|
+
sysConfObj: confObj,
|
|
415
|
+
repoObj: obj
|
|
416
|
+
});
|
|
417
|
+
const betaInfo = this.getRepoActiveInfo({
|
|
418
|
+
url: import_utils.BETA_REPO_URL,
|
|
419
|
+
sysConfObj: confObj,
|
|
420
|
+
repoObj: obj
|
|
421
|
+
});
|
|
422
|
+
if (stableInfo.isActive && betaInfo.isActive) {
|
|
423
|
+
const posStable = confObj.common.activeRepo.indexOf(stableInfo.name);
|
|
424
|
+
const posBeta = confObj.common.activeRepo.indexOf(betaInfo.name);
|
|
425
|
+
if (posStable < posBeta) {
|
|
426
|
+
confObj.common.activeRepo.splice(posBeta, 1);
|
|
427
|
+
confObj.common.activeRepo.splice(posStable, 0, betaInfo.name);
|
|
428
|
+
console.info(`Ensured that stable repository "${stableInfo.name}" has priority over beta repository "${betaInfo.name}"`);
|
|
382
429
|
}
|
|
383
430
|
}
|
|
431
|
+
if (confObj.common.activeRepo.length > 1) {
|
|
432
|
+
console.info("More than one repository is active. Please be sure, that this is a desired constellation!");
|
|
433
|
+
}
|
|
434
|
+
confObj.from = `system.host.${import_js_controller_common.tools.getHostName()}.cli`;
|
|
435
|
+
confObj.ts = Date.now();
|
|
436
|
+
await this.objects.setObject(import_constants.SYSTEM_CONFIG_ID, confObj);
|
|
384
437
|
}
|
|
385
438
|
/**
|
|
386
439
|
* Set given repo as inactive
|
|
@@ -388,7 +441,7 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
388
441
|
* @param repoName name of the repository
|
|
389
442
|
*/
|
|
390
443
|
async setInactive(repoName) {
|
|
391
|
-
const confObj = await this.objects.
|
|
444
|
+
const confObj = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID);
|
|
392
445
|
if (typeof confObj?.common.activeRepo === "string") {
|
|
393
446
|
confObj.common.activeRepo = [confObj.common.activeRepo];
|
|
394
447
|
}
|
|
@@ -397,11 +450,11 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
397
450
|
confObj.common.activeRepo.splice(pos, 1);
|
|
398
451
|
confObj.from = `system.host.${import_js_controller_common.tools.getHostName()}.cli`;
|
|
399
452
|
confObj.ts = Date.now();
|
|
400
|
-
await this.objects.
|
|
453
|
+
await this.objects.setObject(import_constants.SYSTEM_CONFIG_ID, confObj);
|
|
401
454
|
}
|
|
402
455
|
}
|
|
403
456
|
/**
|
|
404
|
-
* Renames existing repository if old name and link matches, renaming will not be performed if
|
|
457
|
+
* Renames existing repository if old name and link matches, renaming will not be performed if a repo with the new name already exists
|
|
405
458
|
*
|
|
406
459
|
* @param oldName - name of the current repository
|
|
407
460
|
* @param newName - target name
|
|
@@ -411,32 +464,36 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
411
464
|
let repoObj;
|
|
412
465
|
let sysConfigObj;
|
|
413
466
|
try {
|
|
414
|
-
sysConfigObj = await this.objects.
|
|
415
|
-
repoObj = await this.objects.
|
|
467
|
+
sysConfigObj = await this.objects.getObject(import_constants.SYSTEM_CONFIG_ID);
|
|
468
|
+
repoObj = await this.objects.getObject(import_constants.SYSTEM_REPOSITORIES_ID);
|
|
416
469
|
} catch (err) {
|
|
417
470
|
throw new Error(`Could not rename repository "${oldName}" to "${newName}": ${err.message}`);
|
|
418
471
|
}
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
472
|
+
if ((0, import_utils.isIntegerLikeInput)(newName)) {
|
|
473
|
+
throw new Error(`Invalid name "${newName}"! A repository name is not allowed to contain only numbers.`);
|
|
474
|
+
}
|
|
475
|
+
if (!repoObj) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (repoObj.native.repositories[oldName] && repoObj.native.repositories[oldName].link === repoUrl && !repoObj.native.repositories[newName]) {
|
|
479
|
+
repoObj.native.repositories[newName] = repoObj.native.repositories[oldName];
|
|
480
|
+
delete repoObj.native.repositories[oldName];
|
|
481
|
+
try {
|
|
482
|
+
await this.objects.setObject(import_constants.SYSTEM_REPOSITORIES_ID, repoObj);
|
|
483
|
+
console.log(`Renamed repository "${oldName} to "${newName}"`);
|
|
484
|
+
} catch (e) {
|
|
485
|
+
throw new Error(`Could not rename repository "${oldName}" to "${newName}": ${e.message}`);
|
|
486
|
+
}
|
|
487
|
+
if (sysConfigObj?.common && (typeof sysConfigObj.common.activeRepo === "string" && sysConfigObj.common.activeRepo === oldName || Array.isArray(sysConfigObj.common.activeRepo) && sysConfigObj.common.activeRepo.includes(oldName))) {
|
|
488
|
+
if (typeof sysConfigObj.common.activeRepo === "string") {
|
|
489
|
+
sysConfigObj.common.activeRepo = [sysConfigObj.common.activeRepo];
|
|
428
490
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
try {
|
|
436
|
-
await this.objects.setObjectAsync("system.config", sysConfigObj);
|
|
437
|
-
} catch (err) {
|
|
438
|
-
throw new Error(`Could not set "${newName}" as active repository: ${err.message}`);
|
|
439
|
-
}
|
|
491
|
+
const pos = sysConfigObj.common.activeRepo.indexOf(oldName);
|
|
492
|
+
sysConfigObj.common.activeRepo.splice(pos, 1, newName);
|
|
493
|
+
try {
|
|
494
|
+
await this.objects.setObject(import_constants.SYSTEM_CONFIG_ID, sysConfigObj);
|
|
495
|
+
} catch (e) {
|
|
496
|
+
throw new Error(`Could not set "${newName}" as active repository: ${e.message}`);
|
|
440
497
|
}
|
|
441
498
|
}
|
|
442
499
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/setup/setupRepo.ts"],
|
|
4
|
-
"sourcesContent": ["import { tools, EXIT_CODES } from '@iobroker/js-controller-common';\nimport axios from 'axios';\nimport fs from 'fs-extra';\nimport type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport type { Client as StatesRedisClient } from '@iobroker/db-states-redis';\nimport { isVersionIgnored } from '@/lib/setup/utils.js';\nimport path from 'node:path';\n\nexport interface CLIRepoOptions {\n objects: ObjectsRedisClient;\n states: StatesRedisClient;\n}\n\nexport interface RepoFlags {\n /** Also list not installed adapters */\n a?: boolean;\n all?: boolean;\n /** Only list updatable adapters */\n u?: boolean;\n updatable?: boolean;\n /** Force update even if hash hasn't changed */\n f?: boolean;\n force?: boolean;\n}\n\nexport class Repo {\n private readonly defaultSystemRepo: ioBroker.RepositoryObject;\n private readonly objects: ObjectsRedisClient;\n private readonly states: StatesRedisClient;\n private readonly controllerVersion: string;\n\n constructor(options: CLIRepoOptions) {\n if (!options?.objects) {\n throw new Error('Invalid arguments: objects is missing');\n }\n if (!options?.states) {\n throw new Error('Invalid arguments: states is missing');\n }\n\n const ioPackage = fs.readJSONSync(path.join(tools.getControllerDir(), 'io-package.json'));\n this.controllerVersion = ioPackage.common.version;\n\n this.objects = options.objects;\n this.states = options.states;\n\n this.defaultSystemRepo = {\n common: {\n name: 'System repositories',\n dontDelete: true,\n },\n native: {\n repositories: {\n stable: {\n link: 'http://download.iobroker.net/sources-dist.json',\n json: null,\n },\n beta: {\n link: 'http://download.iobroker.net/sources-dist-latest.json',\n json: null,\n },\n },\n },\n _id: 'system.repositories',\n type: 'config',\n };\n }\n\n /**\n * Update the given repository and returns new repo content\n *\n * @param repoName name of the repository\n * @param force force update even if same hash\n * @param systemConfig content of system.config object\n * @param systemRepos content of system.repositories object\n */\n private async updateRepo(\n repoName: string,\n force: boolean | undefined,\n systemConfig?: ioBroker.OtherObject,\n systemRepos?: ioBroker.RepositoryObject,\n ): Promise<null | ioBroker.RepositoryJson> {\n if (!repoName) {\n const sysConfig = systemConfig || (await this.objects.getObject('system.config'));\n repoName = sysConfig!.common.activeRepo;\n }\n\n const oldRepos = systemRepos || (await this.objects.getObject('system.repositories'));\n if (!oldRepos?.native.repositories?.[repoName]) {\n console.log(`Error: repository \"${repoName}\" not found in the \"system.repositories`);\n return null;\n }\n\n const urlOrPath = oldRepos.native.repositories[repoName].link;\n const hashUrl = urlOrPath.replace(/\\.json$/, '-hash.json');\n let hash;\n\n if (\n !force &&\n oldRepos.native.repositories[repoName].hash &&\n oldRepos.native.repositories[repoName].json &&\n (urlOrPath.startsWith('http://') || urlOrPath.startsWith('https://'))\n ) {\n try {\n hash = await axios({ url: hashUrl, timeout: 10_000 });\n } catch (e) {\n console.error(`Cannot download repository hash file from \"${hashUrl}\": ${e.message}`);\n }\n if (hash?.data && oldRepos.native.repositories[repoName].hash === hash.data.hash) {\n return oldRepos.native.repositories[repoName].json;\n }\n }\n\n let data;\n\n if (urlOrPath.startsWith('http://') || urlOrPath.startsWith('https://')) {\n if (!hash) {\n try {\n hash = await axios({ url: hashUrl, timeout: 10000 });\n } catch (e) {\n console.error(`Cannot download repository hash file from \"${hashUrl}\": ${e.message}`);\n }\n }\n\n const agent = `${tools.appName}, RND: CLI, Node:${process.version}, V:${this.controllerVersion}`;\n try {\n data = await axios({\n url: urlOrPath,\n timeout: 10_000,\n headers: { 'User-Agent': agent },\n });\n if (data.data) {\n data = data.data;\n } else {\n data = null;\n }\n } catch (e) {\n console.error(`Cannot download repository file from \"${urlOrPath}\": ${e.message}`);\n data = null;\n }\n } else {\n if (fs.existsSync(urlOrPath)) {\n try {\n data = JSON.parse(fs.readFileSync(urlOrPath).toString('utf8'));\n } catch (err) {\n console.error(`Error: Cannot read or parse file \"${urlOrPath}\": ${err.message}`);\n }\n } else {\n console.error(`Error: Cannot find file \"${urlOrPath}\"`);\n }\n }\n\n let changed;\n if (data) {\n oldRepos.native.repositories[repoName].json = data;\n changed = true;\n }\n if (hash?.data) {\n oldRepos.native.repositories[repoName].hash = hash.data.hash;\n changed = true;\n }\n if (changed) {\n oldRepos.from = `system.host.${tools.getHostName()}.cli`;\n oldRepos.ts = Date.now();\n await this.objects.setObject('system.repositories', oldRepos);\n }\n\n return oldRepos.native.repositories[repoName].json;\n }\n\n /**\n * Show repo on CLI\n *\n * @param repoUrl url of the repository\n * @param flags CLI flags\n */\n async showRepo(repoUrl: string | string[], flags: RepoFlags): Promise<void> {\n // Get the repositories\n const systemConfig = await this.objects.getObject('system.config');\n const systemRepos = await this.objects.getObject('system.repositories');\n if (!systemConfig) {\n console.error('Error: Object \"system.config\" not found');\n } else if (!systemRepos) {\n console.error('Error: Object \"system.repositories\" not found');\n } else if (!systemRepos.native || !systemRepos.native.repositories) {\n console.error('Error: no repositories found in the \"system.config');\n } else {\n repoUrl = repoUrl || systemConfig.common.activeRepo;\n\n if (!Array.isArray(repoUrl)) {\n repoUrl = [repoUrl];\n }\n\n console.log(`Used ${repoUrl.length > 1 ? 'repositories' : 'repository'}: ${repoUrl.join(', ')}`);\n\n const allSources = {};\n\n for (const url of repoUrl) {\n const repo = systemRepos.native.repositories[url];\n // If known repository\n if (repo) {\n if (typeof repo === 'string') {\n systemRepos.native.repositories[url] = {\n link: repo,\n json: null,\n hash: '',\n };\n }\n\n const sources = await this.updateRepo(url, flags.force || flags.f, systemConfig, systemRepos);\n sources && Object.assign(allSources, sources);\n } else {\n console.error(\n `Error: unknown repository is active - \"${url}\". Known: ${Object.keys(\n systemRepos.native.repositories,\n ).join(', ')}`,\n );\n }\n }\n\n try {\n // update variables of every admin instance\n await this.updateInfo(allSources);\n } catch {\n // not important if fails\n }\n\n return this.showRepoResult(allSources, flags);\n }\n }\n\n /**\n * Show the repo result on CLI\n *\n * @param sources Repo json sources\n * @param flags CLI flags\n */\n private async showRepoResult(sources: Record<string, any>, flags: RepoFlags): Promise<void> {\n const installed = tools.getInstalledInfo();\n const adapters = Object.keys(sources).sort();\n\n for (const name of adapters) {\n let updatable = false;\n let text = sources[name].controller ? 'Controller ' : 'Adapter ';\n text += `\"${name}\"`;\n text = text.padEnd(11 + 15);\n\n if (sources[name].version) {\n text += `: ${sources[name].version}`;\n }\n text = text.padEnd(11 + 15 + 11);\n\n if (!(flags.all || flags.a) && !installed[name]) {\n continue;\n }\n\n if (installed[name]?.version) {\n text += `, installed ${installed[name].version}`;\n try {\n // tools.upToDate can throw if version is invalid\n if (\n sources[name].version !== installed[name].version &&\n sources[name].version &&\n !tools.upToDate(sources[name].version, installed[name].version)\n ) {\n updatable = true;\n text = text.padEnd(11 + 15 + 11 + 18);\n const isIgnored = await isVersionIgnored({\n adapterName: name,\n objects: this.objects,\n version: sources[name].version,\n });\n\n text += isIgnored ? ' [Ignored]' : ' [Updatable]';\n }\n } catch (e) {\n console.error(`Cannot determine update info of \"${name}\": ${e.message}`);\n }\n }\n if ((flags.updatable || flags.u) && !updatable) {\n continue;\n }\n console.log(text);\n }\n }\n\n /**\n * Update Admin info states with number of updates\n *\n * @param sources the repository object\n */\n private async updateInfo(sources: Record<string, any>): Promise<void> {\n const installed = tools.getInstalledInfo();\n const list: string[] = [];\n\n for (const name of Object.keys(sources)) {\n if (installed[name] && installed[name].version && sources[name].version) {\n try {\n // tools.upToDate can throw if version is invalid\n if (\n sources[name].version !== installed[name].version &&\n !tools.upToDate(sources[name].version, installed[name].version)\n ) {\n // remove first part of the name\n const n = name.indexOf('.');\n list.push(n === -1 ? name : name.substring(n + 1));\n }\n } catch (e) {\n console.error(`Cannot determine update info of \"${name}\": ${e.message}`);\n }\n }\n }\n\n const objs = await this.objects.getObjectViewAsync('system', 'instance', {\n startkey: 'system.adapter.admin',\n endkey: 'system.adapter.admin\\u9999',\n });\n\n if (objs?.rows?.length) {\n const listStr = list.join(', ');\n for (const row of objs.rows) {\n if (row?.value?.type === 'instance') {\n await this.states.setState(`${row.id}.info.updatesNumber`, { val: list.length, ack: true });\n await this.states.setState(`${row.id}.info.updatesList`, { val: listStr, ack: true });\n }\n }\n }\n }\n\n /**\n * Show current status of Repo on CLI\n */\n async showRepoStatus(): Promise<number> {\n try {\n const obj = await this.objects.getObject('system.repositories');\n const objCfg = await this.objects.getObject('system.config');\n\n if (!obj) {\n console.error('List is empty');\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n } else if (obj.native.repositories) {\n console.table(\n Object.entries(obj.native.repositories).map(([key, value]) => {\n return {\n name: key,\n url: value.link,\n 'auto upgrade': objCfg?.common.adapterAutoUpgrade?.repositories[key] ?? false,\n };\n }),\n );\n\n if (objCfg?.common) {\n let activeRepo = objCfg.common.activeRepo;\n if (typeof activeRepo === 'string') {\n activeRepo = [activeRepo];\n }\n console.log(`\\nActive repo(s): ${activeRepo.join(', ')}`);\n console.log(`Upgrade policy: ${objCfg.common.adapterAutoUpgrade?.defaultPolicy ?? 'none'}`);\n }\n } else {\n console.error('List is empty');\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n }\n } catch (err) {\n console.error(`Cannot get list: ${err}`);\n }\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n }\n\n /**\n * Add new repo\n *\n * @param repoName name of new repo\n * @param repoUrl url of new repo\n */\n async add(repoName: string, repoUrl: string): Promise<void> {\n const sysRepoObj = await this.objects.getObjectAsync('system.repositories');\n const obj = sysRepoObj || this.defaultSystemRepo;\n\n if (obj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" yet exists: ${obj.native.repositories[repoName].link}`);\n } else {\n obj.native.repositories[repoName] = {\n link: repoUrl,\n json: null,\n };\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n await this.objects.setObjectAsync('system.repositories', obj);\n }\n }\n\n /**\n * Remove repository from sources\n *\n * @param repoName name of repository to remove\n */\n async del(repoName: string): Promise<void> {\n const obj = await this.objects.getObjectAsync('system.config');\n if (\n (obj?.common.activeRepo &&\n typeof obj.common.activeRepo === 'string' &&\n obj.common.activeRepo === repoName) ||\n (obj?.common.activeRepo && Array.isArray(obj.common.activeRepo) && obj.common.activeRepo.includes(repoName))\n ) {\n throw new Error(`Cannot delete active repository: ${repoName}`);\n } else {\n const repoObj = await this.objects.getObjectAsync('system.repositories');\n if (repoObj) {\n if (!repoObj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" not found.`);\n } else {\n delete repoObj.native.repositories[repoName];\n repoObj.from = `system.host.${tools.getHostName()}.cli`;\n repoObj.ts = Date.now();\n await this.objects.setObject('system.repositories', repoObj);\n }\n }\n }\n }\n\n /**\n * Set specific repo as active one\n *\n * @param repoName name of the respository to activate\n */\n async setActive(repoName: string): Promise<void> {\n const sysRepoObj = await this.objects.getObjectAsync('system.repositories');\n const obj = sysRepoObj || this.defaultSystemRepo;\n\n if (!obj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" not found.`);\n } else {\n const confObj = await this.objects.getObjectAsync('system.config');\n if (typeof confObj?.common.activeRepo === 'string') {\n confObj.common.activeRepo = [confObj.common.activeRepo];\n }\n\n if (confObj && !confObj.common.activeRepo.includes(repoName)) {\n confObj.common.activeRepo.push(repoName);\n confObj.from = `system.host.${tools.getHostName()}.cli`;\n confObj.ts = Date.now();\n await this.objects.setObjectAsync('system.config', confObj);\n }\n }\n }\n\n /**\n * Set given repo as inactive\n *\n * @param repoName name of the repository\n */\n async setInactive(repoName: string): Promise<void> {\n const confObj = (await this.objects.getObjectAsync('system.config'))!;\n if (typeof confObj?.common.activeRepo === 'string') {\n confObj.common.activeRepo = [confObj.common.activeRepo];\n }\n\n const pos = confObj.common.activeRepo.indexOf(repoName);\n if (pos !== -1) {\n confObj.common.activeRepo.splice(pos, 1);\n confObj.from = `system.host.${tools.getHostName()}.cli`;\n confObj.ts = Date.now();\n await this.objects.setObjectAsync('system.config', confObj);\n }\n }\n\n /**\n * Renames existing repository if old name and link matches, renaming will not be performed if an repo with the new name already exists\n *\n * @param oldName - name of the current repository\n * @param newName - target name\n * @param repoUrl - hyperlink of the repository\n */\n async rename(oldName: string, newName: string, repoUrl: string): Promise<void> {\n let repoObj;\n let sysConfigObj;\n try {\n sysConfigObj = await this.objects.getObjectAsync('system.config');\n repoObj = await this.objects.getObjectAsync('system.repositories');\n } catch (err) {\n throw new Error(`Could not rename repository \"${oldName}\" to \"${newName}\": ${err.message}`);\n }\n\n if (repoObj && repoObj.native && repoObj.native.repositories) {\n if (\n repoObj.native.repositories[oldName] &&\n repoObj.native.repositories[oldName].link === repoUrl &&\n !repoObj.native.repositories[newName]\n ) {\n repoObj.native.repositories[newName] = repoObj.native.repositories[oldName];\n delete repoObj.native.repositories[oldName];\n\n try {\n await this.objects.setObjectAsync('system.repositories', repoObj);\n console.log(`Renamed repository \"${oldName} to \"${newName}\"`);\n } catch (err) {\n throw new Error(`Could not rename repository \"${oldName}\" to \"${newName}\": ${err.message}`);\n }\n\n // if we changed the name of the activeRepo, we should set newName as active repo\n if (\n sysConfigObj &&\n sysConfigObj.common &&\n ((typeof sysConfigObj.common.activeRepo === 'string' &&\n sysConfigObj.common.activeRepo === oldName) ||\n (Array.isArray(sysConfigObj.common.activeRepo) &&\n sysConfigObj.common.activeRepo.includes(oldName)))\n ) {\n if (typeof sysConfigObj.common.activeRepo === 'string') {\n sysConfigObj.common.activeRepo = [sysConfigObj.common.activeRepo];\n }\n const pos = sysConfigObj.common.activeRepo.indexOf(oldName);\n sysConfigObj.common.activeRepo.splice(pos, 1, newName);\n\n try {\n await this.objects.setObjectAsync('system.config', sysConfigObj);\n } catch (err) {\n throw new Error(`Could not set \"${newName}\" as active repository: ${err.message}`);\n }\n }\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kCAAkC;AAClC,mBAAkB;AAClB,sBAAe;AAGf,
|
|
4
|
+
"sourcesContent": ["import { tools, EXIT_CODES } from '@iobroker/js-controller-common';\nimport axios from 'axios';\nimport fs from 'fs-extra';\nimport type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport type { Client as StatesRedisClient } from '@iobroker/db-states-redis';\nimport { BETA_REPO_URL, isIntegerLikeInput, isVersionIgnored, STABLE_REPO_URL } from '@/lib/setup/utils.js';\nimport path from 'node:path';\nimport { SYSTEM_CONFIG_ID, SYSTEM_REPOSITORIES_ID } from '@iobroker/js-controller-common-db/constants';\n\n/** The options passed to the Repo constructor */\nexport interface CLIRepoOptions {\n /** Instance of objects DB */\n objects: ObjectsRedisClient;\n /** Instance of states DB */\n states: StatesRedisClient;\n}\n\n/**\n * All possible Repo Flags which can be passed to the `show` method\n */\nexport interface RepoFlags {\n /** Also list not installed adapters */\n a?: boolean;\n /** Also list not installed adapters */\n all?: boolean;\n /** Only list updatable adapters */\n u?: boolean;\n /** Only list updatable adapters */\n updatable?: boolean;\n /** Force update even if hash hasn't changed */\n f?: boolean;\n /** Force update even if hash hasn't changed */\n force?: boolean;\n}\n\ntype RepoActiveInfo =\n | {\n /** If the repo is active */\n isActive: true;\n /** Name of the repository */\n name: string;\n }\n | {\n /** If the repo is active */\n isActive: false;\n };\n\ninterface RepoActiveOptions {\n /** Url to check if active */\n url: string;\n /** System config object */\n sysConfObj: ioBroker.SystemConfigObject;\n /** Repository object */\n repoObj: ioBroker.RepositoryObject;\n}\n\nexport class Repo {\n private readonly defaultSystemRepo: ioBroker.RepositoryObject;\n private readonly objects: ObjectsRedisClient;\n private readonly states: StatesRedisClient;\n private readonly controllerVersion: string;\n\n constructor(options: CLIRepoOptions) {\n if (!options?.objects) {\n throw new Error('Invalid arguments: objects is missing');\n }\n if (!options?.states) {\n throw new Error('Invalid arguments: states is missing');\n }\n\n const ioPackage = fs.readJSONSync(path.join(tools.getControllerDir(), 'io-package.json'));\n this.controllerVersion = ioPackage.common.version;\n\n this.objects = options.objects;\n this.states = options.states;\n\n this.defaultSystemRepo = {\n common: {\n name: 'System repositories',\n dontDelete: true,\n },\n native: {\n repositories: {\n stable: {\n link: STABLE_REPO_URL,\n json: null,\n },\n beta: {\n link: BETA_REPO_URL,\n json: null,\n },\n },\n },\n _id: SYSTEM_REPOSITORIES_ID,\n type: 'config',\n };\n }\n\n /**\n * Get the repository name by index\n * Throws if the index does not exist\n *\n * @param repoIndex repo name or index\n */\n async getNameByIndex(repoIndex: number): Promise<string> {\n const obj = await this.objects.getObject(SYSTEM_REPOSITORIES_ID);\n if (!obj?.native?.repositories) {\n throw new Error('No repositories setup!');\n }\n\n const repoNames = Object.keys(obj.native.repositories);\n if (!repoNames[repoIndex]) {\n throw new Error(`No repository for index \"${repoIndex}\" found`);\n }\n\n return repoNames[repoIndex];\n }\n\n /**\n * Update the given repository and returns new repo content\n *\n * @param repoName name of the repository\n * @param force force update even if same hash\n * @param systemConfig content of `system.config` object\n * @param systemRepos content of `system.repositories` object\n */\n private async updateRepo(\n repoName: string,\n force: boolean | undefined,\n systemConfig?: ioBroker.OtherObject,\n systemRepos?: ioBroker.RepositoryObject,\n ): Promise<null | ioBroker.RepositoryJson> {\n if (!repoName) {\n const sysConfig = systemConfig || (await this.objects.getObject(SYSTEM_CONFIG_ID));\n repoName = sysConfig!.common.activeRepo;\n }\n\n const oldRepos = systemRepos || (await this.objects.getObject(SYSTEM_REPOSITORIES_ID));\n if (!oldRepos?.native.repositories?.[repoName]) {\n console.log(`Error: repository \"${repoName}\" not found in the \"${SYSTEM_REPOSITORIES_ID}\"`);\n return null;\n }\n\n const urlOrPath = oldRepos.native.repositories[repoName].link;\n const hashUrl = urlOrPath.replace(/\\.json$/, '-hash.json');\n let hash;\n\n if (\n !force &&\n oldRepos.native.repositories[repoName].hash &&\n oldRepos.native.repositories[repoName].json &&\n (urlOrPath.startsWith('http://') || urlOrPath.startsWith('https://'))\n ) {\n try {\n hash = await axios({ url: hashUrl, timeout: 10_000 });\n } catch (e) {\n console.error(`Cannot download repository hash file from \"${hashUrl}\": ${e.message}`);\n }\n if (hash?.data && oldRepos.native.repositories[repoName].hash === hash.data.hash) {\n return oldRepos.native.repositories[repoName].json;\n }\n }\n\n let data;\n\n if (urlOrPath.startsWith('http://') || urlOrPath.startsWith('https://')) {\n if (!hash) {\n try {\n hash = await axios({ url: hashUrl, timeout: 10000 });\n } catch (e) {\n console.error(`Cannot download repository hash file from \"${hashUrl}\": ${e.message}`);\n }\n }\n\n const agent = `${tools.appName}, RND: CLI, Node:${process.version}, V:${this.controllerVersion}`;\n try {\n data = await axios({\n url: urlOrPath,\n timeout: 10_000,\n headers: { 'User-Agent': agent },\n });\n if (data.data) {\n data = data.data;\n } else {\n data = null;\n }\n } catch (e) {\n console.error(`Cannot download repository file from \"${urlOrPath}\": ${e.message}`);\n data = null;\n }\n } else {\n if (fs.existsSync(urlOrPath)) {\n try {\n data = JSON.parse(fs.readFileSync(urlOrPath).toString('utf8'));\n } catch (err) {\n console.error(`Error: Cannot read or parse file \"${urlOrPath}\": ${err.message}`);\n }\n } else {\n console.error(`Error: Cannot find file \"${urlOrPath}\"`);\n }\n }\n\n let changed;\n if (data) {\n oldRepos.native.repositories[repoName].json = data;\n changed = true;\n }\n if (hash?.data) {\n oldRepos.native.repositories[repoName].hash = hash.data.hash;\n changed = true;\n }\n if (changed) {\n oldRepos.from = `system.host.${tools.getHostName()}.cli`;\n oldRepos.ts = Date.now();\n await this.objects.setObject(SYSTEM_REPOSITORIES_ID, oldRepos);\n }\n\n return oldRepos.native.repositories[repoName].json;\n }\n\n /**\n * Show repo on CLI\n *\n * @param repoUrl url of the repository\n * @param flags CLI flags\n */\n async showRepo(repoUrl: string | string[], flags: RepoFlags): Promise<void> {\n // Get the repositories\n const systemConfig = await this.objects.getObject(SYSTEM_CONFIG_ID);\n const systemRepos = await this.objects.getObject(SYSTEM_REPOSITORIES_ID);\n if (!systemConfig) {\n console.error(`Error: Object \"${SYSTEM_CONFIG_ID}\" not found`);\n } else if (!systemRepos) {\n console.error(`Error: Object \"${SYSTEM_REPOSITORIES_ID}\" not found`);\n } else if (!systemRepos.native || !systemRepos.native.repositories) {\n console.error(`Error: no repositories found in the \"${SYSTEM_REPOSITORIES_ID}\"`);\n } else {\n repoUrl = repoUrl || systemConfig.common.activeRepo;\n\n if (!Array.isArray(repoUrl)) {\n repoUrl = [repoUrl];\n }\n\n console.log(`Used ${repoUrl.length > 1 ? 'repositories' : 'repository'}: ${repoUrl.join(', ')}`);\n\n const allSources = {};\n\n for (const url of repoUrl) {\n const repo = systemRepos.native.repositories[url];\n // If known repository\n if (repo) {\n if (typeof repo === 'string') {\n systemRepos.native.repositories[url] = {\n link: repo,\n json: null,\n hash: '',\n };\n }\n\n const sources = await this.updateRepo(url, flags.force || flags.f, systemConfig, systemRepos);\n sources && Object.assign(allSources, sources);\n } else {\n console.error(\n `Error: unknown repository is active - \"${url}\". Known: ${Object.keys(\n systemRepos.native.repositories,\n ).join(', ')}`,\n );\n }\n }\n\n try {\n // update variables of every admin instance\n await this.updateInfo(allSources);\n } catch {\n // not important if fails\n }\n\n return this.showRepoResult(allSources, flags);\n }\n }\n\n /**\n * Show the repo result on CLI\n *\n * @param sources Repo JSON sources\n * @param flags CLI flags\n */\n private async showRepoResult(sources: Record<string, any>, flags: RepoFlags): Promise<void> {\n const installed = tools.getInstalledInfo();\n const adapters = Object.keys(sources).sort();\n\n for (const name of adapters) {\n let updatable = false;\n let text = sources[name].controller ? 'Controller ' : 'Adapter ';\n text += `\"${name}\"`;\n text = text.padEnd(11 + 15);\n\n if (sources[name].version) {\n text += `: ${sources[name].version}`;\n }\n text = text.padEnd(11 + 15 + 11);\n\n if (!(flags.all || flags.a) && !installed[name]) {\n continue;\n }\n\n if (installed[name]?.version) {\n text += `, installed ${installed[name].version}`;\n try {\n // tools.upToDate can throw if a version is invalid\n if (\n sources[name].version !== installed[name].version &&\n sources[name].version &&\n !tools.upToDate(sources[name].version, installed[name].version)\n ) {\n updatable = true;\n text = text.padEnd(11 + 15 + 11 + 18);\n const isIgnored = await isVersionIgnored({\n adapterName: name,\n objects: this.objects,\n version: sources[name].version,\n });\n\n text += isIgnored ? ' [Ignored]' : ' [Updatable]';\n }\n } catch (e) {\n console.error(`Cannot determine update info of \"${name}\": ${e.message}`);\n }\n }\n if ((flags.updatable || flags.u) && !updatable) {\n continue;\n }\n console.log(text);\n }\n }\n\n /**\n * Update Admin info states with number of updates\n *\n * @param sources the repository object\n */\n private async updateInfo(sources: Record<string, any>): Promise<void> {\n const installed = tools.getInstalledInfo();\n const list: string[] = [];\n\n for (const name of Object.keys(sources)) {\n if (installed[name] && installed[name].version && sources[name].version) {\n try {\n // tools.upToDate can throw if a version is invalid\n if (\n sources[name].version !== installed[name].version &&\n !tools.upToDate(sources[name].version, installed[name].version)\n ) {\n // remove the first part of the name\n const n = name.indexOf('.');\n list.push(n === -1 ? name : name.substring(n + 1));\n }\n } catch (e) {\n console.error(`Cannot determine update info of \"${name}\": ${e.message}`);\n }\n }\n }\n\n const objs = await this.objects.getObjectViewAsync('system', 'instance', {\n startkey: 'system.adapter.admin',\n endkey: 'system.adapter.admin\\u9999',\n });\n\n if (objs?.rows?.length) {\n const listStr = list.join(', ');\n for (const row of objs.rows) {\n if (row?.value?.type === 'instance') {\n await this.states.setState(`${row.id}.info.updatesNumber`, { val: list.length, ack: true });\n await this.states.setState(`${row.id}.info.updatesList`, { val: listStr, ack: true });\n }\n }\n }\n }\n\n /**\n * Show the current status of Repo on CLI\n */\n async showRepoStatus(): Promise<number> {\n try {\n const obj = await this.objects.getObject(SYSTEM_REPOSITORIES_ID);\n const objCfg = await this.objects.getObject(SYSTEM_CONFIG_ID);\n\n if (!obj) {\n console.error('List is empty');\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n } else if (obj.native.repositories) {\n console.table(\n Object.entries(obj.native.repositories).map(([key, value]) => {\n return {\n name: key,\n url: value.link,\n 'auto upgrade': objCfg?.common.adapterAutoUpgrade?.repositories[key] ?? false,\n };\n }),\n );\n\n if (objCfg?.common) {\n let activeRepo = objCfg.common.activeRepo;\n if (typeof activeRepo === 'string') {\n activeRepo = [activeRepo];\n }\n console.log(`\\nActive repo(s): ${activeRepo.join(', ')}`);\n console.log(`Upgrade policy: ${objCfg.common.adapterAutoUpgrade?.defaultPolicy ?? 'none'}`);\n }\n } else {\n console.error('List is empty');\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n }\n } catch (err) {\n console.error(`Cannot get list: ${err}`);\n }\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n }\n\n /**\n * Add new repo\n *\n * @param repoName name of new repo\n * @param repoUrl url of new repo\n */\n async add(repoName: string, repoUrl: string): Promise<void> {\n const sysRepoObj = await this.objects.getObject(SYSTEM_REPOSITORIES_ID);\n const obj = sysRepoObj || this.defaultSystemRepo;\n\n if (obj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" yet exists: ${obj.native.repositories[repoName].link}`);\n } else {\n if (isIntegerLikeInput(repoName)) {\n throw new Error(\n `Invalid name \"${repoName}\"! A repository name is not allowed to contain only numbers.`,\n );\n }\n\n obj.native.repositories[repoName] = {\n link: repoUrl,\n json: null,\n };\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n await this.objects.setObject(SYSTEM_REPOSITORIES_ID, obj);\n }\n }\n\n /**\n * Remove repository from sources\n *\n * @param repoName name of repository to remove\n */\n async del(repoName: string): Promise<void> {\n const obj = await this.objects.getObject(SYSTEM_CONFIG_ID);\n if (\n (obj?.common.activeRepo &&\n typeof obj.common.activeRepo === 'string' &&\n obj.common.activeRepo === repoName) ||\n (obj?.common.activeRepo && Array.isArray(obj.common.activeRepo) && obj.common.activeRepo.includes(repoName))\n ) {\n throw new Error(`Cannot delete active repository: ${repoName}`);\n } else {\n const repoObj = await this.objects.getObject(SYSTEM_REPOSITORIES_ID);\n if (repoObj) {\n if (!repoObj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" not found.`);\n } else {\n delete repoObj.native.repositories[repoName];\n repoObj.from = `system.host.${tools.getHostName()}.cli`;\n repoObj.ts = Date.now();\n await this.objects.setObject(SYSTEM_REPOSITORIES_ID, repoObj);\n }\n }\n }\n }\n\n /**\n * Checks if stable repo is active\n *\n * @param options the system config object and the repository object\n */\n private getRepoActiveInfo(options: RepoActiveOptions): RepoActiveInfo {\n const { repoObj, sysConfObj, url } = options;\n\n const name = sysConfObj.common.activeRepo.find(\n activeRepo => repoObj.native.repositories[activeRepo].link === url,\n );\n\n return name ? { isActive: true, name } : { isActive: false };\n }\n\n /**\n * Set specific repo as active one\n *\n * @param repoName name of the repository to activate\n */\n async setActive(repoName: string): Promise<void> {\n const sysRepoObj = await this.objects.getObject(SYSTEM_REPOSITORIES_ID);\n const obj = sysRepoObj || this.defaultSystemRepo;\n\n if (!obj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" not found.`);\n }\n\n const confObj = await this.objects.getObject(SYSTEM_CONFIG_ID);\n if (typeof confObj?.common.activeRepo === 'string') {\n confObj.common.activeRepo = [confObj.common.activeRepo];\n }\n\n if (!confObj || confObj.common.activeRepo.includes(repoName)) {\n return;\n }\n\n confObj.common.activeRepo.push(repoName);\n\n const stableInfo = this.getRepoActiveInfo({\n url: STABLE_REPO_URL,\n sysConfObj: confObj,\n repoObj: obj,\n });\n\n const betaInfo = this.getRepoActiveInfo({\n url: BETA_REPO_URL,\n sysConfObj: confObj,\n repoObj: obj,\n });\n\n if (stableInfo.isActive && betaInfo.isActive) {\n const posStable = confObj.common.activeRepo.indexOf(stableInfo.name);\n const posBeta = confObj.common.activeRepo.indexOf(betaInfo.name);\n\n if (posStable < posBeta) {\n // put beta in front of stable, so stable will override adapters\n confObj.common.activeRepo.splice(posBeta, 1);\n confObj.common.activeRepo.splice(posStable, 0, betaInfo.name);\n console.info(\n `Ensured that stable repository \"${stableInfo.name}\" has priority over beta repository \"${betaInfo.name}\"`,\n );\n }\n }\n\n if (confObj.common.activeRepo.length > 1) {\n console.info('More than one repository is active. Please be sure, that this is a desired constellation!');\n }\n\n confObj.from = `system.host.${tools.getHostName()}.cli`;\n confObj.ts = Date.now();\n await this.objects.setObject(SYSTEM_CONFIG_ID, confObj);\n }\n\n /**\n * Set given repo as inactive\n *\n * @param repoName name of the repository\n */\n async setInactive(repoName: string): Promise<void> {\n const confObj = (await this.objects.getObject(SYSTEM_CONFIG_ID))!;\n if (typeof confObj?.common.activeRepo === 'string') {\n confObj.common.activeRepo = [confObj.common.activeRepo];\n }\n\n const pos = confObj.common.activeRepo.indexOf(repoName);\n if (pos !== -1) {\n confObj.common.activeRepo.splice(pos, 1);\n confObj.from = `system.host.${tools.getHostName()}.cli`;\n confObj.ts = Date.now();\n await this.objects.setObject(SYSTEM_CONFIG_ID, confObj);\n }\n }\n\n /**\n * Renames existing repository if old name and link matches, renaming will not be performed if a repo with the new name already exists\n *\n * @param oldName - name of the current repository\n * @param newName - target name\n * @param repoUrl - hyperlink of the repository\n */\n async rename(oldName: string, newName: string, repoUrl: string): Promise<void> {\n let repoObj;\n let sysConfigObj;\n try {\n sysConfigObj = await this.objects.getObject(SYSTEM_CONFIG_ID);\n repoObj = await this.objects.getObject(SYSTEM_REPOSITORIES_ID);\n } catch (err) {\n throw new Error(`Could not rename repository \"${oldName}\" to \"${newName}\": ${err.message}`);\n }\n\n if (isIntegerLikeInput(newName)) {\n throw new Error(`Invalid name \"${newName}\"! A repository name is not allowed to contain only numbers.`);\n }\n\n if (!repoObj) {\n return;\n }\n\n if (\n repoObj.native.repositories[oldName] &&\n repoObj.native.repositories[oldName].link === repoUrl &&\n !repoObj.native.repositories[newName]\n ) {\n repoObj.native.repositories[newName] = repoObj.native.repositories[oldName];\n delete repoObj.native.repositories[oldName];\n\n try {\n await this.objects.setObject(SYSTEM_REPOSITORIES_ID, repoObj);\n console.log(`Renamed repository \"${oldName} to \"${newName}\"`);\n } catch (e) {\n throw new Error(`Could not rename repository \"${oldName}\" to \"${newName}\": ${e.message}`);\n }\n\n // if we changed the name of the activeRepo, we should set newName as active repo\n if (\n sysConfigObj?.common &&\n ((typeof sysConfigObj.common.activeRepo === 'string' && sysConfigObj.common.activeRepo === oldName) ||\n (Array.isArray(sysConfigObj.common.activeRepo) && sysConfigObj.common.activeRepo.includes(oldName)))\n ) {\n if (typeof sysConfigObj.common.activeRepo === 'string') {\n sysConfigObj.common.activeRepo = [sysConfigObj.common.activeRepo];\n }\n const pos = sysConfigObj.common.activeRepo.indexOf(oldName);\n sysConfigObj.common.activeRepo.splice(pos, 1, newName);\n\n try {\n await this.objects.setObject(SYSTEM_CONFIG_ID, sysConfigObj);\n } catch (e) {\n throw new Error(`Could not set \"${newName}\" as active repository: ${e.message}`);\n }\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;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AAwB,OAAO;AAC5D,gBAAQ,IAAI,uBAAuB,OAAO,QAAQ,OAAO,GAAG;MAChE,SAAS,GAAG;AACR,cAAM,IAAI,MAAM,gCAAgC,OAAO,SAAS,OAAO,MAAM,EAAE,OAAO,EAAE;MAC5F;AAGA,UACI,cAAc,WACZ,OAAO,aAAa,OAAO,eAAe,YAAY,aAAa,OAAO,eAAe,WACtF,MAAM,QAAQ,aAAa,OAAO,UAAU,KAAK,aAAa,OAAO,WAAW,SAAS,OAAO,IACvG;AACE,YAAI,OAAO,aAAa,OAAO,eAAe,UAAU;AACpD,uBAAa,OAAO,aAAa,CAAC,aAAa,OAAO,UAAU;QACpE;AACA,cAAM,MAAM,aAAa,OAAO,WAAW,QAAQ,OAAO;AAC1D,qBAAa,OAAO,WAAW,OAAO,KAAK,GAAG,OAAO;AAErD,YAAI;AACA,gBAAM,KAAK,QAAQ,UAAU,mCAAkB,YAAY;QAC/D,SAAS,GAAG;AACR,gBAAM,IAAI,MAAM,kBAAkB,OAAO,2BAA2B,EAAE,OAAO,EAAE;QACnF;MACJ;IACJ;EACJ;;",
|
|
6
6
|
"names": ["fs", "path", "axios"]
|
|
7
7
|
}
|
|
@@ -39,5 +39,15 @@ export declare function ignoreVersion(options: IgnoreVersionOptions): Promise<vo
|
|
|
39
39
|
* @param options name of the adapter
|
|
40
40
|
*/
|
|
41
41
|
export declare function recognizeVersion(options: VersionOptions): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Check if user input is an integer
|
|
44
|
+
*
|
|
45
|
+
* @param input input string to check
|
|
46
|
+
*/
|
|
47
|
+
export declare function isIntegerLikeInput(input: string): boolean;
|
|
48
|
+
/** URL of the official stable repository */
|
|
49
|
+
export declare const STABLE_REPO_URL = "http://download.iobroker.net/sources-dist.json";
|
|
50
|
+
/** URL of the official beta repository */
|
|
51
|
+
export declare const BETA_REPO_URL = "http://download.iobroker.net/sources-dist-latest.json";
|
|
42
52
|
export {};
|
|
43
53
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -28,8 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var utils_exports = {};
|
|
30
30
|
__export(utils_exports, {
|
|
31
|
+
BETA_REPO_URL: () => BETA_REPO_URL,
|
|
32
|
+
STABLE_REPO_URL: () => STABLE_REPO_URL,
|
|
31
33
|
getRepository: () => getRepository,
|
|
32
34
|
ignoreVersion: () => ignoreVersion,
|
|
35
|
+
isIntegerLikeInput: () => isIntegerLikeInput,
|
|
33
36
|
isVersionIgnored: () => isVersionIgnored,
|
|
34
37
|
recognizeVersion: () => recognizeVersion
|
|
35
38
|
});
|
|
@@ -119,10 +122,18 @@ async function recognizeVersion(options) {
|
|
|
119
122
|
delete obj.common.ignoreVersion;
|
|
120
123
|
await objects.setObject(id, obj);
|
|
121
124
|
}
|
|
125
|
+
function isIntegerLikeInput(input) {
|
|
126
|
+
return /^\d+$/.test(input);
|
|
127
|
+
}
|
|
128
|
+
const STABLE_REPO_URL = "http://download.iobroker.net/sources-dist.json";
|
|
129
|
+
const BETA_REPO_URL = "http://download.iobroker.net/sources-dist-latest.json";
|
|
122
130
|
// Annotate the CommonJS export names for ESM import in node:
|
|
123
131
|
0 && (module.exports = {
|
|
132
|
+
BETA_REPO_URL,
|
|
133
|
+
STABLE_REPO_URL,
|
|
124
134
|
getRepository,
|
|
125
135
|
ignoreVersion,
|
|
136
|
+
isIntegerLikeInput,
|
|
126
137
|
isVersionIgnored,
|
|
127
138
|
recognizeVersion
|
|
128
139
|
});
|