@iobroker/repochecker 2.2.3 → 2.3.1

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/README.md CHANGED
@@ -20,14 +20,23 @@ Branch (`master/main/dev`) is optional.
20
20
  -->
21
21
 
22
22
  ## Changelog
23
+ ### 2.3.1 (2024-05-07)
24
+ * (mcm1957) Reduce number of missing translation warnings.
25
+ * (mcm1957) Seperate between required and recommended translations.
26
+ * (mcm1957) Log missing translations in detail.
27
+
28
+ ### 2.3.0 (2024-05-07)
29
+ * (mcm1957) Elements marked as deprectaed added to blacklist.
30
+ * (mcm1957) Blacklist added to block elements at package.json and io-package.json.
31
+ * (mcm1957) Error [E000] will be raised now if repository cannot be accessed at all [#194].
32
+ * (mcm1957) Reading of package.json and io-package.json has been moved to head of tests.
33
+ * (mcm1957) Check minimum and recommended node version at package.json (#160)
34
+ * (mcm1957) Raise an error if version at package.json is lower than latest release at npmjs [#192]
23
35
 
24
- <!--
25
- * (mcm1957) Added deprecate warnings for "main', 'materialize", "materializeTab" and "noConfig"
26
- -->
27
36
  ### 2.2.3 (2024-03-29)
28
37
  * (mcm1957) Checking of license has been improved
29
38
 
30
- ### 2.2.2 (2024-03-29)
39
+ ### 2.2.2 (2024-03-29)
31
40
  * (mcm1957) Checking of adapter-core has been fixed
32
41
  * (mcm1957) Load all potential interesting files, fixes [#149]
33
42
 
package/doc/issues.json CHANGED
@@ -1,4 +1,7 @@
1
1
  {
2
+ "E000": {
3
+ "title": "FATAL: cannot access repository ${context.githubUrlApi}"
4
+ },
2
5
  "E001": {
3
6
  "_comment": "all texts can be string or object with language translations",
4
7
  "title": {
@@ -122,9 +125,30 @@
122
125
  "E025": {
123
126
  "title": "Do not include `iobroker.js-controller` as dependency!"
124
127
  },
128
+ "E026": {
129
+ "title": "`{'engines': {'node'>='${requiredNodeVersion}'}}` is required at package.json, `{'engines':{'node'>='${recommendedNodeVersion}'}}` is recommened"
130
+ },
125
131
  "E029": {
126
132
  "title": "Node.js ${requiredNodeVersion} is required as minimum, node.js ${recommendedNodeVersion} is recommended. Please adapt `{'engines' : { 'node' >= '${match.groups.vers}' } }` at package.json."
127
133
  },
134
+ "E031": {
135
+ "title": "No devDependencies declared at package.json. Plase correct package.json"
136
+ },
137
+ "E032": {
138
+ "title": "No dependency declared for ${dependency}. Please add `${dependency}`:`${recommendedVersion}` to dependencies at package.json"
139
+ },
140
+ "E033": {
141
+ "title": "${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update dependencies at package.json"
142
+ },
143
+ "E034": {
144
+ "title": "No devDependency declared for ${dependency}. Please add `${dependency}`:`${recommendedVersion}` to devDependencies at package.json"
145
+ },
146
+ "E035": {
147
+ "title": "${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update devDependencies at package.json"
148
+ },
149
+ "E036": {
150
+ "title": "${blacklistPackageJson[blacklist].msg}"
151
+ },
128
152
  "E100": {
129
153
  "title": "Cannot parse io-package.json"
130
154
  },
@@ -308,6 +332,9 @@
308
332
  "E183": {
309
333
  "title": "`common.licenseInformation.license` is missing"
310
334
  },
335
+ "E184": {
336
+ "title": "${blacklistIOPackageJson[blacklist].msg}"
337
+ },
311
338
  "E200": {
312
339
  "title": "Not found on npm. Please publish"
313
340
  },
@@ -458,15 +485,18 @@
458
485
  "E903": {
459
486
  "title": "iob_npm.done not found in .gitignore"
460
487
  },
461
- "W026": {
462
- "title": "`{'engines' : { 'node' >= '${recommendedNodeVersion}' } }` is required at package.json"
463
- },
464
488
  "W027": {
465
489
  "title": "{'engines' : { 'node' : '${nodeVal}' } }` is not parseable."
466
490
  },
467
491
  "W028": {
468
492
  "title": "Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt `{'engines' : { 'node' >= '${match.groups.vers}' } }` at package.json."
469
493
  },
494
+ "W030": {
495
+ "title": "No dependencies declared at package.json. Is this really correct?"
496
+ },
497
+ "W036": {
498
+ "title": "${blacklistPackageJson[blacklist].msg}"
499
+ },
470
500
  "W105": {
471
501
  "title": "`common.titleLang` should be translated into all supported languages"
472
502
  },
@@ -500,9 +530,6 @@
500
530
  "W172": {
501
531
  "title": "`common.localLink` in io-package.json is deprecated. Please define object `common.localLinks`: { `_default`: `...` }"
502
532
  },
503
- "W173": {
504
- "title": "`@iobroker/adapter-core` (${context.packageJson.dependencies['@iobroker/adapter-core']}) should be ${recommendedAdapterCoreVersion} or newer - please update"
505
- },
506
533
  "W174": {
507
534
  "title": "`common.wakeup` is deprectaed. Please remove from io-package.json"
508
535
  },
@@ -521,6 +548,9 @@
521
548
  "W181": {
522
549
  "title": "`common.license` in io-package.json is deprecated. Please define object `common.licenseInformation`"
523
550
  },
551
+ "W184": {
552
+ "title": "${blacklistIOPackageJson[blacklist].msg}"
553
+ },
524
554
  "W302": {
525
555
  "title": "Use github actions instead of travis-ci"
526
556
  },
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  /*
4
3
 
5
4
  ___ _ _ _____ _ _
@@ -30,6 +29,63 @@ const recommendedJsControllerVersion = '5.0.11';
30
29
  const recommendedNodeVersion = '18';
31
30
  const requiredNodeVersion = '16';
32
31
 
32
+ const dependencies = {
33
+ "@iobroker/adapter-core": {
34
+ "required":"3.1.4",
35
+ "recommended":"3.1.4"
36
+ }
37
+ };
38
+
39
+ const devDependencies = {
40
+ "@iobroker/testing": {
41
+ "required":"4.1.3",
42
+ "recommended":"4.1.3"
43
+ }
44
+ };
45
+
46
+ const blacklistPackageJson = {
47
+
48
+ };
49
+
50
+ const blacklistIOPackageJson = {
51
+ "installedFrom": {
52
+ "msg": "\"installedFrom\" is invalid at io-package.json. Please remove.",
53
+ "err": true
54
+ },
55
+ "common.installedFrom": {
56
+ "msg": "\"common.installedFrom\" is invalid. Please remove from io-package.json.",
57
+ "err": true
58
+ },
59
+ "common.title": {
60
+ "msg": "\"common.title\" is deprecated and replaced by \"common.titleLang\". Please remove from io-package.json.",
61
+ "err": false
62
+ },
63
+ "common.main": {
64
+ "msg": "\"common.main\" is deprecated and ignored. Please remove from io-package.json. Use \"main\" at package.json instead.",
65
+ "err": false
66
+ },
67
+ "common.materialize": {
68
+ "msg": "\"common.materialize\" is deprecated for admin >= 5 at io-package.json. Please use property \"adminUI\".",
69
+ "err": false
70
+ },
71
+ "common.materializeTab": {
72
+ "msg": "\"common.materializeTab\" is deprecated for admin >= 5 at io-package.json. Please use property \"adminUI\".",
73
+ "err": false
74
+ },
75
+ "common.noConfig": {
76
+ "msg": "\"common.noConfig\" is deprecated for admin >= 5 at io-package.json. Please use property \"adminUI.config\":\"none\".",
77
+ "err": false
78
+ },
79
+ "common.subscribe": {
80
+ "msg": "\"common.subscribe\" will be removed with js-controller >= 6. Please remove from io-package.json and adapt code if required.",
81
+ "err": true
82
+ },
83
+ "common.wapeup": {
84
+ "msg": "\"common.wakeup\" is deprecated and ignored. Please remove from io-package.json.",
85
+ "err": true
86
+ },
87
+ };
88
+
33
89
  const memStore = {};
34
90
 
35
91
  /* Writable memory stream */
@@ -77,14 +133,21 @@ function getDependencyArray(deps) {
77
133
  .reduce((acc, dep) => acc.concat(dep), []);
78
134
  }
79
135
 
136
+ /*
80
137
  function checkLanguages(langObj) {
81
138
  if (Object.keys(langObj).length !== allowedLanguages.length) return false;
82
139
 
83
140
  return Object.keys(langObj).filter(lang => allowedLanguages.includes(lang)).length === allowedLanguages.length;
84
141
  }
142
+ */
143
+
144
+ function checkLanguages(langObj, languages) {
145
+ return languages.filter( lang => !langObj[lang]);
146
+ }
85
147
 
86
148
  function getGithubApiData(context) {
87
149
  return new Promise((resolve, reject) => {
150
+ console.log('\ngetGithubApiData');
88
151
  axios.get(context.githubUrlApi, { cache: false })
89
152
  .then(response => {
90
153
  context.githubApiData = response.data;
@@ -96,14 +159,93 @@ function getGithubApiData(context) {
96
159
  }
97
160
 
98
161
  context.githubUrl = `${context.githubUrlOriginal.replace('https://github.com', 'https://raw.githubusercontent.com')}/${context.branch}`;
99
- console.log(`Original URL: ${context.githubUrlOriginal}, raw: ${context.githubUrl}, api: ${context.githubUrlApi}`);
162
+ console.log(`Original URL: ${context.githubUrlOriginal}`);
163
+ console.log(`raw: ${context.githubUrl}`);
164
+ console.log(`api: ${context.githubUrlApi}`);
100
165
 
101
166
  resolve(context);
102
167
  })
103
- .catch(e => reject(e.toJSON()));
168
+ .catch(e => {
169
+ context.errors.push(`[E000] FATAL: cannot access repository ${context.githubUrlApi}`);
170
+ reject(e.toJSON())
171
+ });// E0xx
104
172
  });
105
173
  }
106
174
 
175
+ // Error ranges
176
+ // E0xx
177
+ // check package.json
178
+ //
179
+ // E1xx
180
+ // check io-package.json
181
+ //
182
+ // E2xx
183
+ // check npm and npmjs.org
184
+ //
185
+ // E3xx
186
+ // check testing
187
+ //
188
+ // E4xx
189
+ // check repositories
190
+ //
191
+ // E5xx
192
+ // check code
193
+ //
194
+ // E6xx
195
+ // check README file
196
+ //
197
+ // E7xx
198
+ // check license file
199
+ //
200
+ // E8xx
201
+ // check github repository
202
+ //
203
+ // E9xx
204
+ // check .gitignore file
205
+
206
+ // ---------------------------- let's begin ----------------------------
207
+
208
+ function getPackageJson(context) {
209
+ return new Promise((resolve, reject) => {
210
+ console.log('\ngetPackageJson');
211
+
212
+ downloadFile(context.githubUrl, '/package.json')
213
+ .then(packageJson => {
214
+ context.packageJson = packageJson;
215
+ if (typeof context.packageJson === 'string') {
216
+ try {
217
+ context.packageJson = JSON.parse(context.packageJson);
218
+ } catch (e) {
219
+ context.errors.push(`[E001] Cannot parse package.json: ${e}`);
220
+ }
221
+ }
222
+ resolve( context );
223
+ })
224
+ .catch(e => reject(e));
225
+ })
226
+ };
227
+
228
+ function getIOPackageJson(context) {
229
+ return new Promise((resolve, reject) => {
230
+ console.log('\ngetIOPackageJson');
231
+
232
+ downloadFile(context.githubUrl, '/io-package.json')
233
+ .then(ioPackageJson => {
234
+ context.ioPackageJson = ioPackageJson;
235
+ if (typeof context.ioPackageJson === 'string') {
236
+ try {
237
+ context.ioPackageJson = JSON.parse(context.ioPackageJson);
238
+ } catch (e) {
239
+ context.errors.push(`[E100] Cannot parse ioPackage.json: ${e}`);
240
+ }
241
+ }
242
+ resolve( context );
243
+ })
244
+ .catch(e => reject(e));
245
+ })
246
+ };
247
+
248
+
107
249
  // check package.json
108
250
  // E0xx
109
251
  function checkPackageJson(context) {
@@ -112,184 +254,282 @@ function checkPackageJson(context) {
112
254
  if (context.packageJson) {
113
255
  return resolve(context.packageJson);
114
256
  } else {
115
- return downloadFile(context.githubUrl, '/package.json')
116
- .then(packageJson => resolve(packageJson))
117
- .catch(e => reject(e));
257
+ throw('package.json not loaded');
118
258
  }
119
259
  })
120
- .then(packageJson => {
121
- context.packageJson = packageJson;
122
- if (typeof context.packageJson === 'string') {
123
- try {
124
- context.packageJson = JSON.parse(context.packageJson);
125
- } catch (e) {
126
- context.errors.push(`[E001] Cannot parse package.json: ${e}`);
127
- return context;
128
- }
260
+ .then(packageJson => {
261
+ context.packageJson = packageJson;
262
+ if (typeof context.packageJson === 'string') {
263
+ try {
264
+ context.packageJson = JSON.parse(context.packageJson);
265
+ } catch (e) {
266
+ context.errors.push(`[E001] Cannot parse package.json: ${e}`);
267
+ return context;
129
268
  }
269
+ }
130
270
 
131
- if (!context.githubUrlOriginal.match(/\/iobroker\./i)) {
132
- context.errors.push('[E002] No "ioBroker." found in the name of repository');
133
- } else {
134
- context.checks.push('"ioBroker" was found in the name of repository');
135
- }
271
+ if (!context.githubUrlOriginal.match(/\/iobroker\./i)) {
272
+ context.errors.push('[E002] No "ioBroker." found in the name of repository');
273
+ } else {
274
+ context.checks.push('"ioBroker" was found in the name of repository');
275
+ }
136
276
 
137
- if (context.githubUrlOriginal.includes('/iobroker.')) {
138
- context.errors.push('[E003] Repository must have name ioBroker.adaptername, but now io"b"roker is in lowercase');
139
- } else {
140
- context.checks.push('Repository has name ioBroker.adaptername (not iobroker.adaptername)');
141
- }
277
+ if (context.githubUrlOriginal.includes('/iobroker.')) {
278
+ context.errors.push('[E003] Repository must have name ioBroker.adaptername, but now io"b"roker is in lowercase');
279
+ } else {
280
+ context.checks.push('Repository has name ioBroker.adaptername (not iobroker.adaptername)');
281
+ }
142
282
 
143
- const m = context.githubUrlOriginal.match(/\/ioBroker\.(.*)$/);
144
- let adapterName = '';
145
- if (!m || !m[1]) {
146
- context.errors.push(`[E004] No adapter name found in URL: ${context.githubUrlOriginal}`);
147
- } else {
148
- context.checks.push('Adapter name found in the URL');
149
- adapterName = m[1].replace(/\/master$/, '').replace(/\/main$/, '');
150
- }
283
+ const m = context.githubUrlOriginal.match(/\/ioBroker\.(.*)$/);
284
+ let adapterName = '';
285
+ if (!m || !m[1]) {
286
+ context.errors.push(`[E004] No adapter name found in URL: ${context.githubUrlOriginal}`);
287
+ } else {
288
+ context.checks.push('Adapter name found in the URL');
289
+ adapterName = m[1].replace(/\/master$/, '').replace(/\/main$/, '');
290
+ }
151
291
 
152
- context.adapterName = adapterName;
292
+ context.adapterName = adapterName;
153
293
 
154
- if (adapterName.match(/[A-Z]/)) {
155
- context.errors.push('[E005] Adapter name must be lowercase');
156
- } else {
157
- context.checks.push('Adapter name is lowercase');
158
- }
294
+ if (adapterName.match(/[A-Z]/)) {
295
+ context.errors.push('[E005] Adapter name must be lowercase');
296
+ } else {
297
+ context.checks.push('Adapter name is lowercase');
298
+ }
159
299
 
160
- if (adapterName.match(/[^-_a-z\d]/)) {
161
- context.errors.push(`[E006] Invalid characters found in adapter name "${adapterName}". Only lowercase chars, digits, "-" and "_" are allowed`);
162
- } else {
163
- context.checks.push(`No invalid characters found in "${adapterName}"`);
164
- }
300
+ if (adapterName.match(/[^-_a-z\d]/)) {
301
+ context.errors.push(`[E006] Invalid characters found in adapter name "${adapterName}". Only lowercase chars, digits, "-" and "_" are allowed`);
302
+ } else {
303
+ context.checks.push(`No invalid characters found in "${adapterName}"`);
304
+ }
165
305
 
166
- if (adapterName.startsWith('_')) {
167
- context.errors.push(`[E024] Adapter name "${adapterName}" may not start with '_'`);
168
- } else {
169
- context.checks.push(`Adapter name "${adapterName}" does not start with '_'`);
170
- }
306
+ if (adapterName.startsWith('_')) {
307
+ context.errors.push(`[E024] Adapter name "${adapterName}" may not start with '_'`);
308
+ } else {
309
+ context.checks.push(`Adapter name "${adapterName}" does not start with '_'`);
310
+ }
171
311
 
172
- const n = context.githubUrlOriginal.match(/\/([^/]+)\/iobroker\./i);
173
- if (!n || !n[1]) {
174
- context.errors.push('[E007] Cannot find author repo in the URL');
175
- } else {
176
- context.authorName = n[1];
177
- }
312
+ const n = context.githubUrlOriginal.match(/\/([^/]+)\/iobroker\./i);
313
+ if (!n || !n[1]) {
314
+ context.errors.push('[E007] Cannot find author repo in the URL');
315
+ } else {
316
+ context.authorName = n[1];
317
+ }
178
318
 
179
- if (context.packageJson.name !== `iobroker.${adapterName.toLowerCase()}`) {
180
- context.errors.push(`[E020] Name of adapter in package.json must be lowercase and be equal to "iobroker.${adapterName.toLowerCase()}". Now is "${packageJson.name}"`);
181
- } else {
182
- context.checks.push(`Name of adapter in package.json must be lowercase and be equal to "iobroker.${adapterName.toLowerCase()}".`);
183
- }
319
+ if (context.packageJson.name !== `iobroker.${adapterName.toLowerCase()}`) {
320
+ context.errors.push(`[E020] Name of adapter in package.json must be lowercase and be equal to "iobroker.${adapterName.toLowerCase()}". Now is "${packageJson.name}"`);
321
+ } else {
322
+ context.checks.push(`Name of adapter in package.json must be lowercase and be equal to "iobroker.${adapterName.toLowerCase()}".`);
323
+ }
184
324
 
185
- if (!context.packageJson.version) {
186
- context.errors.push('[E009] No version found in the package.json');
187
- } else {
188
- context.checks.push('Version found in package.json');
189
- }
325
+ if (!context.packageJson.version) {
326
+ context.errors.push('[E009] No version found in the package.json');
327
+ } else {
328
+ context.checks.push('Version found in package.json');
329
+ }
190
330
 
191
- if (!context.packageJson.description) {
192
- context.errors.push('[E010] No description found in the package.json');
193
- } else {
194
- context.checks.push('Description found in package.json');
195
- }
331
+ if (!context.packageJson.description) {
332
+ context.errors.push('[E010] No description found in the package.json');
333
+ } else {
334
+ context.checks.push('Description found in package.json');
335
+ }
196
336
 
197
- if (context.packageJson.licenses) {
198
- context.errors.push('[E021] "licenses" in package.json are deprecated. Please use only "license": "NAME" field.');
199
- } else {
200
- context.checks.push('No "licenses" found in package.json');
201
- }
337
+ if (context.packageJson.licenses) {
338
+ context.errors.push('[E021] "licenses" in package.json are deprecated. Please remove and use "license": "NAME" field.');
339
+ } else {
340
+ context.checks.push('No "licenses" found in package.json');
341
+ }
202
342
 
203
- if (!context.packageJson.author) {
204
- context.errors.push('[E013] No author found in the package.json');
205
- } else {
206
- context.checks.push('Author found in package.json');
207
- }
343
+ if (!context.packageJson.author) {
344
+ context.errors.push('[E013] No author found in the package.json');
345
+ } else {
346
+ context.checks.push('Author found in package.json');
347
+ }
348
+
349
+ if (context.packageJson._args) {
350
+ context.errors.push('[E014] NPM information found in package.json. Please remove all attributes starting with "_"');
351
+ } else {
352
+ context.checks.push('No npm generated attributes found in package.json');
353
+ }
354
+
355
+ if (!context.packageJson.license) {
356
+ context.errors.push('[E015] No license found in package.json');
357
+ } else {
358
+ context.checks.push('"license" found in package.json');
208
359
 
209
- if (context.packageJson._args) {
210
- context.errors.push('[E014] NPM information found in package.json. Please remove all attributes starting with "_"');
360
+ // check if license valid
361
+ if (!licenses.includes(context.packageJson.license)) {
362
+ context.errors.push('[E016] ${context.packageJson.license} found in package.json is no valid SPDX license. Please use one of listed here: https://spdx.org/licenses/');
211
363
  } else {
212
- context.checks.push('No npm generated attributes found in package.json');
364
+ context.checks.push('"license" is valid in package.json');
213
365
  }
366
+ }
214
367
 
215
- if (!context.packageJson.license) {
216
- context.errors.push('[E015] No license found in package.json');
217
- } else {
218
- context.checks.push('"license" found in package.json');
368
+ if (!context.packageJson.repository) {
369
+ context.errors.push('[E017] No repository found in the package.json');
370
+ } else {
371
+ context.checks.push('Repository found in package.json');
372
+
373
+ const allowedRepoUrls = [
374
+ context.githubApiData.html_url, // https://github.com/klein0r/ioBroker.luftdaten
375
+ `git+${context.githubApiData.html_url}`, // git+https://github.com/klein0r/ioBroker.luftdaten
376
+ context.githubApiData.git_url, // git://github.com/klein0r/ioBroker.luftdaten.git
377
+ context.githubApiData.ssh_url, // git@github.com:klein0r/ioBroker.luftdaten.git
378
+ context.githubApiData.clone_url, // https://github.com/klein0r/ioBroker.luftdaten.git
379
+ `git+${context.githubApiData.clone_url}` // git+https://github.com/klein0r/ioBroker.luftdaten.git
380
+ ];
381
+
382
+ // https://docs.npmjs.com/cli/v7/configuring-npm/package-json#repository
383
+ if (context.packageJson.repository && typeof context.packageJson.repository === 'object') {
384
+ if (context.packageJson.repository.type !== 'git') {
385
+ context.errors.push(`[E018] Invalid repository type in package.json: ${context.packageJson.repository.type}. It should be git`);
386
+ } else {
387
+ context.checks.push('Repository type is valid in package.json: git');
388
+ }
219
389
 
220
- // check if license valid
221
- if (!licenses.includes(context.packageJson.license)) {
222
- context.errors.push('[E016] No SPDX license found in package.json. Please use one of listed here: https://spdx.org/licenses/');
390
+ if (!allowedRepoUrls.includes(context.packageJson.repository.url)) {
391
+ context.errors.push(`[E019] Invalid repository URL in package.json: ${context.packageJson.repository.url}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
392
+ } else {
393
+ context.checks.push('Repository URL is valid in package.json');
394
+ }
395
+ } else if (context.packageJson.repository && typeof context.packageJson.repository === 'string') {
396
+ if (!allowedRepoUrls.includes(context.packageJson.repository)) {
397
+ context.errors.push(`[E019] Invalid repository URL in package.json: ${context.packageJson.repository}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
223
398
  } else {
224
- context.checks.push('"license" is valid in package.json');
399
+ context.checks.push('Repository URL is valid in package.json');
225
400
  }
401
+ } else {
402
+ context.errors.push('[E019] Invalid repository URL in package.json');
226
403
  }
404
+ }
405
+
406
+ if (reservedAdapterNames.includes(adapterName)) {
407
+ context.errors.push('[E022] Adapter name is reserved. Please rename adapter.');
408
+ } else {
409
+ context.checks.push('Adapter name is not reserved');
410
+ }
411
+
412
+ if (!context.packageJson.dependencies) {
413
+ context.errors.push('[W030] No dependencies declared at package.json. Is this really correct?');
414
+ }
415
+ if (!context.packageJson.devDependencies) {
416
+ context.errors.push('[E031] No devDependencies declared at package.json. Plase correct package.json');
417
+ }
418
+
419
+ if ((context.packageJson.dependencies && context.packageJson.dependencies.npm) || (context.packageJson.optionalDependencies && context.packageJson.optionalDependencies.npm)) {
420
+ context.errors.push('[E023] Do not include "npm" as dependency!');
421
+ } else {
422
+ context.checks.push('npm is not in dependencies');
423
+ }
424
+
425
+ if ((context.packageJson.dependencies && context.packageJson.dependencies['iobroker.js-controller']) ||
426
+ (context.packageJson.devDependencies && context.packageJson.devDependencies['iobroker.js-controller']) ||
427
+ (context.packageJson.optionalDependencies && context.packageJson.optionalDependencies['iobroker.js-controller'])
428
+ ) {
429
+ context.errors.push('[E025] Do not include "iobroker.js-controller" as dependency!');
430
+ } else {
431
+ context.checks.push('iobroker.js-controller is not in dependencies');
432
+ }
227
433
 
228
- if (!context.packageJson.repository) {
229
- context.errors.push('[E017] No repository found in the package.json');
434
+ if (!context.ioPackageJson.common.onlyWWW) {
435
+ if (!context.packageJson.engines) {
436
+ context.errors.push(`[E026] "{'engines': {'node'>='${requiredNodeVersion}'}}" is required at package.json, "{'engines':{'node'>='${recommendedNodeVersion}'}}" is recommened`);
230
437
  } else {
231
- context.checks.push('Repository found in package.json');
232
-
233
- const allowedRepoUrls = [
234
- context.githubApiData.html_url, // https://github.com/klein0r/ioBroker.luftdaten
235
- `git+${context.githubApiData.html_url}`, // git+https://github.com/klein0r/ioBroker.luftdaten
236
- context.githubApiData.git_url, // git://github.com/klein0r/ioBroker.luftdaten.git
237
- context.githubApiData.ssh_url, // git@github.com:klein0r/ioBroker.luftdaten.git
238
- context.githubApiData.clone_url, // https://github.com/klein0r/ioBroker.luftdaten.git
239
- `git+${context.githubApiData.clone_url}` // git+https://github.com/klein0r/ioBroker.luftdaten.git
240
- ];
241
-
242
- // https://docs.npmjs.com/cli/v7/configuring-npm/package-json#repository
243
- if (context.packageJson.repository && typeof context.packageJson.repository === 'object') {
244
- if (context.packageJson.repository.type !== 'git') {
245
- context.errors.push(`[E018] Invalid repository type in package.json: ${context.packageJson.repository.type}. It should be git`);
438
+ if (!context.packageJson.engines.node) {
439
+ context.errors.push(`[E026] "{'engines': {'node'>='${requiredNodeVersion}'}}" is required at package.json, "{'engines':{'node'>='${recommendedNodeVersion}'}}" is recommened`);
440
+ } else {
441
+ context.checks.push('engines attribute containing node requirements exist.');
442
+ // 'engines': { 'node': '>= 18' }
443
+ // 'engines': { 'node': '>= 18.1.2' }
444
+ // 'engines': { 'node': '>= 18.1.2 < 19' }
445
+ const nodeVal = context.packageJson.engines.node;
446
+ let match = nodeVal.match(/^^(?<cmp>[<>=~]+)?\s*(?<vers>\d+(\.\d+(\.\d+)?)?(\-\w+\.\d+)?)/m);
447
+ if ( ! match ) {
448
+ context.warnings.push(`[W027] {'engines' : { 'node' : '${nodeVal}' } }" is not parseable.`);
246
449
  } else {
247
- context.checks.push('Repository type is valid in package.json: git');
450
+ //console.log( `${JSON.stringify(match.groups)}`);
451
+ if ( match.groups.cmp !== '>' && match.groups.cmp !== '>=' ) {
452
+ context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
453
+ } else {
454
+ //console.log( `${match.groups.vers} - ${recommendedNodeVersion}`);
455
+ if ( ! compareVersions.compare( match.groups.vers, requiredNodeVersion, '>=')) {
456
+ context.errors.push(`[E029] Node.js ${requiredNodeVersion} is required as minimum, node.js ${recommendedNodeVersion} is recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
457
+ } else if ( ! compareVersions.compare( match.groups.vers, recommendedNodeVersion, '>=')) {
458
+ context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
459
+ } else {
460
+ context.checks.push(`Correct node.js version ${match.groups.vers} requested by "engines" attribute at package.json.`);
461
+ }
462
+ }
248
463
  }
464
+ }
465
+ }
466
+ } else {
467
+ context.checks.push('"engines" check skipped for wwwOnly adapter.');
468
+ }
249
469
 
250
- if (!allowedRepoUrls.includes(context.packageJson.repository.url)) {
251
- context.errors.push(`[E019] Invalid repository URL in package.json: ${context.packageJson.repository.url}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
252
- } else {
253
- context.checks.push('Repository URL is valid in package.json');
254
- }
255
- } else if (context.packageJson.repository && typeof context.packageJson.repository === 'string') {
256
- if (!allowedRepoUrls.includes(context.packageJson.repository)) {
257
- context.errors.push(`[E019] Invalid repository URL in package.json: ${context.packageJson.repository}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
258
- } else {
259
- context.checks.push('Repository URL is valid in package.json');
260
- }
470
+ if (!context.ioPackageJson.common.onlyWWW) {
471
+ for (const dependency in dependencies) {
472
+ const requiredVersion = dependencies[dependency].required;
473
+ const recommendedVersion = dependencies[dependency].recommended;
474
+ let dependencyVersion = context.packageJson.dependencies[`${dependency}`] || '';
475
+ dependencyVersion = dependencyVersion.replace(/[\^\~]/,'' );
476
+ if (!dependencyVersion) {
477
+ context.errors.push(`[E032] No dependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to dependencies at package.json`);
478
+ } else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
479
+ context.errors.push(`[E033] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update dependencies at package.json`);
261
480
  } else {
262
- context.errors.push('[E019] Invalid repository URL in package.json');
481
+ context.checks.push('dependency ${dependency} ${dependencyVersion} is ok');
263
482
  }
264
483
  }
484
+ context.checks.push('"dependencies" checked.');
485
+ } else {
486
+ context.checks.push('"dependencies" check skipped for wwwOnly adapter.');
487
+ }
265
488
 
266
- if (reservedAdapterNames.includes(adapterName)) {
267
- context.errors.push('[E022] Adapter name is reserved!');
268
- } else {
269
- context.checks.push('Adapter name is not reserved');
270
- }
271
-
272
- if ((context.packageJson.dependencies && context.packageJson.dependencies.npm) || (context.packageJson.optionalDependencies && context.packageJson.optionalDependencies.npm)) {
273
- context.errors.push('[E023] Do not include "npm" as dependency!');
489
+ for (const dependency in devDependencies) {
490
+ const requiredVersion = devDependencies[dependency].required;
491
+ const recommendedVersion = devDependencies[dependency].recommended;
492
+ let dependencyVersion = context.packageJson.devDependencies[`${dependency}`] || '';
493
+ dependencyVersion = dependencyVersion.replace(/[\^\~]/,'' );
494
+ if (!dependencyVersion) {
495
+ context.errors.push(`[E034] No devDependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to devDependencies at package.json`);
496
+ } else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
497
+ context.errors.push(`[E035] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update devDependencies at package.json`);
274
498
  } else {
275
- context.checks.push('npm is not in dependencies');
499
+ context.checks.push('devDependency ${dependency} ${dependencyVersion} is ok');
276
500
  }
277
-
278
- if ((context.packageJson.dependencies && context.packageJson.dependencies['iobroker.js-controller']) ||
279
- (context.packageJson.devDependencies && context.packageJson.devDependencies['iobroker.js-controller']) ||
280
- (context.packageJson.optionalDependencies && context.packageJson.optionalDependencies['iobroker.js-controller'])
281
- ) {
282
- context.errors.push('[E025] Do not include "iobroker.js-controller" as dependency!');
283
- } else {
284
- context.checks.push('iobroker.js-controller is not in dependencies');
501
+ }
502
+ context.checks.push('"devDependencies" checked.');
503
+
504
+ for (const blacklist in blacklistPackageJson) {
505
+ //console.log(`checking blacklist ${blacklist}`);
506
+ let tmp = context.packageJson;
507
+ let log = '';
508
+ for (const element of blacklist.split('.')){
509
+ log = log + '.' + element;
510
+ //console.log(` check ${log}`);
511
+ tmp = tmp[element];
512
+ if ( !tmp ){
513
+ //console.log(` ${log} does not exist`);
514
+ break
515
+ }
285
516
  }
517
+ if (tmp) {
518
+ if (blacklistPackageJson[blacklist].err) {
519
+ context.errors.push(`[E036] ${blacklistPackageJson[blacklist].msg}`);
520
+ } else {
521
+ context.warnings.push(`[W036] ${blacklistPackageJson[blacklist].msg}`);
522
+ }
523
+ }
524
+ //else {
525
+ // console.log(`blacklist ${blacklist} no match`);
526
+ //}
527
+ }
528
+ context.checks.push('"blacklist (package)" checked.');
529
+ // max number is E036
286
530
 
287
- // SPECIAL NOTE: E026-E029 are used at checkIoPackage.json
288
-
289
- // max number is E029
290
-
291
- return context;
292
- });
531
+ return context;
532
+ });
293
533
  }
294
534
 
295
535
  const allowedLanguages = [
@@ -306,6 +546,12 @@ const allowedLanguages = [
306
546
  'zh-cn'
307
547
  ];
308
548
 
549
+ const requiredLanguages = [
550
+ 'en',
551
+ 'de',
552
+ // 'xx' // TESTING ONLY
553
+ ];
554
+
309
555
  const allowedModes = {
310
556
  'none': 'this adapter will not be started',
311
557
  'daemon': 'always running process (will be restarted if process exits)',
@@ -723,11 +969,10 @@ function checkIOPackageJson(context) {
723
969
  if (context.ioPackageJson) {
724
970
  return resolve(context.ioPackageJson);
725
971
  } else {
726
- return downloadFile(context.githubUrl, '/io-package.json')
727
- .then(packageJson => resolve(packageJson))
728
- .catch(e => reject(e));
972
+ throw('io-package.json not loaded');
729
973
  }
730
- }).then(ioPackageJson => {
974
+ })
975
+ .then(ioPackageJson => {
731
976
  return new Promise(resolve => {
732
977
  context.ioPackageJson = ioPackageJson;
733
978
  if (typeof context.ioPackageJson === 'string') {
@@ -756,10 +1001,11 @@ function checkIOPackageJson(context) {
756
1001
  context.checks.push('"common.name" is valid in io-package.json');
757
1002
  }
758
1003
 
1004
+ /*
759
1005
  if (context.ioPackageJson.common.title) {
760
1006
  context.warnings.push('[W171] "common.title" is deprecated in io-package.json. Please remove from io-package.json.');
761
1007
  }
762
- /*
1008
+
763
1009
  if (context.ioPackageJson.common.main) {
764
1010
  context.warnings.push('[W177] "common.main" is deprecated in io-package.json. For js-controller >= 3.3 please use package.json main and remove "common.main" from io-package.json.');
765
1011
  }
@@ -783,24 +1029,34 @@ function checkIOPackageJson(context) {
783
1029
 
784
1030
  if (typeof context.ioPackageJson.common.titleLang !== 'object') {
785
1031
  context.errors.push(`[E105] "common.titleLang" must be an object. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
786
- } else if (!checkLanguages(context.ioPackageJson.common.titleLang)) {
787
- context.warnings.push(`[W105] "common.titleLang" should be translated into all supported languages (${allowedLanguages.join(', ')})`);
788
- } else {
789
- Object.keys(context.ioPackageJson.common.titleLang).forEach(lang => {
790
- const text = context.ioPackageJson.common.titleLang[lang];
791
- if (text.match(/iobroker/i)) {
792
- context.errors.push(`[W105] "common.titleLang" should not have ioBroker in the name. It is clear, for what this adapter was created. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
793
- } else {
794
- context.checks.push('"common.titleLang" has no ioBroker in it in io-package.json');
795
- }
796
-
797
- if (text.match(/\sadapter|adapter\s/i)) {
798
- context.errors.push(`[E106] "common.titleLang" should not contain word "adapter" in the name. It is clear, that this is adapter. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
799
- } else {
800
- context.checks.push('"common.titleLang" has no "adapter" in it in io-package.json');
801
- }
802
- });
1032
+ } else {
1033
+ let missingLang = checkLanguages(context.ioPackageJson.common.titleLang, requiredLanguages);
1034
+ if (missingLang.length) {
1035
+ context.warnings.push(`[E105] Missing mandatory translation into ${missingLang.join()} of "common.titleLang" in io-package.json.`);
1036
+ }
1037
+
1038
+ missingLang = checkLanguages(context.ioPackageJson.common.titleLang, allowedLanguages);
1039
+ missingLang = missingLang.filter( lang => !requiredLanguages.includes(lang));
1040
+ if (missingLang.length) {
1041
+ missingLang = [... new Set(missingLang)]; // make unique
1042
+ context.warnings.push(`[W105] Missing suggested translation into ${missingLang.join()} of "common.titleLang" in io-package.json.`);
1043
+ }
803
1044
  }
1045
+
1046
+ Object.keys(context.ioPackageJson.common.titleLang).forEach(lang => {
1047
+ const text = context.ioPackageJson.common.titleLang[lang];
1048
+ if (text.match(/iobroker/i)) {
1049
+ context.errors.push(`[W105] "common.titleLang" should not have ioBroker in the name. It is clear, for what this adapter was created. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
1050
+ } else {
1051
+ context.checks.push('"common.titleLang" has no ioBroker in it in io-package.json');
1052
+ }
1053
+
1054
+ if (text.match(/\sadapter|adapter\s/i)) {
1055
+ context.errors.push(`[E106] "common.titleLang" should not contain word "adapter" in the name. It is clear, that this is adapter. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
1056
+ } else {
1057
+ context.checks.push('"common.titleLang" has no "adapter" in it in io-package.json');
1058
+ }
1059
+ });
804
1060
  }
805
1061
 
806
1062
  if (!context.ioPackageJson.common.version) {
@@ -822,13 +1078,22 @@ function checkIOPackageJson(context) {
822
1078
 
823
1079
  if (typeof context.ioPackageJson.common.desc !== 'object') {
824
1080
  context.errors.push(`[E109] "common.desc" in io-package.json should be an object for many languages. Found only "${context.ioPackageJson.common.desc}"`);
825
- } else if (!checkLanguages(context.ioPackageJson.common.desc)) {
826
- context.warnings.push(`[W109] "common.desc" should be translated into all supported languages (${allowedLanguages.join(', ')})`);
827
1081
  } else {
828
- context.checks.push('"common.desc" is multilingual in io-package.json');
1082
+
1083
+ let missingLang = checkLanguages(context.ioPackageJson.common.desc, requiredLanguages);
1084
+ if (missingLang.length) {
1085
+ context.warnings.push(`[E109] Missing mandatory translation into ${missingLang.join()} of "common.desc" in io-package.json.`);
1086
+ }
1087
+
1088
+ missingLang = checkLanguages(context.ioPackageJson.common.desc, allowedLanguages);
1089
+ missingLang = missingLang.filter( lang => !requiredLanguages.includes(lang));
1090
+ if (missingLang.length) {
1091
+ missingLang = [... new Set(missingLang)]; // make unique
1092
+ context.warnings.push(`[W109] Missing suggested translation into ${missingLang.join()} of "common.desc" in io-package.json.`);
1093
+ }
829
1094
  }
830
1095
  }
831
-
1096
+
832
1097
  if (context.ioPackageJson.common.keywords) {
833
1098
  const forbiddenKeywords = ['iobroker', 'adapter', 'smart home'];
834
1099
  if (!Array.isArray(context.ioPackageJson.common.keywords)) {
@@ -1014,14 +1279,28 @@ function checkIOPackageJson(context) {
1014
1279
  });
1015
1280
 
1016
1281
  if (!context.ioPackageJson.common.news[context.ioPackageJson.common.version]) {
1017
- context.errors.push(`[E145] No "common.news" found for actual version ${context.ioPackageJson.common.version}`);
1282
+ context.errors.push(`[E145] No "common.news" found for actual version ${context.ioPackageJson.common.version} in io-package.json`);
1018
1283
  }
1019
1284
 
1020
- Object.keys(context.ioPackageJson.common.news).forEach(version => {
1021
- if (!checkLanguages(context.ioPackageJson.common.news[version])) {
1022
- context.warnings.push(`[W145] Each "common.news" should be translated into all supported languages (${allowedLanguages.join(', ')})`);
1023
- }
1285
+ let missingLang =[];
1286
+ Object.keys(context.ioPackageJson.common.news).forEach(version => {
1287
+ missingLang = missingLang.concat( checkLanguages(context.ioPackageJson.common.news[version], requiredLanguages) );
1024
1288
  });
1289
+ if (missingLang.length) {
1290
+ missingLang = [... new Set(missingLang)]; // make unique
1291
+ context.warnings.push(`[E145] Missing mandatory translation into ${missingLang.join()} of some "common.news" in io-package.json.`);
1292
+ }
1293
+
1294
+ missingLang =[];
1295
+ Object.keys(context.ioPackageJson.common.news).forEach(version => {
1296
+ missingLang = missingLang.concat(checkLanguages(context.ioPackageJson.common.news[version], allowedLanguages));
1297
+ });
1298
+ missingLang = missingLang.filter( lang => !requiredLanguages.includes(lang));
1299
+ if (missingLang.length) {
1300
+ missingLang = [... new Set(missingLang)]; // make unique
1301
+ context.warnings.push(`[W145] Missing suggested translation into ${missingLang.join()} of some "common.news" in io-package.json.`);
1302
+ }
1303
+
1025
1304
  }
1026
1305
 
1027
1306
  // now check the package.json again, because it is valid only for onlyWWW
@@ -1035,9 +1314,9 @@ function checkIOPackageJson(context) {
1035
1314
  }
1036
1315
  }
1037
1316
 
1038
- if (context.ioPackageJson.common.installedFrom) {
1039
- context.errors.push('[E144] common.installedFrom field found in io-package.json. Must be removed.');
1040
- }
1317
+ //if (context.ioPackageJson.common.installedFrom) {
1318
+ // context.errors.push('[E144] common.installedFrom field found in io-package.json. Must be removed.');
1319
+ //}
1041
1320
 
1042
1321
  if (context.ioPackageJson.instanceObjects) {
1043
1322
  const instanceObjects = context.ioPackageJson.instanceObjects;
@@ -1068,15 +1347,15 @@ function checkIOPackageJson(context) {
1068
1347
  }
1069
1348
 
1070
1349
  if (!context.ioPackageJson.common.connectionType) {
1071
- !context.ioPackageJson.common.onlyWWW && context.errors.push('[E150] No common.connectionType found in io-package.json');
1350
+ !context.ioPackageJson.common.onlyWWW && context.errors.push('[E150] No "common.connectionType" found in io-package.json');
1072
1351
  } else if (!['local', 'cloud', 'none'].includes(context.ioPackageJson.common.connectionType)) {
1073
- context.errors.push(`[E151] common.connectionType type has an invalid value "${context.ioPackageJson.common.connectionType}"`);
1352
+ context.errors.push(`[E151] "common.connectionType" type has an invalid value "${context.ioPackageJson.common.connectionType}"`);
1074
1353
  }
1075
1354
 
1076
1355
  if (!context.ioPackageJson.common.dataSource) {
1077
- !context.ioPackageJson.common.onlyWWW && context.errors.push('[E152] No common.dataSource found in io-package.json');
1356
+ !context.ioPackageJson.common.onlyWWW && context.errors.push('[E152] No "common.dataSource" found in io-package.json');
1078
1357
  } else if (!['poll', 'push', 'assumption', 'none'].includes(context.ioPackageJson.common.dataSource)) {
1079
- context.errors.push(`[E152] common.dataSource type has an invalid value "${context.ioPackageJson.common.dataSource}"`);
1358
+ context.errors.push(`[E153] "common.dataSource" type has an invalid value "${context.ioPackageJson.common.dataSource}"`);
1080
1359
  }
1081
1360
 
1082
1361
  let currentJsControllerVersion = undefined;
@@ -1145,19 +1424,8 @@ function checkIOPackageJson(context) {
1145
1424
  }
1146
1425
  }
1147
1426
  }
1148
-
1149
- /*
1150
- - adapter-core 3.0.0+ requires node 16+ - solved as node 16 is global minimum
1151
- - adapter-core 3.0.6 is recommended as minimum
1152
- */
1153
-
1154
- if (!compareVersions.compare(context.packageJson.dependencies['@iobroker/adapter-core'], `${recommendedAdapterCoreVersion}`, '>=')) {
1155
- context.warnings.push(`[W173] "@iobroker/adapter-core" (${context.packageJson.dependencies['@iobroker/adapter-core']}) should be ${recommendedAdapterCoreVersion} or newer - please update`);
1156
- } else {
1157
- context.checks.push(`adapter-core ${context.packageJson.dependencies['@iobroker/adapter-core']} matches recommendation`);
1158
- }
1159
1427
  }
1160
-
1428
+
1161
1429
  if (context.ioPackageJson.common.protectedNative) {
1162
1430
  if (!currentJsControllerVersion) {
1163
1431
  context.errors.push(`[E157] common.protectedNative requires dependency {"js-controller": ">=2.0.2"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
@@ -1184,9 +1452,9 @@ function checkIOPackageJson(context) {
1184
1452
 
1185
1453
  if (!context.ioPackageJson.common.onlyWWW) {
1186
1454
  if (!context.ioPackageJson.common.tier) {
1187
- context.warnings.push(`[W115] common.tier is required in io-package.json. Please check https://github.com/ioBroker/ioBroker.docs/blob/master/docs/en/dev/objectsschema.md#adapter.`);
1455
+ context.warnings.push(`[W115] \"common.tier\" is required in io-package.json. Please check https://github.com/ioBroker/ioBroker.docs/blob/master/docs/en/dev/objectsschema.md#adapter.`);
1188
1456
  } else if (![1, 2, 3].includes(context.ioPackageJson.common.tier)) {
1189
- context.errors.push(`[E155] Invalid common.tier value: ${context.ioPackageJson.common.tier}. Only 1, 2 or 3 are allowed!`);
1457
+ context.errors.push(`[E155] Invalid \"common.tier\" value: ${context.ioPackageJson.common.tier} at io-package.json. Only 1, 2 or 3 are allowed!`);
1190
1458
  } else {
1191
1459
  context.checks.push('"common.tier" is valid in io-package.json');
1192
1460
  }
@@ -1200,55 +1468,11 @@ function checkIOPackageJson(context) {
1200
1468
  context.checks.push('"common.automaticUpgrade" does not exist in io-package.json');
1201
1469
  }
1202
1470
 
1203
- if (context.ioPackageJson.common.wakeup) {
1204
- context.warnings.push(`[W174] "common.wakeup" is deprectaed. Please remove from io-package.json`);
1205
- } else {
1206
- context.checks.push('"common.wakeup" does not exist in io-package.json');
1207
- }
1208
-
1209
- /*
1210
- * The following check is logical related to package.json. It is placed here as the check must be performed only
1211
- * if wwwOnly attribute is not set at io-package.json. Please note that these errors use error number form package.json range.
1212
- *
1213
- */
1214
-
1215
- if (!context.ioPackageJson.common.onlyWWW) {
1216
- if (!context.packageJson.engines) {
1217
- context.warnings.push(`[W026] "{'engines' : { 'node' >= '${recommendedNodeVersion}' } }" is required at package.json`);
1218
- } else {
1219
- if (!context.packageJson.engines.node) {
1220
- context.warnings.push(`[W026] "{'engines' : { 'node' >= '${recommendedNodeVersion}' } }" is required at package.json`);
1221
- } else {
1222
- context.checks.push('engines attribute containing node requirements exist.');
1223
- // 'engines': { 'node': '>= 18' }
1224
- // 'engines': { 'node': '>= 18.1.2' }
1225
- // 'engines': { 'node': '>= 18.1.2 < 19' }
1226
- const nodeVal = context.packageJson.engines.node;
1227
- let match = nodeVal.match(/^^(?<cmp>[<>=~]+)?\s*(?<vers>\d+(\.\d+(\.\d+)?)?(\-\w+\.\d+)?)/m);
1228
- if ( ! match ) {
1229
- context.warnings.push(`[W027] {'engines' : { 'node' : '${nodeVal}' } }" is not parseable.`);
1230
- } else {
1231
- //console.log( `${JSON.stringify(match.groups)}`);
1232
- if ( match.groups.cmp !== '>' && match.groups.cmp !== '>=' ) {
1233
- context.warnings.push(`[W026] "{'engines' : { 'node' >= '${recommendedNodeVersion}' } }" is required at package.json`);
1234
- } else {
1235
- //console.log( `${match.groups.vers} - ${recommendedNodeVersion}`);
1236
- if ( ! compareVersions.compare( match.groups.vers, requiredNodeVersion, '>=')) {
1237
- context.errors.push(`[E029] Node.js ${requiredNodeVersion} is required as minimum, node.js ${recommendedNodeVersion} is recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
1238
- } else if ( ! compareVersions.compare( match.groups.vers, recommendedNodeVersion, '>=')) {
1239
- context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
1240
- } else {
1241
- context.checks.push('Correct node.js version requested by "engines" attribute at package.json.');
1242
- }
1243
- }
1244
- }
1245
- }
1246
- }
1247
- } else {
1248
- context.checks.push('"engines" check skipped for wwwOnly adapter.');
1249
- }
1250
- /* end of foreign check */
1251
-
1471
+ //if (context.ioPackageJson.common.wakeup) {
1472
+ // context.warnings.push(`[W174] "common.wakeup" is deprectaed. Please remove from io-package.json`);
1473
+ //} else {
1474
+ // context.checks.push('"common.wakeup" does not exist in io-package.json');
1475
+ //}
1252
1476
 
1253
1477
  if (context.ioPackageJson.common.restartAdapters) {
1254
1478
  const restartAdaptersArray = context.ioPackageJson.common.restartAdapters;
@@ -1263,6 +1487,32 @@ function checkIOPackageJson(context) {
1263
1487
  context.checks.push('"restartAdapters" check skipped as object not present.');
1264
1488
  }
1265
1489
 
1490
+ for (const blacklist in blacklistIOPackageJson) {
1491
+ //console.log(`checking blacklist ${blacklist}`);
1492
+ let tmp = context.ioPackageJson;
1493
+ let log = '';
1494
+ for (const element of blacklist.split('.')){
1495
+ log = log + '.' + element;
1496
+ //console.log(` check ${log}`);
1497
+ tmp = tmp[element];
1498
+ if ( !tmp ){
1499
+ //console.log(` ${log} does not exist`);
1500
+ break
1501
+ }
1502
+ }
1503
+ if (tmp) {
1504
+ if (blacklistIOPackageJson[blacklist].err) {
1505
+ context.errors.push(`[E184] ${blacklistIOPackageJson[blacklist].msg}`);
1506
+ } else {
1507
+ context.warnings.push(`[W184] ${blacklistIOPackageJson[blacklist].msg}`);
1508
+ }
1509
+ }
1510
+ //else {
1511
+ // console.log(`blacklist ${blacklist} no match`);
1512
+ //}
1513
+ }
1514
+ context.checks.push('"blacklist (io-package)" checked.');
1515
+
1266
1516
  if (context.ioPackageJson.common.extIcon) {
1267
1517
  return downloadFile(context.ioPackageJson.common.extIcon, null, true)
1268
1518
  .then(icon => {
@@ -1279,7 +1529,7 @@ function checkIOPackageJson(context) {
1279
1529
  }
1280
1530
 
1281
1531
  context.checks.push('"extIcon" could be downloaded');
1282
- if (!context.ioPackageJson.onlyWWW && context.packageJson.main) {
1532
+ if (!context.ioPackageJson.common.onlyWWW && context.packageJson.main) {
1283
1533
  return downloadFile(context.githubUrl, '/' + context.packageJson.main)
1284
1534
  .then(() => context.checks.push(context.packageJson.main + ' could be downloaded'))
1285
1535
  .catch(() => context.errors.push(`[E124] Main file not found under URL: ${context.githubUrl}/${context.packageJson.main}`))
@@ -1295,7 +1545,9 @@ function checkIOPackageJson(context) {
1295
1545
  }
1296
1546
  // do not put any code behind this line
1297
1547
 
1298
- // max number is E183
1548
+ // max number is E184
1549
+ // free 144, 174
1550
+ // duplicates to check 145
1299
1551
  }
1300
1552
  });
1301
1553
  });
@@ -1342,10 +1594,15 @@ function checkNpm(context) {
1342
1594
  if (!body['dist-tags'] ||
1343
1595
  context.packageJson.version !== body['dist-tags'].latest
1344
1596
  ) {
1345
- context.warnings.push(`[W202] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${
1346
- (body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
1597
+ if ( compareVersions.compare( body['dist-tags'].latest, context.packageJson.version, '>=' )) {
1598
+ context.errors.push(`[E203] Version of package.json (${context.packageJson.version}) lower than latest version on NPM (${
1599
+ (body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
1600
+ } else {
1601
+ context.warnings.push(`[W202] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${
1602
+ (body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
1603
+ }
1347
1604
  } else {
1348
- context.checks.push('Version of package.json matches latest version on NPM');
1605
+ context.checks.push(`Version of package.json ${context.packageJson.version} matches latest version on NPM`);
1349
1606
  }
1350
1607
  }
1351
1608
 
@@ -1565,7 +1822,7 @@ function checkCode(context) {
1565
1822
  '.releaseconfig.json',
1566
1823
 
1567
1824
  // add all potential files anyway. If they exist they must be valid.
1568
- // if the are nozt needed a warning could be issued
1825
+ // if the are not needed a warning could be issued
1569
1826
  'admin/index_m.html',
1570
1827
  'admin/words.js',
1571
1828
  'admin/jsonConfig.json',
@@ -2073,7 +2330,7 @@ function makeResponse(code, data) {
2073
2330
  }
2074
2331
 
2075
2332
  function check(request, ctx, callback) {
2076
- console.log('PROCESS: ' + JSON.stringify(request));
2333
+ // console.log('PROCESS: ' + JSON.stringify(request));
2077
2334
  if (!request.queryStringParameters.url) {
2078
2335
  return callback(null, makeResponse(500, {error: 'No github URL provided'}));
2079
2336
  } else {
@@ -2095,6 +2352,8 @@ function check(request, ctx, callback) {
2095
2352
  context.branch = githubBranch || null;
2096
2353
 
2097
2354
  getGithubApiData(context)
2355
+ .then(context => getPackageJson(context))
2356
+ .then(context => getIOPackageJson(context))
2098
2357
  .then(context => checkPackageJson(context))
2099
2358
  .then(context => checkIOPackageJson(context))
2100
2359
  .then(context => checkNpm(context))
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.2.3",
2
+ "version": "2.3.1",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
5
  "axios": "^1.6.8",
package/doc/readme.js DELETED
@@ -1,151 +0,0 @@
1
- const fs = require('fs');
2
- const issues = require('./issues');
3
- const languages = ['en'];
4
-
5
- // try to extract error description from index.js
6
- function extractFromIndex() {
7
- let added = false;
8
- const lines = fs.readFileSync(`${__dirname}/../index.js`, {encoding: 'utf8'}).split('\n');
9
- for (let i = 0; i < lines.length; i++) {
10
- const m = lines[i].match(/`(\[[EW]\d\d\d] [^`]+)`/) || lines[i].match(/'(\[[EW]\d\d\d] [^`]+)'/) || lines[i].match(/"(\[[EW]\d\d\d] [^`]+)"/);
11
- if (m) {
12
- const parts = m[1].match(/\[([EW]\d\d\d)] (.+)/);
13
- if (parts) {
14
- console.log(parts[1], parts[2]);
15
- if (!issues[parts[1]]) {
16
- // cut off the last part
17
- parts[2] = parts[2].replace(/"/g, '`');
18
- issues[parts[1]] = {
19
- title: parts[2],
20
- };
21
- added = true;
22
- }
23
- }
24
- }
25
- }
26
- if (added) {
27
- // sort issues
28
- const newIssues = {};
29
- const keys = Object.keys(issues).sort();
30
- keys.forEach(key => newIssues[key] = issues[key]);
31
-
32
- fs.writeFileSync(`${__dirname}/issues.json`, JSON.stringify(newIssues, null, 2));
33
- }
34
- }
35
-
36
- extractFromIndex();
37
-
38
-
39
-
40
- const explanationTitle = {
41
- en: 'Explanation',
42
- de: 'Erklärung',
43
- ru: 'Объяснение',
44
- fr: 'Explication',
45
- nl: 'Uitleg',
46
- 'pt-pt': 'Explicação',
47
- it: 'Spiegazione',
48
- es: 'Explicación',
49
- uk: 'Пояснення',
50
- pl: 'Wyjaśnienie',
51
- 'zh-cn': '解释',
52
- };
53
-
54
- const stepsTitle = {
55
- en: 'Required step to resolve the problem',
56
- de: 'Erforderlicher Schritt zur Behebung des Problems',
57
- ru: 'Необходимый шаг для устранения проблемы',
58
- fr: 'Étape requise pour résoudre le problème',
59
- nl: 'Vereiste stap om het probleem op te lossen',
60
- 'pt-pt': 'Etapa necessária para resolver o problema',
61
- it: 'Passaggio richiesto per risolvere il problema',
62
- es: 'Paso requerido para resolver el problema',
63
- uk: 'Необхідний крок для вирішення проблеми',
64
- pl: 'Wymagany krok do rozwiązania problemu',
65
- 'zh-cn': '解决问题所需的步骤',
66
- };
67
-
68
- const notesTitle = {
69
- en: 'Technical notes',
70
- de: 'Technische Notizen',
71
- ru: 'Технические заметки',
72
- fr: 'Notes techniques',
73
- nl: 'Technische notities',
74
- 'pt-pt': 'Notas técnicas',
75
- it: 'Note tecniche',
76
- es: 'Notas técnicas',
77
- uk: 'Технічні примітки',
78
- pl: 'Notatki techniczne',
79
- 'zh-cn': '技术说明',
80
- };
81
-
82
-
83
- // try to find possible languages
84
- Object.keys(issues).forEach(issue => {
85
- const entry = issues[issue];
86
- if (entry.title && typeof entry.title === 'object') {
87
- const langs = Object.keys(entry.title);
88
- langs.forEach(lang => !languages.includes(lang) && languages.push(lang));
89
- }
90
- if (entry.explanation && typeof entry.explanation === 'object') {
91
- const langs = Object.keys(entry.explanation);
92
- langs.forEach(lang => !languages.includes(lang) && languages.push(lang));
93
- }
94
- if (entry.resolving && typeof entry.resolving === 'object') {
95
- const langs = Object.keys(entry.resolving);
96
- langs.forEach(lang => !languages.includes(lang) && languages.push(lang));
97
- }
98
- });
99
-
100
- function getText(text, lang) {
101
- if (typeof text === 'object') {
102
- if (text[lang]) {
103
- return text[lang];
104
- } else {
105
- return text.en;
106
- }
107
- }
108
- return text;
109
- }
110
-
111
- languages.forEach(lang => {
112
- // generate one language file for each language
113
- const lines = [];
114
- const content = [
115
- '# Explanation of repo checker issues',
116
- '## Content',
117
- ];
118
-
119
- Object.keys(issues).forEach(issue => {
120
- const entry = issues[issue];
121
- const title = `[${issue}] ${getText(entry.title, lang)}`;
122
- const explanation = getText(entry.explanation, lang);
123
- const resolving = getText(entry.resolving, lang);
124
- const note = getText(entry.note, lang);
125
-
126
- // link => e001-cannot-parse-packetjson
127
- content.push(`- [${issue} ${getText(entry.title, lang)}](#${title.toLowerCase()
128
- .replace(/\s/g, '-')
129
- .replace(/\[/g, '')
130
- .replace(/]/g, '')
131
- .replace(/[^-\w\d]/g, '')
132
- })`);
133
- lines.push(`### ${title}`);
134
- if (explanation) {
135
- lines.push(`#### ${getText(explanationTitle, lang)}`);
136
- lines.push(explanation);
137
- }
138
- if (resolving) {
139
- lines.push(`#### ${getText(stepsTitle, lang)}`);
140
- lines.push(resolving);
141
- }
142
- if (note) {
143
- lines.push(`#### ${getText(notesTitle, lang)}`);
144
- lines.push(note);
145
- }
146
- lines.push('');
147
- });
148
- content.push('');
149
- content.push('## Issues');
150
- fs.writeFileSync(`${__dirname}/issues_${lang}.md`, `${content.join('\n')}\n${lines.join('\n')}\n`, {encoding: 'utf8'});
151
- });