@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
package/build/esm/lib/setup.js
CHANGED
|
@@ -19,7 +19,7 @@ import { CLIProcess } from '../lib/cli/cliProcess.js';
|
|
|
19
19
|
import { CLIMessage } from '../lib/cli/cliMessage.js';
|
|
20
20
|
import { CLIPlugin } from '../lib/cli/cliPlugin.js';
|
|
21
21
|
import { error as CLIError } from '../lib/cli/messages.js';
|
|
22
|
-
import { getRepository, ignoreVersion, recognizeVersion } from '../lib/setup/utils.js';
|
|
22
|
+
import { BETA_REPO_URL, getRepository, ignoreVersion, isIntegerLikeInput, recognizeVersion, STABLE_REPO_URL, } from '../lib/setup/utils.js';
|
|
23
23
|
import { dbConnect, dbConnectAsync, exitApplicationSave } from '../lib/setup/dbConnection.js';
|
|
24
24
|
import { IoBrokerError } from '../lib/setup/customError.js';
|
|
25
25
|
import * as url from 'node:url';
|
|
@@ -27,6 +27,7 @@ import * as events from 'node:events';
|
|
|
27
27
|
// eslint-disable-next-line unicorn/prefer-module
|
|
28
28
|
const thisDir = url.fileURLToPath(new URL('.', import.meta.url || `file://${__filename}`));
|
|
29
29
|
import { createRequire } from 'node:module';
|
|
30
|
+
import { SYSTEM_CONFIG_ID, SYSTEM_REPOSITORIES_ID } from '@iobroker/js-controller-common-db/constants';
|
|
30
31
|
// eslint-disable-next-line unicorn/prefer-module
|
|
31
32
|
const require = createRequire(import.meta.url || `file://${__filename}`);
|
|
32
33
|
tools.ensureDNSOrder();
|
|
@@ -329,10 +330,10 @@ function initYargs() {
|
|
|
329
330
|
.command('all', 'Show entire config')
|
|
330
331
|
.command('<adapter>[.<instance>]', 'Status of a specified adapter instance');
|
|
331
332
|
})
|
|
332
|
-
.command('repo
|
|
333
|
+
.command('repo', 'Show repo information', yargs => {
|
|
333
334
|
yargs
|
|
334
|
-
.command('set <name>', 'Set active repository')
|
|
335
|
-
.command('del <name>', 'Remove repository')
|
|
335
|
+
.command('set <name>|<index>', 'Set active repository')
|
|
336
|
+
.command('del <name>|<index>', 'Remove repository')
|
|
336
337
|
.command('add <name> <url>', 'Add repository')
|
|
337
338
|
.command('addset <name> <url>', 'Add repository and set it as active one')
|
|
338
339
|
.command('show', 'List repositories');
|
|
@@ -560,8 +561,8 @@ async function processCommand(command, args, params, callback) {
|
|
|
560
561
|
const { Repo } = await import('./setup/setupRepo.js');
|
|
561
562
|
const repo = new Repo({ objects, states });
|
|
562
563
|
try {
|
|
563
|
-
await repo.rename('default', 'stable',
|
|
564
|
-
await repo.rename('latest', 'beta',
|
|
564
|
+
await repo.rename('default', 'stable', STABLE_REPO_URL);
|
|
565
|
+
await repo.rename('latest', 'beta', BETA_REPO_URL);
|
|
565
566
|
}
|
|
566
567
|
catch (err) {
|
|
567
568
|
console.warn(`Cannot rename: ${err.message}`);
|
|
@@ -2240,7 +2241,7 @@ async function processCommand(command, args, params, callback) {
|
|
|
2240
2241
|
}
|
|
2241
2242
|
case 'repo': {
|
|
2242
2243
|
let repoUrlOrCommand = args[0]; // Repo url or name or "add" / "del" / "set" / "show" / "addset" / "unset"
|
|
2243
|
-
|
|
2244
|
+
let repoName = args[1]; // Repo url or name
|
|
2244
2245
|
let repoUrl = args[2]; // Repo url or name
|
|
2245
2246
|
if (repoUrlOrCommand !== 'add' &&
|
|
2246
2247
|
repoUrlOrCommand !== 'del' &&
|
|
@@ -2251,95 +2252,103 @@ async function processCommand(command, args, params, callback) {
|
|
|
2251
2252
|
repoUrl = repoUrlOrCommand;
|
|
2252
2253
|
repoUrlOrCommand = 'show';
|
|
2253
2254
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2255
|
+
const { objects, states } = await dbConnectAsync(false, params);
|
|
2256
|
+
const { Repo } = await import('./setup/setupRepo.js');
|
|
2257
|
+
const repo = new Repo({
|
|
2258
|
+
objects,
|
|
2259
|
+
states,
|
|
2260
|
+
});
|
|
2261
|
+
if (repoUrlOrCommand === 'show') {
|
|
2262
|
+
try {
|
|
2263
|
+
await repo.showRepoStatus();
|
|
2264
|
+
return void callback();
|
|
2265
|
+
}
|
|
2266
|
+
catch (e) {
|
|
2267
|
+
console.error(`Cannot show repository status: ${e.message}`);
|
|
2268
|
+
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
if (repoUrlOrCommand === 'add' ||
|
|
2272
|
+
repoUrlOrCommand === 'del' ||
|
|
2273
|
+
repoUrlOrCommand === 'set' ||
|
|
2274
|
+
repoUrlOrCommand === 'addset' ||
|
|
2275
|
+
repoUrlOrCommand === 'unset') {
|
|
2276
|
+
if (!repoName || !repoName.match(/[-_\w]+/)) {
|
|
2277
|
+
console.error(`Invalid repository name: "${repoName}"`);
|
|
2278
|
+
return void callback(EXIT_CODES.INVALID_ARGUMENTS);
|
|
2279
|
+
}
|
|
2280
|
+
if (isIntegerLikeInput(repoName)) {
|
|
2261
2281
|
try {
|
|
2282
|
+
repoName = await repo.getNameByIndex(parseInt(repoName));
|
|
2283
|
+
}
|
|
2284
|
+
catch (e) {
|
|
2285
|
+
console.error(e.message);
|
|
2286
|
+
return void callback(EXIT_CODES.INVALID_ARGUMENTS);
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
if (repoUrlOrCommand === 'add' || repoUrlOrCommand === 'addset') {
|
|
2290
|
+
if (!repoUrl) {
|
|
2291
|
+
console.warn(`Please define repository URL or path: ${tools.appName.toLowerCase()} add <repoName> <repoUrlOrPath>`);
|
|
2292
|
+
return void callback(EXIT_CODES.INVALID_ARGUMENTS);
|
|
2293
|
+
}
|
|
2294
|
+
try {
|
|
2295
|
+
await repo.add(repoName, repoUrl);
|
|
2296
|
+
if (repoUrlOrCommand === 'addset') {
|
|
2297
|
+
await repo.setActive(repoName);
|
|
2298
|
+
console.log(`Repository "${repoName}" set as active: "${repoUrl}"`);
|
|
2299
|
+
await repo.showRepoStatus();
|
|
2300
|
+
return void callback();
|
|
2301
|
+
}
|
|
2302
|
+
console.log(`Repository "${repoName}" added as "${repoUrl}"`);
|
|
2262
2303
|
await repo.showRepoStatus();
|
|
2263
2304
|
return void callback();
|
|
2264
2305
|
}
|
|
2265
|
-
catch (
|
|
2266
|
-
console.error(`Cannot
|
|
2306
|
+
catch (e) {
|
|
2307
|
+
console.error(`Cannot add repository location: ${e.message}`);
|
|
2267
2308
|
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2268
2309
|
}
|
|
2269
2310
|
}
|
|
2270
|
-
else if (repoUrlOrCommand === '
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
if (!repoName || !repoName.match(/[-_\w\d]+/)) {
|
|
2276
|
-
console.error(`Invalid repository name: "${repoName}"`);
|
|
2311
|
+
else if (repoUrlOrCommand === 'set') {
|
|
2312
|
+
try {
|
|
2313
|
+
await repo.setActive(repoName);
|
|
2314
|
+
console.log(`Repository "${repoName}" set as active.`);
|
|
2315
|
+
await repo.showRepoStatus();
|
|
2277
2316
|
return void callback();
|
|
2278
2317
|
}
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
return void callback(EXIT_CODES.INVALID_ARGUMENTS);
|
|
2283
|
-
}
|
|
2284
|
-
try {
|
|
2285
|
-
await repo.add(repoName, repoUrl);
|
|
2286
|
-
if (repoUrlOrCommand === 'addset') {
|
|
2287
|
-
await repo.setActive(repoName);
|
|
2288
|
-
console.log(`Repository "${repoName}" set as active: "${repoUrl}"`);
|
|
2289
|
-
await repo.showRepoStatus();
|
|
2290
|
-
return void callback();
|
|
2291
|
-
}
|
|
2292
|
-
console.log(`Repository "${repoName}" added as "${repoUrl}"`);
|
|
2293
|
-
await repo.showRepoStatus();
|
|
2294
|
-
return void callback();
|
|
2295
|
-
}
|
|
2296
|
-
catch (err) {
|
|
2297
|
-
console.error(`Cannot add repository location: ${err.message}`);
|
|
2298
|
-
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2299
|
-
}
|
|
2318
|
+
catch (e) {
|
|
2319
|
+
console.error(`Cannot activate repository: ${e.message}`);
|
|
2320
|
+
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2300
2321
|
}
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
catch (err) {
|
|
2309
|
-
console.error(`Cannot activate repository: ${err.message}`);
|
|
2310
|
-
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2311
|
-
}
|
|
2322
|
+
}
|
|
2323
|
+
else if (repoUrlOrCommand === 'del') {
|
|
2324
|
+
try {
|
|
2325
|
+
await repo.del(repoName);
|
|
2326
|
+
console.log(`Repository "${repoName}" deleted.`);
|
|
2327
|
+
await repo.showRepoStatus();
|
|
2328
|
+
return void callback();
|
|
2312
2329
|
}
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
console.log(`Repository "${repoName}" deleted.`);
|
|
2317
|
-
await repo.showRepoStatus();
|
|
2318
|
-
return void callback();
|
|
2319
|
-
}
|
|
2320
|
-
catch (err) {
|
|
2321
|
-
console.error(`Cannot remove repository: ${err.message}`);
|
|
2322
|
-
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2323
|
-
}
|
|
2330
|
+
catch (e) {
|
|
2331
|
+
console.error(`Cannot remove repository: ${e.message}`);
|
|
2332
|
+
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2324
2333
|
}
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
catch (err) {
|
|
2333
|
-
console.error(`Cannot deactivate repository: ${err.message}`);
|
|
2334
|
-
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2335
|
-
}
|
|
2334
|
+
}
|
|
2335
|
+
else if (repoUrlOrCommand === 'unset') {
|
|
2336
|
+
try {
|
|
2337
|
+
await repo.setInactive(repoName);
|
|
2338
|
+
console.log(`Repository "${repoName}" deactivated.`);
|
|
2339
|
+
await repo.showRepoStatus();
|
|
2340
|
+
return void callback();
|
|
2336
2341
|
}
|
|
2337
|
-
|
|
2338
|
-
console.
|
|
2339
|
-
return void callback(EXIT_CODES.
|
|
2342
|
+
catch (e) {
|
|
2343
|
+
console.error(`Cannot deactivate repository: ${e.message}`);
|
|
2344
|
+
return void callback(EXIT_CODES.INVALID_REPO);
|
|
2340
2345
|
}
|
|
2341
2346
|
}
|
|
2342
|
-
|
|
2347
|
+
else {
|
|
2348
|
+
console.warn(`Unknown repo command: ${repoUrlOrCommand}`);
|
|
2349
|
+
return void callback(EXIT_CODES.INVALID_ARGUMENTS);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2343
2352
|
break;
|
|
2344
2353
|
}
|
|
2345
2354
|
case 'multihost':
|
|
@@ -2503,10 +2512,10 @@ const OBJECTS_THAT_CANNOT_BE_DELETED = [
|
|
|
2503
2512
|
'alias.0',
|
|
2504
2513
|
'enum.functions',
|
|
2505
2514
|
'enum.rooms',
|
|
2506
|
-
|
|
2515
|
+
SYSTEM_CONFIG_ID,
|
|
2507
2516
|
'system.group.administrator',
|
|
2508
2517
|
'system.group.user',
|
|
2509
|
-
|
|
2518
|
+
SYSTEM_REPOSITORIES_ID,
|
|
2510
2519
|
'system.user.admin',
|
|
2511
2520
|
];
|
|
2512
2521
|
/**
|
|
@@ -2578,40 +2587,39 @@ async function cleanDatabase(isDeleteDb) {
|
|
|
2578
2587
|
const keysCount = await delStates();
|
|
2579
2588
|
return keysCount;
|
|
2580
2589
|
}
|
|
2581
|
-
function unsetup(params, callback) {
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2590
|
+
async function unsetup(params, callback) {
|
|
2591
|
+
const { objects } = await dbConnectAsync(false, params);
|
|
2592
|
+
objects.delObject('system.meta.uuid', err => {
|
|
2593
|
+
if (err) {
|
|
2594
|
+
console.log(`uuid cannot be deleted: ${err.message}`);
|
|
2595
|
+
}
|
|
2596
|
+
else {
|
|
2597
|
+
console.log('system.meta.uuid deleted');
|
|
2598
|
+
}
|
|
2599
|
+
objects.getObject(SYSTEM_CONFIG_ID, (_err, obj) => {
|
|
2600
|
+
if (obj?.common.licenseConfirmed || obj?.common.language || obj?.native?.secret) {
|
|
2601
|
+
obj.common.language = 'en';
|
|
2602
|
+
// allow with parameter --keepsecret to not delete the secret
|
|
2603
|
+
// This is very specific use case for vendors and must not be described in documentation
|
|
2604
|
+
if (!params.keepsecret) {
|
|
2605
|
+
obj.common.licenseConfirmed = false;
|
|
2606
|
+
obj.native && delete obj.native.secret;
|
|
2607
|
+
}
|
|
2608
|
+
obj.from = `system.host.${tools.getHostName()}.cli`;
|
|
2609
|
+
obj.ts = new Date().getTime();
|
|
2610
|
+
objects.setObject(SYSTEM_CONFIG_ID, obj, err => {
|
|
2611
|
+
if (err) {
|
|
2612
|
+
console.log(`not found: ${err.message}`);
|
|
2613
|
+
return void callback(EXIT_CODES.CANNOT_SET_OBJECT);
|
|
2614
|
+
}
|
|
2615
|
+
console.log(`${SYSTEM_CONFIG_ID} reset`);
|
|
2616
|
+
return void callback();
|
|
2617
|
+
});
|
|
2586
2618
|
}
|
|
2587
2619
|
else {
|
|
2588
|
-
console.log(
|
|
2620
|
+
console.log(`${SYSTEM_CONFIG_ID} is OK`);
|
|
2621
|
+
return void callback();
|
|
2589
2622
|
}
|
|
2590
|
-
objects.getObject('system.config', (_err, obj) => {
|
|
2591
|
-
if (obj?.common.licenseConfirmed || obj?.common.language || obj?.native?.secret) {
|
|
2592
|
-
obj.common.language = 'en';
|
|
2593
|
-
// allow with parameter --keepsecret to not delete the secret
|
|
2594
|
-
// This is very specific use case for vendors and must not be described in documentation
|
|
2595
|
-
if (!params.keepsecret) {
|
|
2596
|
-
obj.common.licenseConfirmed = false;
|
|
2597
|
-
obj.native && delete obj.native.secret;
|
|
2598
|
-
}
|
|
2599
|
-
obj.from = `system.host.${tools.getHostName()}.cli`;
|
|
2600
|
-
obj.ts = new Date().getTime();
|
|
2601
|
-
objects.setObject('system.config', obj, err => {
|
|
2602
|
-
if (err) {
|
|
2603
|
-
console.log(`not found: ${err.message}`);
|
|
2604
|
-
return void callback(EXIT_CODES.CANNOT_SET_OBJECT);
|
|
2605
|
-
}
|
|
2606
|
-
console.log('system.config reset');
|
|
2607
|
-
return void callback();
|
|
2608
|
-
});
|
|
2609
|
-
}
|
|
2610
|
-
else {
|
|
2611
|
-
console.log('system.config is OK');
|
|
2612
|
-
return void callback();
|
|
2613
|
-
}
|
|
2614
|
-
});
|
|
2615
2623
|
});
|
|
2616
2624
|
});
|
|
2617
2625
|
}
|