Skip to content

Commit 1de5e71

Browse files
Added readme attribute to the adapter object (#2848)
* Added readme attribute to the adapter object * Comments checking --------- Co-authored-by: Max Hauser <[email protected]>
1 parent 74445d3 commit 1de5e71

File tree

4 files changed

+43
-41
lines changed

4 files changed

+43
-41
lines changed

packages/cli/src/lib/setup/setupInstall.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Install adapter
33
*
4-
* Copyright 2013-2023 bluefox <[email protected]>
4+
* Copyright 2013-2024 bluefox <[email protected]>
55
*
66
* MIT License
77
*
@@ -187,7 +187,7 @@ export class Install {
187187
packetName = parts[0];
188188
version = parts[1];
189189
} else {
190-
// always take version from repository
190+
// always take a version from repository
191191
if (sources[packetName]?.version) {
192192
version = sources[packetName].version;
193193
} else {
@@ -272,7 +272,7 @@ export class Install {
272272
}
273273

274274
console.error(
275-
`host.${hostname} Unknown packetName ${packetName}. Please install packages from outside the repository using "${tools.appNameLowerCase} url <url-or-package>"!`
275+
`host.${hostname} Unknown packet name ${packetName}. Please install packages from outside the repository using "${tools.appNameLowerCase} url <url-or-package>"!`
276276
);
277277
throw new IoBrokerError({
278278
code: EXIT_CODES.UNKNOWN_PACKET_NAME,
@@ -359,7 +359,7 @@ export class Install {
359359
npmUrl = npmUrl.substring(0, npmUrl.indexOf('#'));
360360
}
361361
if (npmUrl.includes('/') && !npmUrl.startsWith('@')) {
362-
// only scoped packages (e.g. @types/node ) may have a slash in their path
362+
// only scoped packages (e.g., @types/node) may have a slash in their path
363363
npmUrl = npmUrl.substring(npmUrl.lastIndexOf('/') + 1);
364364
}
365365
if (!npmUrl.startsWith('@')) {
@@ -397,7 +397,7 @@ export class Install {
397397
unsafePerm: !!options.unsafePerm
398398
});
399399

400-
// code 1 is sometimes a real error and sometimes a strange error, where everything is installed but error
400+
// code 1 is sometimes a real error and sometimes a strange error, where everything is installed but still the error
401401
const isSuccess = result.success || (result.exitCode === 1 && !result.stderr.startsWith('npm ERR!'));
402402

403403
if (isSuccess) {
@@ -530,7 +530,7 @@ export class Install {
530530

531531
if (dName === 'js-controller') {
532532
const version = allDeps[dName];
533-
// Check only if version not *, else we dont have to read io-pack unnecessarily
533+
// Check only if version not *, else we don't have to read io-pack unnecessarily
534534
if (version !== '*') {
535535
const packJson = fs.readJSONSync(`${tools.getControllerDir()}/package.json`);
536536
if (!semver.satisfies(packJson.version, version, { includePrerelease: true })) {
@@ -554,7 +554,7 @@ export class Install {
554554
gInstances = objs.rows.filter(obj => obj.value.common && obj.value.common.name === dName);
555555
}
556556
if (deps[dName] !== undefined) {
557-
// local dep get all instances on same host
557+
// local dependencies: get all instances on the same host
558558
locInstances = objs.rows.filter(
559559
obj =>
560560
obj.value.common &&
@@ -566,7 +566,7 @@ export class Install {
566566
}
567567
}
568568

569-
// we check, that all existing instances match - respect different versions for local and global deps
569+
// we check that all existing instances match - respect different versions for local and global deps
570570
for (const instance of locInstances) {
571571
const instanceVersion = instance.value.common.version;
572572
if (
@@ -698,7 +698,7 @@ export class Install {
698698

699699
const { stoppedList } = await this.downloadPacket(repoUrl, fullName);
700700
await this.installAdapter(adapter, repoUrl, _installCount);
701-
await this.enableInstances(stoppedList, true); // even if unlikely make sure to reenable disabled instances
701+
await this.enableInstances(stoppedList, true); // even if unlikely make sure to re-enable disabled instances
702702
return adapter;
703703
}
704704
let adapterConf: ioBroker.AdapterObject;
@@ -1097,7 +1097,7 @@ export class Install {
10971097
.filter(row => !!row.value._id)
10981098
// ... that matches the pattern
10991099
.filter(row => instanceRegex.test(row.value._id))
1100-
// if instance given also delete from foreign host else only instance on this host
1100+
// if instance given, also delete it from foreign host else only instance on this host
11011101
.filter(row => {
11021102
if (instance !== undefined || !row.value.common?.host || row.value.common?.host === hostname) {
11031103
return true;
@@ -1471,14 +1471,14 @@ export class Install {
14711471

14721472
while (stateIDs.length > 0) {
14731473
if (stateIDs.length % 200 === 0) {
1474-
// write progress report
1474+
// write a progress report
14751475
console.log(`host.${hostname}: Only ${stateIDs.length} states left to be deleted.`);
14761476
}
14771477
// try to delete the current state
14781478
try {
14791479
await this.states.delState(stateIDs.pop()!);
14801480
} catch (e) {
1481-
// yep that works!
1481+
// yep, that works!
14821482
e !== tools.ERRORS.ERROR_NOT_FOUND &&
14831483
e.message !== tools.ERRORS.ERROR_NOT_FOUND &&
14841484
console.error(`host.${hostname} Cannot delete states: ${e.message}`);
@@ -1506,7 +1506,7 @@ export class Install {
15061506

15071507
while (objIDs.length > 0) {
15081508
if (objIDs.length % 200 === 0) {
1509-
// write progress report
1509+
// write a progress report
15101510
console.log(`host.${hostname}: Only ${objIDs.length} objects left to be deleted.`);
15111511
}
15121512
// try to delete the current object
@@ -1543,7 +1543,7 @@ export class Install {
15431543

15441544
if (!ioPack.common || !ioPack.common.nondeletable) {
15451545
await this._npmUninstall(adapterNpm, false);
1546-
// after uninstalling we have to restart the defined adapters
1546+
// after uninstalling, we have to restart the defined adapters
15471547
if (ioPack.common.restartAdapters) {
15481548
if (!Array.isArray(ioPack.common.restartAdapters)) {
15491549
// it's not an array, now it can only be a single adapter as string
@@ -1602,7 +1602,7 @@ export class Install {
16021602
await this._removeCustomFromObjects([adapter]);
16031603
await _uninstallNpm();
16041604
} else {
1605-
// we are not allowed to delete last instance if another instance depends on us
1605+
// we are not allowed to delete the last instance if another instance depends on us
16061606
const dependentInstance = await this._hasDependentInstances(adapter);
16071607

16081608
if (dependentInstance) {
@@ -1649,7 +1649,7 @@ export class Install {
16491649
const knownObjectIDs: string[] = [];
16501650
const knownStateIDs: string[] = [];
16511651

1652-
// we are not allowed to delete last instance if another instance depends on us
1652+
// we are not allowed to delete the last instance if another instance depends on us
16531653
const dependentInstance = await this._hasDependentInstances(adapter, instance);
16541654

16551655
if (dependentInstance) {
@@ -1677,7 +1677,7 @@ export class Install {
16771677
}
16781678

16791679
/**
1680-
* Remove all node modules which has been installed by this instance
1680+
* Remove all node modules that has been installed by this instance
16811681
*
16821682
* @param adapter adapter name like hm-rpc
16831683
* @param instance e.g. 1, if undefined deletes all instances
@@ -1703,7 +1703,7 @@ export class Install {
17031703
* @param ids - id of the adapter/instance to check for
17041704
*/
17051705
private async _removeCustomFromObjects(ids: string[]): Promise<void> {
1706-
// get all objects which have a custom attribute
1706+
// get all objects that have a custom attribute
17071707
const res = await this.objects.getObjectViewAsync('system', 'custom', {
17081708
startkey: '',
17091709
endkey: '\u9999'
@@ -1739,7 +1739,7 @@ export class Install {
17391739
* @param name package name
17401740
*/
17411741
async installAdapterFromUrl(url: string, name: string): Promise<void> {
1742-
// If the user provided an URL, try to parse it into known ways to represent a Github URL
1742+
// If the user provided a URL, try to parse it into known ways to represent a GitHub URL
17431743
let parsedUrl;
17441744
try {
17451745
parsedUrl = new URL(url);
@@ -1764,7 +1764,7 @@ export class Install {
17641764
const result = await axios(`http://api.github.com/repos/${user}/${repo}/commits`, {
17651765
headers: {
17661766
'User-Agent': 'ioBroker Adapter install',
1767-
// @ts-expect-error should be okay..
1767+
// @ts-expect-error should be okay...
17681768
validateStatus: status => status === 200
17691769
}
17701770
});
@@ -1793,14 +1793,14 @@ export class Install {
17931793

17941794
// Try to extract name from URL
17951795
if (!name) {
1796-
const reNpmPacket = new RegExp('^' + tools.appName + '\\.([-_\\w\\d]+)(@.*)?$', 'i');
1796+
const reNpmPacket = new RegExp(`^${tools.appName}\\.([-_\\w\\d]+)(@.*)?$`, 'i');
17971797
const match = reNpmPacket.exec(url); // we have [email protected]
17981798
if (match) {
17991799
name = match[1];
18001800
} else if (url.match(/\.(tgz|gz|zip|tar\.gz)$/)) {
18011801
const parts = url.split('/');
18021802
const last = parts.pop()!;
1803-
const mm = last.match(/\.([-_\w\d]+)-[.\d]+/);
1803+
const mm = last.match(/\.([-_\w]+)-[.\d]+/);
18041804
if (mm) {
18051805
name = mm[1];
18061806
}
@@ -1814,7 +1814,7 @@ export class Install {
18141814
name = url;
18151815
}
18161816
// Remove the leading `iobroker.` from the name
1817-
const reG = new RegExp(tools.appName + '\\.([-_\\w\\d]+)$', 'i');
1817+
const reG = new RegExp(`${tools.appName}\\.([-_\\w\\d]+)$`, 'i');
18181818
const match = reG.exec(name);
18191819
if (match) {
18201820
name = match[1];
@@ -1883,7 +1883,7 @@ export class Install {
18831883
*
18841884
* @param adapter adapter name
18851885
* @param instance instance, like 1
1886-
* @returns if dependent exists returns adapter name
1886+
* @returns if dependent exists, returns adapter name
18871887
*/
18881888
private async _hasDependentInstances(adapter: string, instance?: number): Promise<void | string> {
18891889
try {
@@ -1907,7 +1907,7 @@ export class Install {
19071907

19081908
for (const row of doc.rows) {
19091909
if (!row.value?.common) {
1910-
// this object seems to be corrupted so it will not need our adapter
1910+
// this object seems to be corrupted, so it will not need our adapter
19111911
continue;
19121912
}
19131913

@@ -1919,7 +1919,7 @@ export class Install {
19191919
// this adapter needs us locally and all instances should be deleted
19201920
return `${row.value.common.name}.${row.id.split('.').pop()}`;
19211921
} else {
1922-
// check if other instance of us exists on this host
1922+
// check if another instance of us exists on this host
19231923
if (this._checkDependencyFulfilledThisHost(adapter, instance, doc.rows, scopedHostname)) {
19241924
// there are other instances of our adapter - ok
19251925
break;
@@ -1935,7 +1935,7 @@ export class Install {
19351935
for (const globalDep of Object.keys(globalDeps)) {
19361936
if (globalDep === adapter) {
19371937
if (instance === undefined) {
1938-
// all instances on this host should be removed so check if there are some on other hosts
1938+
// all instances on this host should be removed, so check if there are some on other hosts
19391939
if (this._checkDependencyFulfilledForeignHosts(adapter, doc.rows, scopedHostname)) {
19401940
break;
19411941
} else {
@@ -1964,7 +1964,7 @@ export class Install {
19641964
* @param adapter adapter name
19651965
* @param instancesRows all instances objects view rows
19661966
* @param scopedHostname hostname which should be assumed as local
1967-
* @returns true if an instance is present on other host
1967+
* @returns true if an instance is present on another host
19681968
*/
19691969
private _checkDependencyFulfilledForeignHosts(
19701970
adapter: string,

packages/cli/src/lib/setup/setupUpgrade.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ export class Upgrade {
8181

8282
while (relevantAdapters.length) {
8383
let oneAdapterAdded = false;
84-
// create ordered list for upgrades
84+
// create an ordered list for upgrades
8585
for (let i = relevantAdapters.length - 1; i >= 0; i--) {
8686
const relAdapter = relevantAdapters[i];
87-
// if new version has no dependencies we can upgrade
87+
// if a new version has no dependencies, we can upgrade
8888
if (!repo[relAdapter].dependencies && !repo[relAdapter].globalDependencies) {
8989
// no deps, simply add it
9090
sortedAdapters.push(relAdapter);
@@ -101,7 +101,7 @@ export class Upgrade {
101101
for (const [depName, version] of Object.entries(allDeps)) {
102102
debug(`adapter "${relAdapter}" has dependency "${depName}": "${version}"`);
103103
if (version !== '*') {
104-
// dependency is important, because it affects version range
104+
// dependency is important because it affects the version range
105105
if (relevantAdapters.includes(depName)) {
106106
// the dependency is also in the upgrade list and not previously added, we should add the dependency first
107107
debug(`conflict for dependency "${depName}" at adapter "${relAdapter}"`);
@@ -110,7 +110,7 @@ export class Upgrade {
110110
}
111111
}
112112
}
113-
// we reached here and no conflict so every dep is satisfied
113+
// we reached here and no conflict, so every dep is satisfied
114114
if (!conflict) {
115115
sortedAdapters.push(relAdapter);
116116
relevantAdapters.splice(relevantAdapters.indexOf(relAdapter), 1);
@@ -204,7 +204,7 @@ export class Upgrade {
204204
gInstances = objs.rows.filter(obj => obj.value.common && obj.value.common.name === dName);
205205
}
206206
if (deps[dName] !== undefined) {
207-
// local dep get all instances on same host
207+
// local dependencies: get all instances on the same host
208208
locInstances = objs.rows.filter(
209209
obj =>
210210
obj.value.common &&
@@ -217,7 +217,7 @@ export class Upgrade {
217217
}
218218

219219
let isFound = false;
220-
// we check, that all instances match - respect different local and global dep versions
220+
// we check that all instances match - respect different local and global dep versions
221221
for (const instance of locInstances) {
222222
const instanceVersion = instance.value.common.version;
223223
try {
@@ -277,9 +277,9 @@ export class Upgrade {
277277
}
278278

279279
/**
280-
* Try to async upgrade adapter from given source with some checks
280+
* Try to async upgrade adapter from a given source with some checks
281281
*
282-
* @param repoUrlOrObject url of the selected repository or parsed repo, if undefined use current active repository
282+
* @param repoUrlOrObject url of the selected repository or parsed repo, if undefined, use current active repository
283283
* @param adapter name of the adapter (can also include version like [email protected])
284284
* @param forceDowngrade flag to force downgrade
285285
* @param autoConfirm automatically confirm the tty questions (bypass)
@@ -353,7 +353,7 @@ export class Upgrade {
353353

354354
const adapterDir = tools.getAdapterDir(adapter);
355355

356-
// Read actual description of installed adapter with version
356+
// Read the actual description of installed adapter with a version
357357
if (!adapterDir || (!version && !fs.existsSync(path.join(adapterDir, 'io-package.json')))) {
358358
return console.log(
359359
`Adapter "${adapter}"${
@@ -395,7 +395,7 @@ export class Upgrade {
395395
const isMajor = semver.major(installedVersion) !== semver.major(targetVersion);
396396

397397
if (autoConfirm || (!tty.isatty(process.stdout.fd) && (!isMajor || !upgradeAll))) {
398-
// force flag or script on non major or single adapter upgrade -> always upgrade
398+
// force flag or script on non-major or single adapter upgrade -> always upgrade
399399
return true;
400400
}
401401

@@ -512,7 +512,7 @@ export class Upgrade {
512512
return true;
513513
};
514514

515-
// If version is included in repository
515+
// If a version is included in the repository
516516
if (repoAdapter.version) {
517517
if (!forceDowngrade) {
518518
try {
@@ -604,7 +604,7 @@ export class Upgrade {
604604
} is up to date.`
605605
);
606606
} else {
607-
// Get the adapter from web site
607+
// Get the adapter from website
608608
const targetVersion = version || ioPack.common.version;
609609

610610
const isIgnored = await isVersionIgnored({

packages/cli/src/lib/setup/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface GetRepositoryOptions {
1212
}
1313

1414
/**
15-
* Get json of the given repository
15+
* Get JSON of the given repository
1616
*
1717
* @param options Repository specific options
1818
*/

packages/types-dev/objects.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ declare global {
702702
platform: 'Javascript/Node.js';
703703
/** The keys of common attributes (e.g. `history`) which are not deleted in a `setObject` call even if they are not present. Deletion must be done explicitly by setting them to `null`. */
704704
preserveSettings?: string | string[];
705+
/** Url of the ReadMe file */
706+
readme?: string;
705707
/** Which adapters must be restarted after installing or updating this adapter. */
706708
restartAdapters?: string[];
707709
/** CRON schedule to restart mode `daemon` adapters */

0 commit comments

Comments
 (0)