@iobroker/repochecker 3.0.0-alpha.0 → 3.0.0-alpha.2

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/index.js CHANGED
@@ -12,17 +12,7 @@
12
12
  |_|
13
13
 
14
14
  */
15
- //const unzipper = require('unzipper');
16
- // const util = require('node:util');
17
- // const stream = require('node:stream');
18
- // const Writable = stream.Writable;
19
- // const sizeOf = require('image-size');
20
15
  const axios = require('axios');
21
- // const JSON5 = require('json5');
22
- // const compareVersions = require('compare-versions');
23
- // const Languagedetect = require('languagedetect');
24
- // const languagedetect = new Languagedetect;
25
- // const execSync = require('node:child_process').execSync;
26
16
 
27
17
  const issues = require('./doc/issues');
28
18
  const version = require('./package.json').version;
@@ -49,203 +39,6 @@ axios.defaults.headers = {
49
39
  'Expires': '0',
50
40
  };
51
41
 
52
- // // adapt a recommended version here
53
- // // outdated? // const recommendedAdapterCoreVersion = '3.0.6';
54
- // const recommendedJsControllerVersion = '5.0.19';
55
- // let requiredJsControllerVersion = '4.0.24';
56
- // const recommendedNodeVersion = '18'; // This is the minimum node version that should be required
57
- // const requiredNodeVersion = '16'; // This is the minimum node version that must be required
58
-
59
- // const dependenciesPackageJson = {
60
- // '@iobroker/adapter-core': {
61
- // required: '3.1.4',
62
- // recommended: '3.1.6',
63
- // },
64
- // };
65
-
66
- // const devDependenciesPackageJson = {
67
- // '@iobroker/testing': {
68
- // required: '4.1.3',
69
- // recommended: '4.1.3',
70
- // onlyWWW: false,
71
- // },
72
- // };
73
-
74
- // const blacklistPackageJson = {
75
-
76
- // };
77
-
78
- // const blacklistIOPackageJson = {
79
- // installedFrom: {
80
- // msg: '"installedFrom" is invalid at io-package.json. Please remove.',
81
- // err:true
82
- // },
83
- // 'common.installedFrom': {
84
- // msg: '"common.installedFrom" is invalid. Please remove from io-package.json.',
85
- // err:true
86
- // },
87
- // 'common.title': {
88
- // msg: '"common.title" is deprecated and replaced by "common.titleLang". Please remove from io-package.json.',
89
- // err:false
90
- // },
91
- // 'common.main': {
92
- // msg: '"common.main" is deprecated and ignored. Please remove from io-package.json. Use "main" at package.json instead.',
93
- // err:false
94
- // },
95
- // 'common.materialize': {
96
- // msg: '"common.materialize" is deprecated for admin >= 5 at io-package.json. Please use property "adminUI".',
97
- // err:false
98
- // },
99
- // 'common.materializeTab': {
100
- // msg: '"common.materializeTab" is deprecated for admin >= 5 at io-package.json. Please use property "adminUI".',
101
- // err:false
102
- // },
103
- // 'common.noConfig': {
104
- // msg: '"common.noConfig" is deprecated for admin >= 5 at io-package.json. Please use property "adminUI.config":"none".',
105
- // err:false
106
- // },
107
- // 'common.subscribe': {
108
- // msg: '"common.subscribe" will be removed with js-controller >= 6. Please remove from io-package.json and adapt code if required.',
109
- // err:true
110
- // },
111
- // 'common.wapeup': {
112
- // msg: '"common.wakeup" is deprecated and ignored. Please remove from io-package.json.',
113
- // err:true
114
- // },
115
- // };
116
-
117
- // const memStore = {};
118
-
119
- // /* Writable memory stream */
120
- // function WMStrm(key, options) {
121
- // // allow use without a new operator
122
- // if (!(this instanceof WMStrm)) {
123
- // return new WMStrm(key, options);
124
- // }
125
- // Writable.call(this, options); // init super
126
- // this.key = key; // save key
127
- // memStore[key] = Buffer.from(''); // empty
128
- // }
129
-
130
- // util.inherits(WMStrm, Writable);
131
-
132
- // WMStrm.prototype._write = function (chunk, enc, cb) {
133
- // // our memory store stores things in buffers
134
- // const buffer = Buffer.isBuffer(chunk) ?
135
- // chunk : // already is Buffer use it
136
- // new Buffer(chunk, enc); // string, convert
137
-
138
- // // concat to the buffer already there
139
- // memStore[this.key] = Buffer.concat([memStore[this.key], buffer]);
140
- // cb();
141
- // };
142
-
143
- // function downloadFile(githubUrl, path, binary, noError) {
144
- // console.log(`Download ${githubUrl}${path || ''}`);
145
- // const options = {};
146
- // if (binary) {
147
- // options.responseType = 'arraybuffer';
148
- // }
149
-
150
- // return axios(githubUrl + (path || ''), options)
151
- // .then(response => response.data)
152
- // .catch(e => {
153
- // !noError && console.error(`Cannot download ${githubUrl}${path || ''}`);
154
- // throw e;
155
- // });
156
- // }
157
-
158
- // function getDependencyArray(deps) {
159
- // return deps
160
- // .map(dep => typeof dep === 'object' ? Object.keys(dep) : [dep])
161
- // .reduce((acc, dep) => acc.concat(dep), []);
162
- // }
163
-
164
- // // dependencies might be:
165
- // // [
166
- // // {"js-controller":">=1.2.3"}
167
- // // ]
168
- // // or
169
- // // [
170
- // // {"js-controller":">=1.2.3"},
171
- // // {"vis":">=1.2.3"}
172
- // // ]
173
- // // or
174
- // // [
175
- // // {
176
- // // "js-controller":">=1.2.3",
177
- // // "vis":">=1.2.3"
178
- // // }
179
- // // ]
180
- // // or
181
- // // [
182
- // // {"js-controller":">=1.2.3"},
183
- // // "vis"
184
- // // ]
185
- // function getDependencies(deps) {
186
- // const ret = {};
187
- // console.log(`deps: ${JSON.stringify(deps)}, type ${typeof deps}`);
188
- // for (const dep of deps ) {
189
- // if (typeof dep === 'object') {
190
- // for (const key in dep ) {
191
- // ret[key] = dep[key];
192
- // }
193
- // } else {
194
- // ret[ dep ] = '>=0';
195
- // }
196
- // }
197
- // console.log(`ret: ${JSON.stringify(ret)}`);
198
- // return ret;
199
- // }
200
-
201
- // /*
202
- // return the greater of two semver versions
203
- // */
204
- // function maxVersion(v1, v2) {
205
- // if (compareVersions.compareVersions(v1, v2) > 0) {
206
- // return v1;
207
- // }
208
- // return v2;
209
- // }
210
-
211
- // /*
212
- // function checkLanguages(langObj) {
213
- // if (Object.keys(langObj).length !== allowedLanguages.length) return false;
214
-
215
- // return Object.keys(langObj).filter(lang => allowedLanguages.includes(lang)).length === allowedLanguages.length;
216
- // }
217
- // */
218
-
219
- // function checkLanguages(langObj, languages) {
220
- // return languages.filter(lang => !langObj[lang]);
221
- // }
222
-
223
- function getGithubApiData(context) {
224
- return new Promise((resolve, reject) => {
225
- console.log('\ngetGithubApiData');
226
- axios.get(context.githubUrlApi, { cache: false })
227
- .then(response => {
228
- context.githubApiData = response.data;
229
- // console.log(`API Data: ${JSON.stringify(context.githubApiData)}`);
230
-
231
- if (!context.branch) {
232
- context.branch = context.githubApiData.default_branch; // main vs. master
233
- console.log(`Branch was not defined by user - checking branch: ${context.branch}`);
234
- }
235
-
236
- context.githubUrl = `${context.githubUrlOriginal.replace('https://github.com', 'https://raw.githubusercontent.com')}/${context.branch}`;
237
- console.log(`Original URL: ${context.githubUrlOriginal}`);
238
- console.log(`raw: ${context.githubUrl}`);
239
- console.log(`api: ${context.githubUrlApi}`);
240
-
241
- resolve(context);
242
- })
243
- .catch(e => {
244
- context.errors.push(`[E000] FATAL: cannot access repository ${context.githubUrlApi}`);
245
- reject(e.toJSON());
246
- });// E0xx
247
- });
248
- }
249
42
 
250
43
  // Error ranges
251
44
  // E0xx
@@ -278,2527 +71,33 @@ function getGithubApiData(context) {
278
71
  // E9xx
279
72
  // check .gitignore file
280
73
 
281
- // ---------------------------- let's begin ----------------------------
282
-
283
- // function getPackageJson(context) {
284
- // return new Promise((resolve, reject) => {
285
- // console.log('\ngetPackageJson');
286
-
287
- // downloadFile(context.githubUrl, '/package.json')
288
- // .then(packageJson => {
289
- // context.packageJson = packageJson;
290
- // if (typeof context.packageJson === 'string') {
291
- // try {
292
- // context.packageJson = JSON.parse(context.packageJson);
293
- // } catch (e) {
294
- // context.errors.push(`[E001] Cannot parse package.json: ${e}`);
295
- // }
296
- // }
297
- // resolve( context );
298
- // })
299
- // .catch(e => reject(e));
300
- // });
301
- // }
302
-
303
- // function getIOPackageJson(context) {
304
- // return new Promise((resolve, reject) => {
305
- // console.log('\ngetIOPackageJson');
306
-
307
- // downloadFile(context.githubUrl, '/io-package.json')
308
- // .then(ioPackageJson => {
309
- // context.ioPackageJson = ioPackageJson;
310
- // if (typeof context.ioPackageJson === 'string') {
311
- // try {
312
- // context.ioPackageJson = JSON.parse(context.ioPackageJson);
313
- // } catch (e) {
314
- // context.errors.push(`[E100] Cannot parse ioPackage.json: ${e}`);
315
- // }
316
- // }
317
- // resolve( context );
318
- // })
319
- // .catch(e => reject(e));
320
- // });
321
- // }
322
-
323
-
324
- // // check package.json
325
- // // E0xx
326
- // function checkPackageJson(context) {
327
- // return new Promise(resolve => {
328
- // console.log('\ncheckPackageJson [E0xx]');
329
- // if (context.packageJson) {
330
- // return resolve(context.packageJson);
331
- // } else {
332
- // throw ('package.json not loaded');
333
- // }
334
- // })
335
- // .then(packageJson => {
336
- // context.packageJson = packageJson;
337
- // if (typeof context.packageJson === 'string') {
338
- // try {
339
- // context.packageJson = JSON.parse(context.packageJson);
340
- // } catch (e) {
341
- // context.errors.push(`[E001] Cannot parse package.json: ${e}`);
342
- // return context;
343
- // }
344
- // }
345
-
346
- // if (!context.githubUrlOriginal.match(/\/iobroker\./i)) {
347
- // context.errors.push('[E002] No "ioBroker." found in the name of repository');
348
- // } else {
349
- // context.checks.push('"ioBroker" was found in the name of repository');
350
- // }
351
-
352
- // if (context.githubUrlOriginal.includes('/iobroker.')) {
353
- // context.errors.push('[E003] Repository must have name ioBroker.adaptername, but now io"b"roker is in lowercase');
354
- // } else {
355
- // context.checks.push('Repository has name ioBroker.adaptername (not iobroker.adaptername)');
356
- // }
357
-
358
- // const m = context.githubUrlOriginal.match(/\/ioBroker\.(.*)$/);
359
- // let adapterName = '';
360
- // if (!m || !m[1]) {
361
- // context.errors.push(`[E004] No adapter name found in URL: ${context.githubUrlOriginal}`);
362
- // } else {
363
- // context.checks.push('Adapter name found in the URL');
364
- // adapterName = m[1].replace(/\/master$/, '').replace(/\/main$/, '');
365
- // }
366
-
367
- // context.adapterName = adapterName;
368
-
369
- // if (adapterName.match(/[A-Z]/)) {
370
- // context.errors.push('[E005] Adapter name must be lowercase');
371
- // } else {
372
- // context.checks.push('Adapter name is lowercase');
373
- // }
374
-
375
- // if (adapterName.match(/[^-_a-z\d]/)) {
376
- // context.errors.push(`[E006] Invalid characters found in adapter name "${adapterName}". Only lowercase chars, digits, "-" and "_" are allowed`);
377
- // } else {
378
- // context.checks.push(`No invalid characters found in "${adapterName}"`);
379
- // }
380
-
381
- // if (adapterName.startsWith('_')) {
382
- // context.errors.push(`[E024] Adapter name "${adapterName}" may not start with '_'`);
383
- // } else {
384
- // context.checks.push(`Adapter name "${adapterName}" does not start with '_'`);
385
- // }
386
-
387
- // const n = context.githubUrlOriginal.match(/\/([^/]+)\/iobroker\./i);
388
- // if (!n || !n[1]) {
389
- // context.errors.push('[E007] Cannot find author repo in the URL');
390
- // } else {
391
- // context.authorName = n[1];
392
- // }
393
-
394
- // if (context.packageJson.name !== `iobroker.${adapterName.toLowerCase()}`) {
395
- // context.errors.push(`[E020] Name of adapter in package.json must be lowercase and be equal to "iobroker.${adapterName.toLowerCase()}". Now is "${packageJson.name}"`);
396
- // } else {
397
- // context.checks.push(`Name of adapter in package.json must be lowercase and be equal to "iobroker.${adapterName.toLowerCase()}".`);
398
- // }
399
-
400
- // if (!context.packageJson.version) {
401
- // context.errors.push('[E009] No version found in the package.json');
402
- // } else {
403
- // context.checks.push('Version found in package.json');
404
- // }
405
-
406
- // if (!context.packageJson.description) {
407
- // context.errors.push('[E010] No description found in the package.json');
408
- // } else {
409
- // context.checks.push('Description found in package.json');
410
- // }
411
-
412
- // if (context.packageJson.licenses) {
413
- // context.errors.push('[E021] "licenses" in package.json are deprecated. Please remove and use "license": "NAME" field.');
414
- // } else {
415
- // context.checks.push('No "licenses" found in package.json');
416
- // }
417
-
418
- // if (!context.packageJson.author) {
419
- // context.errors.push('[E013] No author found in the package.json');
420
- // } else {
421
- // context.checks.push('Author found in package.json');
422
- // }
423
-
424
- // if (context.packageJson._args) {
425
- // context.errors.push('[E014] NPM information found in package.json. Please remove all attributes starting with "_"');
426
- // } else {
427
- // context.checks.push('No npm generated attributes found in package.json');
428
- // }
429
-
430
- // if (!context.packageJson.license) {
431
- // context.errors.push('[E015] No license found in package.json');
432
- // } else {
433
- // context.checks.push('"license" found in package.json');
434
-
435
- // // check if license valid
436
- // if (!licenses.includes(context.packageJson.license)) {
437
- // 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/`);
438
- // } else {
439
- // context.checks.push('"license" is valid in package.json');
440
- // }
441
- // }
442
-
443
- // if (!context.packageJson.repository) {
444
- // context.errors.push('[E017] No repository found in the package.json');
445
- // } else {
446
- // context.checks.push('Repository found in package.json');
447
-
448
- // const allowedRepoUrls = [
449
- // context.githubApiData.html_url, // https://github.com/klein0r/ioBroker.luftdaten
450
- // `git+${context.githubApiData.html_url}`, // git+https://github.com/klein0r/ioBroker.luftdaten
451
- // context.githubApiData.git_url, // git://github.com/klein0r/ioBroker.luftdaten.git
452
- // context.githubApiData.ssh_url, // git@github.com:klein0r/ioBroker.luftdaten.git
453
- // context.githubApiData.clone_url, // https://github.com/klein0r/ioBroker.luftdaten.git
454
- // `git+${context.githubApiData.clone_url}` // git+https://github.com/klein0r/ioBroker.luftdaten.git
455
- // ];
456
-
457
- // // https://docs.npmjs.com/cli/v7/configuring-npm/package-json#repository
458
- // if (context.packageJson.repository && typeof context.packageJson.repository === 'object') {
459
- // if (context.packageJson.repository.type !== 'git') {
460
- // context.errors.push(`[E018] Invalid repository type in package.json: ${context.packageJson.repository.type}. It should be git`);
461
- // } else {
462
- // context.checks.push('Repository type is valid in package.json: git');
463
- // }
464
-
465
- // if (!allowedRepoUrls.includes(context.packageJson.repository.url)) {
466
- // context.errors.push(`[E019] Invalid repository URL in package.json: ${context.packageJson.repository.url}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
467
- // } else {
468
- // context.checks.push('Repository URL is valid in package.json');
469
- // }
470
- // } else if (context.packageJson.repository && typeof context.packageJson.repository === 'string') {
471
- // if (!allowedRepoUrls.includes(context.packageJson.repository)) {
472
- // context.errors.push(`[E019] Invalid repository URL in package.json: ${context.packageJson.repository}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
473
- // } else {
474
- // context.checks.push('Repository URL is valid in package.json');
475
- // }
476
- // } else {
477
- // context.errors.push('[E019] Invalid repository URL in package.json');
478
- // }
479
- // }
480
-
481
- // if (reservedAdapterNames.includes(adapterName)) {
482
- // context.errors.push('[E022] Adapter name is reserved. Please rename adapter.');
483
- // } else {
484
- // context.checks.push('Adapter name is not reserved');
485
- // }
486
-
487
- // if (!context.ioPackageJson.common.onlyWWW && !context.packageJson.dependencies) {
488
- // context.errors.push('[W030] No dependencies declared at package.json. Is this really correct?');
489
- // }
490
- // if (!context.packageJson.devDependencies) {
491
- // context.errors.push('[E031] No devDependencies declared at package.json. Please correct package.json');
492
- // }
493
-
494
- // if ((context.packageJson.dependencies && context.packageJson.dependencies.npm) || (context.packageJson.optionalDependencies && context.packageJson.optionalDependencies.npm)) {
495
- // context.errors.push('[E023] Do not include "npm" as dependency!');
496
- // } else {
497
- // context.checks.push('npm is not in dependencies');
498
- // }
499
-
500
- // if ((context.packageJson.dependencies && context.packageJson.dependencies['iobroker.js-controller']) ||
501
- // (context.packageJson.devDependencies && context.packageJson.devDependencies['iobroker.js-controller']) ||
502
- // (context.packageJson.optionalDependencies && context.packageJson.optionalDependencies['iobroker.js-controller'])
503
- // ) {
504
- // context.errors.push('[E025] Do not include "iobroker.js-controller" as dependency!');
505
- // } else {
506
- // context.checks.push('iobroker.js-controller is not in dependencies');
507
- // }
508
-
509
- // if (!context.ioPackageJson.common.onlyWWW) {
510
- // if (!context.packageJson.engines) {
511
- // context.errors.push(`[E026] "{'engines': {'node'>='${requiredNodeVersion}'}}" is required at package.json, "{'engines':{'node'>='${recommendedNodeVersion}'}}" is recommended`);
512
- // } else {
513
- // if (!context.packageJson.engines.node) {
514
- // context.errors.push(`[E026] "{'engines': {'node'>='${requiredNodeVersion}'}}" is required at package.json, "{'engines':{'node'>='${recommendedNodeVersion}'}}" is recommended`);
515
- // } else {
516
- // context.checks.push('engines attribute containing node requirements exist.');
517
- // // 'engines': { 'node': '>= 18' }
518
- // // 'engines': { 'node': '>= 18.1.2' }
519
- // // 'engines': { 'node': '>= 18.1.2 < 19' }
520
- // const nodeVal = context.packageJson.engines.node;
521
- // const match = nodeVal.match(/^\^(?<cmp>[<>=~]+)?\s*(?<vers>\d+(\.\d+(\.\d+)?)?(-\w+\.\d+)?)/m);
522
- // if ( ! match ) {
523
- // context.warnings.push(`[W027] {'engines' : { 'node' : '${nodeVal}' } }" is not parseable.`);
524
- // } else {
525
- // //console.log( `${JSON.stringify(match.groups)}`);
526
- // if ( match.groups.cmp !== '>' && match.groups.cmp !== '>=' ) {
527
- // context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
528
- // } else {
529
- // //console.log( `${match.groups.vers} - ${recommendedNodeVersion}`);
530
- // if ( ! compareVersions.compare( match.groups.vers, requiredNodeVersion, '>=')) {
531
- // 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.`);
532
- // } else if ( ! compareVersions.compare( match.groups.vers, recommendedNodeVersion, '>=')) {
533
- // context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
534
- // } else {
535
- // context.checks.push(`Correct node.js version ${match.groups.vers} requested by "engines" attribute at package.json.`);
536
- // }
537
- // }
538
- // }
539
- // }
540
- // }
541
- // } else {
542
- // context.checks.push('"engines" check skipped for wwwOnly adapter.');
543
- // }
544
-
545
- // if (!context.ioPackageJson.common.onlyWWW) {
546
- // for (const dependency in dependenciesPackageJson) {
547
- // const requiredVersion = dependenciesPackageJson[dependency].required;
548
- // const recommendedVersion = dependenciesPackageJson[dependency].recommended;
549
- // let dependencyVersion = context.packageJson.dependencies[`${dependency}`] || '';
550
- // dependencyVersion = dependencyVersion.replace(/[\^~]/,'' );
551
- // if (!dependencyVersion) {
552
- // context.errors.push(`[E032] No dependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to dependencies at package.json`);
553
- // } else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
554
- // context.errors.push(`[E033] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update dependencies at package.json`);
555
- // } else if (! compareVersions.compare( dependencyVersion, recommendedVersion, '>=' )) {
556
- // context.warnings.push(`[W034] ${dependency} ${dependencyVersion} specified. ${recommendedVersion} is recommended. Please consider updating dependencies at package.json`);
557
- // } else {
558
- // context.checks.push('dependency ${dependency} ${dependencyVersion} is ok');
559
- // }
560
- // }
561
- // context.checks.push('"dependenciesPackageJson" checked.');
562
- // } else {
563
- // context.checks.push('"dependenciesPackageJson" check skipped for wwwOnly adapter.');
564
- // }
565
-
566
- // for (const dependency in devDependenciesPackageJson) {
567
- // if ((devDependenciesPackageJson[dependency].onlyWWW === false) && context.ioPackageJson.common.onlyWWW) continue;
568
- // const requiredVersion = devDependenciesPackageJson[dependency].required;
569
- // const recommendedVersion = devDependenciesPackageJson[dependency].recommended;
570
- // let dependencyVersion = context.packageJson.devDependencies[`${dependency}`] || '';
571
- // dependencyVersion = dependencyVersion.replace(/[\^~]/,'' );
572
- // if (!dependencyVersion) {
573
- // context.errors.push(`[E035] No devDependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to devDependencies at package.json`);
574
- // } else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
575
- // context.errors.push(`[E036] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update devDependencies at package.json`);
576
- // } else if (! compareVersions.compare( dependencyVersion, recommendedVersion, '>=' )) {
577
- // context.warnings.push(`[W037] ${dependency} ${dependencyVersion} specified. ${recommendedVersion} is recommended. Please consider updating devDependencies at package.json`);
578
- // } else {
579
- // context.checks.push('devDependency ${dependency} ${dependencyVersion} is ok');
580
- // }
581
- // }
582
- // context.checks.push('"devDependenciesPackageJson" checked.');
583
-
584
- // const enforcedDependencies = [
585
- // '@iobroker/adapter-core',
586
- // '@alcalzone/release-script',
587
- // '@alcalzone/release-script-plugin-iobroker',
588
- // '@alcalzone/release-script-plugin-license',
589
- // '@alcalzone/release-script-manual-review',
590
- // '@iobroker/adapter-dev',
591
- // '@iobroker/testing'
592
- // ];
593
- // for (const dependency in context.packageJson.dependencies) {
594
- // if (!context.packageJson.dependencies[dependency].startsWith('^') &&
595
- // !context.packageJson.dependencies[dependency].startsWith('~') &&
596
- // !context.packageJson.dependencies[dependency].startsWith('>')
597
- // ) {
598
- // if (context.packageJson.dependencies[dependency].toLowerCase().includes('github.com')) {
599
- // context.warnings.push(`[W043] dependency should not require a github version. Please change "${dependency}:${context.packageJson.dependencies[dependency]}"`);
600
- // } else if (enforcedDependencies.includes(dependency)) {
601
- // context.errors.push(`[E044] dependency must not require a specific version. Use "~1.2.3" or "^1.2.3" syntax. Please update "${dependency}:${context.packageJson.dependencies[dependency]}"`);
602
- // } else {
603
- // context.warnings.push(`[W044] dependency should not require a specific version. Use "~1.2.3" or "^1.2.3" syntax. Please update "${dependency}:${context.packageJson.dependencies[dependency]}"`);
604
- // }
605
- // }
606
- // }
607
-
608
- // for (const dependency in context.packageJson.devDependencies) {
609
- // if (!context.packageJson.devDependencies[dependency].startsWith('^') &&
610
- // !context.packageJson.devDependencies[dependency].startsWith('~') &&
611
- // !context.packageJson.devDependencies[dependency].startsWith('>')
612
- // ) {
613
- // if (context.packageJson.devDependencies[dependency].toLowerCase().includes('github.com')) {
614
- // context.warnings.push(`[W045] devDependency should not require github versions. Please change "${dependency}:${context.packageJson.devDependencies[dependency]}"`);
615
- // } else if (enforcedDependencies.includes(dependency)) {
616
- // context.errors.push(`[E046] devDependency must not require a specific version. Use "~1.2.3" or "^1.2.3" syntax. Please update "${dependency}:${context.packageJson.devDependencies[dependency]}"`);
617
- // } else {
618
- // context.warnings.push(`[W046] devDependency should not require a specific version. Use "~1.2.3" or "^1.2.3" syntax. Please update "${dependency}:${context.packageJson.devDependencies[dependency]}"`);
619
- // }
620
- // }
621
- // }
622
-
623
- // for (const blacklist in blacklistPackageJson) {
624
- // // console.log(`checking blacklist ${blacklist}`);
625
- // let tmp = context.packageJson;
626
- // let log = '';
627
- // for (const element of blacklist.split('.')) {
628
- // log = `${log}.${element}`;
629
- // //console.log(` check ${log}`);
630
- // tmp = tmp[element];
631
- // if (!tmp) {
632
- // //console.log(` ${log} does not exist`);
633
- // break;
634
- // }
635
- // }
636
- // if (tmp) {
637
- // if (blacklistPackageJson[blacklist].err) {
638
- // context.errors.push(`[E038] ${blacklistPackageJson[blacklist].msg}`);
639
- // } else {
640
- // context.warnings.push(`[W038] ${blacklistPackageJson[blacklist].msg}`);
641
- // }
642
- // }
643
- // // else {
644
- // // console.log(`blacklist ${blacklist} no match`);
645
- // // }
646
- // }
647
- // context.checks.push('"blacklist (package)" checked.');
648
-
649
- // if (! context.packageJson.keywords) {
650
- // context.errors.push('[E039] "keywords" must be an array within package.json and contain some useful keywords');
651
- // } else if (!Array.isArray(context.packageJson.keywords)) {
652
- // context.errors.push('[E039] "keywords" must be an array within package.json and contain some useful keywords');
653
- // } else {
654
- // const forbiddenKeywords = [];
655
- // const ignoredKeywords = ['iobroker', 'smart home', 'smarthome', 'home automation', 'template'];
656
- // const recommendedKeywords = ['ioBroker'];
657
- // //console.log(`[DEBUG] package.keywords: "${context.packageJson.keywords.join(', ')}"`);
658
- // //console.log(`[DEBUG] filtered: "${context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase()))}"`);
659
- // if (context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase())).length === 0 ) {
660
- // context.errors.push(`[E039] "keywords" within package.json must contain some keywords besides "${context.packageJson.keywords.join(', ')}" related to adapter`);
661
- // }
662
- // if (! recommendedKeywords.filter(keyword => context.packageJson.keywords.includes(keyword)).length > 0) {
663
- // context.warnings.push(`[W040] "keywords" within package.json should contain "${recommendedKeywords.join(', ')}"`);
664
- // }
665
- // if (forbiddenKeywords.filter(keyword => context.packageJson.keywords.map(k => k.toLowerCase()).includes(keyword)).length > 0) {
666
- // context.warnings.push(`[W041] "keywords" within package.json should not contain "${forbiddenKeywords.join(', ')}"`);
667
- // }
668
-
669
- // context.checks.push('"keywords" found in package.json and refers to an array');
670
- // }
671
-
672
- // if (context.packageJson.globalDependencies) {
673
- // context.errors.push('[E042] "globalDependencies" is misplaced at package.json. Did you mean "common.globalDependencies" at io-package.json?');
674
- // } else {
675
- // context.checks.push('"globalDependencies" not found in package.json');
676
- // }
677
-
678
- // // max number is W046
679
-
680
- // return context;
681
- // });
682
- // }
683
-
684
- // const allowedLanguages = [
685
- // 'en',
686
- // 'de',
687
- // 'ru',
688
- // 'pt',
689
- // 'nl',
690
- // 'fr',
691
- // 'it',
692
- // 'es',
693
- // 'pl',
694
- // 'uk',
695
- // 'zh-cn'
696
- // ];
697
-
698
- // const requiredLanguages = [
699
- // 'en',
700
- // 'de',
701
- // // 'xx' // TESTING ONLY
702
- // ];
703
-
704
- // const allowedModes = {
705
- // 'none': 'this adapter will not be started',
706
- // 'daemon': 'always running process (will be restarted if process exits)',
707
- // 'schedule': 'is started by schedule found in system.adapter…common.schedule - reacts on changes of .schedule by rescheduling with new state',
708
- // 'once': 'his adapter will be started every time the system.adapter.. object changed. It will not be restarted after termination.',
709
- // 'extension': ''
710
- // };
711
-
712
- // const allowedTypes = {
713
- // 'alarm': 'security of home, car, boat, ...',
714
- // 'climate-control': 'climate, heaters, air filters, water heaters, ...',
715
- // 'communication': 'deliver data for other services via RESTapi, websockets',
716
- // 'date-and-time': 'schedules, calendars, ...',
717
- // 'energy': 'energy metering',
718
- // 'metering': 'other, but energy metering (water, gas, oil, ...)',
719
- // 'garden': 'mower, springs, ...',
720
- // 'general': 'general purpose adapters, like admin, web, discovery, ...',
721
- // 'geoposition': 'geo-positioning. These adapters deliver or accept the position of other objects or persons.',
722
- // 'hardware': 'different multi-purpose hardware, arduino, esp, bluetooth, ...',
723
- // 'household': 'vacuum-cleaner, kitchen devices, ...',
724
- // 'health': 'Fitness sensors, scales, blood pressure, ...',
725
- // 'infrastructure': 'Network, printers, phones, NAS, ...',
726
- // 'iot-systems': 'Other comprehensive smarthome systems (software and hardware)',
727
- // 'lighting': 'light',
728
- // 'logic': 'rules, scripts, parsers, scenes, ...',
729
- // 'messaging': 'these adapters send and receive messages from message services: telegram, email, whatsapp, ...',
730
- // 'misc-data': 'export/import of some unsorted information, contacts, systeminfo, gazoline prises, share curses, currents (EUR=>USD), ...',
731
- // 'multimedia': 'TV, AV Receivers, TV play boxes, Android/apple TV boxes, multi-room music, IR controls, speech input/output, ...',
732
- // 'network': 'ping, network detectors, UPnP, ...',
733
- // 'protocols': 'Communication protocols: MQTT,',
734
- // 'storage': 'logging, data protocols, SQL/NoSQL DBs, file storage, ...',
735
- // 'utility': 'different help adapters. Like backup, export/import',
736
- // 'vehicle': 'cars',
737
- // 'visualization': 'visualisation, like vis, material, mobile',
738
- // 'visualization-icons': 'icons for visualisation',
739
- // 'visualization-widgets': 'iobroker.vis widgets',
740
- // 'weather': 'weather info, air quality, environment statistics'
741
- // };
742
-
743
- // const reservedAdapterNames = [
744
- // 'config',
745
- // 'system',
746
- // 'alias',
747
- // 'design',
748
- // 'all',
749
- // 'enum',
750
- // 'this',
751
- // 'self',
752
- // '0_userdata',
753
- // '_design',
754
- // ];
755
-
756
- // const licenses = [
757
- // '0BSD',
758
- // 'AAL',
759
- // 'Abstyles',
760
- // 'Adobe-2006',
761
- // 'Adobe-Glyph',
762
- // 'ADSL',
763
- // 'AFL-1.1',
764
- // 'AFL-1.2',
765
- // 'AFL-2.0',
766
- // 'AFL-2.1',
767
- // 'AFL-3.0',
768
- // 'Afmparse',
769
- // 'AGPL-1.0-only',
770
- // 'AGPL-1.0-or-later',
771
- // 'AGPL-3.0-only',
772
- // 'AGPL-3.0-or-later',
773
- // 'Aladdin',
774
- // 'AMDPLPA',
775
- // 'AML',
776
- // 'AMPAS',
777
- // 'ANTLR-PD',
778
- // 'Apache-1.0',
779
- // 'Apache-1.1',
780
- // 'Apache-2.0',
781
- // 'APAFML',
782
- // 'APL-1.0',
783
- // 'APSL-1.0',
784
- // 'APSL-1.1',
785
- // 'APSL-1.2',
786
- // 'APSL-2.0',
787
- // 'Artistic-1.0-cl8',
788
- // 'Artistic-1.0-Perl',
789
- // 'Artistic-1.0',
790
- // 'Artistic-2.0',
791
- // 'Bahyph',
792
- // 'Barr',
793
- // 'Beerware',
794
- // 'BitTorrent-1.0',
795
- // 'BitTorrent-1.1',
796
- // 'Borceux',
797
- // 'BSD-1-Clause',
798
- // 'BSD-2-Clause-FreeBSD',
799
- // 'BSD-2-Clause-NetBSD',
800
- // 'BSD-2-Clause-Patent',
801
- // 'BSD-2-Clause',
802
- // 'BSD-3-Clause-Attribution',
803
- // 'BSD-3-Clause-Clear',
804
- // 'BSD-3-Clause-LBNL',
805
- // 'BSD-3-Clause-No-Nuclear-License-2014',
806
- // 'BSD-3-Clause-No-Nuclear-License',
807
- // 'BSD-3-Clause-No-Nuclear-Warranty',
808
- // 'BSD-3-Clause',
809
- // 'BSD-4-Clause-UC',
810
- // 'BSD-4-Clause',
811
- // 'BSD-Protection',
812
- // 'BSD-Source-Code',
813
- // 'BSL-1.0',
814
- // 'bzip2-1.0.5',
815
- // 'bzip2-1.0.6',
816
- // 'Caldera',
817
- // 'CATOSL-1.1',
818
- // 'CC-BY-1.0',
819
- // 'CC-BY-2.0',
820
- // 'CC-BY-2.5',
821
- // 'CC-BY-3.0',
822
- // 'CC-BY-4.0',
823
- // 'CC-BY-NC-1.0',
824
- // 'CC-BY-NC-2.0',
825
- // 'CC-BY-NC-2.5',
826
- // 'CC-BY-NC-3.0',
827
- // 'CC-BY-NC-4.0',
828
- // 'CC-BY-NC-ND-1.0',
829
- // 'CC-BY-NC-ND-2.0',
830
- // 'CC-BY-NC-ND-2.5',
831
- // 'CC-BY-NC-ND-3.0',
832
- // 'CC-BY-NC-ND-4.0',
833
- // 'CC-BY-NC-SA-1.0',
834
- // 'CC-BY-NC-SA-2.0',
835
- // 'CC-BY-NC-SA-2.5',
836
- // 'CC-BY-NC-SA-3.0',
837
- // 'CC-BY-NC-SA-4.0',
838
- // 'CC-BY-ND-1.0',
839
- // 'CC-BY-ND-2.0',
840
- // 'CC-BY-ND-2.5',
841
- // 'CC-BY-ND-3.0',
842
- // 'CC-BY-ND-4.0',
843
- // 'CC-BY-SA-1.0',
844
- // 'CC-BY-SA-2.0',
845
- // 'CC-BY-SA-2.5',
846
- // 'CC-BY-SA-3.0',
847
- // 'CC-BY-SA-4.0',
848
- // 'CC0-1.0',
849
- // 'CDDL-1.0',
850
- // 'CDDL-1.1',
851
- // 'CDLA-Permissive-1.0',
852
- // 'CDLA-Sharing-1.0',
853
- // 'CECILL-1.0',
854
- // 'CECILL-1.1',
855
- // 'CECILL-2.0',
856
- // 'CECILL-2.1',
857
- // 'CECILL-B',
858
- // 'CECILL-C',
859
- // 'ClArtistic',
860
- // 'CNRI-Jython',
861
- // 'CNRI-Python-GPL-Compatible',
862
- // 'CNRI-Python',
863
- // 'Condor-1.1',
864
- // 'copyleft-next-0.3.0',
865
- // 'copyleft-next-0.3.1',
866
- // 'CPAL-1.0',
867
- // 'CPL-1.0',
868
- // 'CPOL-1.02',
869
- // 'Crossword',
870
- // 'CrystalStacker',
871
- // 'CUA-OPL-1.0',
872
- // 'Cube',
873
- // 'curl',
874
- // 'D-FSL-1.0',
875
- // 'diffmark',
876
- // 'DOC',
877
- // 'Dotseqn',
878
- // 'DSDP',
879
- // 'dvipdfm',
880
- // 'ECL-1.0',
881
- // 'ECL-2.0',
882
- // 'EFL-1.0',
883
- // 'EFL-2.0',
884
- // 'eGenix',
885
- // 'Entessa',
886
- // 'EPL-1.0',
887
- // 'EPL-2.0',
888
- // 'ErlPL-1.1',
889
- // 'EUDatagrid',
890
- // 'EUPL-1.0',
891
- // 'EUPL-1.1',
892
- // 'EUPL-1.2',
893
- // 'Eurosym',
894
- // 'Fair',
895
- // 'Frameworx-1.0',
896
- // 'FreeImage',
897
- // 'FSFAP',
898
- // 'FSFUL',
899
- // 'FSFULLR',
900
- // 'FTL',
901
- // 'GFDL-1.1-only',
902
- // 'GFDL-1.1-or-later',
903
- // 'GFDL-1.2-only',
904
- // 'GFDL-1.2-or-later',
905
- // 'GFDL-1.3-only',
906
- // 'GFDL-1.3-or-later',
907
- // 'Giftware',
908
- // 'GL2PS',
909
- // 'Glide',
910
- // 'Glulxe',
911
- // 'gnuplot',
912
- // 'GPL-1.0-only',
913
- // 'GPL-1.0-or-later',
914
- // 'GPL-2.0-only',
915
- // 'GPL-2.0-or-later',
916
- // 'GPL-3.0-only',
917
- // 'GPL-3.0-or-later',
918
- // 'gSOAP-1.3b',
919
- // 'HaskellReport',
920
- // 'HPND',
921
- // 'IBM-pibs',
922
- // 'ICU',
923
- // 'IJG',
924
- // 'ImageMagick',
925
- // 'iMatix',
926
- // 'Imlib2',
927
- // 'Info-ZIP',
928
- // 'Intel-ACPI',
929
- // 'Intel',
930
- // 'Interbase-1.0',
931
- // 'IPA',
932
- // 'IPL-1.0',
933
- // 'ISC',
934
- // 'JasPer-2.0',
935
- // 'JSON',
936
- // 'LAL-1.2',
937
- // 'LAL-1.3',
938
- // 'Latex2e',
939
- // 'Leptonica',
940
- // 'LGPL-2.0-only',
941
- // 'LGPL-2.0-or-later',
942
- // 'LGPL-2.1-only',
943
- // 'LGPL-2.1-or-later',
944
- // 'LGPL-3.0-only',
945
- // 'LGPL-3.0-or-later',
946
- // 'LGPLLR',
947
- // 'Libpng',
948
- // 'libtiff',
949
- // 'LiLiQ-P-1.1',
950
- // 'LiLiQ-R-1.1',
951
- // 'LiLiQ-Rplus-1.1',
952
- // 'Linux-OpenIB',
953
- // 'LPL-1.0',
954
- // 'LPL-1.02',
955
- // 'LPPL-1.0',
956
- // 'LPPL-1.1',
957
- // 'LPPL-1.2',
958
- // 'LPPL-1.3a',
959
- // 'LPPL-1.3c',
960
- // 'MakeIndex',
961
- // 'MirOS',
962
- // 'MIT-0',
963
- // 'MIT-advertising',
964
- // 'MIT-CMU',
965
- // 'MIT-enna',
966
- // 'MIT-feh',
967
- // 'MIT',
968
- // 'MITNFA',
969
- // 'Motosoto',
970
- // 'mpich2',
971
- // 'MPL-1.0',
972
- // 'MPL-1.1',
973
- // 'MPL-2.0-no-copyleft-exception',
974
- // 'MPL-2.0',
975
- // 'MS-PL',
976
- // 'MS-RL',
977
- // 'MTLL',
978
- // 'Multics',
979
- // 'Mup',
980
- // 'NASA-1.3',
981
- // 'Naumen',
982
- // 'NBPL-1.0',
983
- // 'NCSA',
984
- // 'Net-SNMP',
985
- // 'NetCDF',
986
- // 'Newsletr',
987
- // 'NGPL',
988
- // 'NLOD-1.0',
989
- // 'NLPL',
990
- // 'Nokia',
991
- // 'NOSL',
992
- // 'Noweb',
993
- // 'NPL-1.0',
994
- // 'NPL-1.1',
995
- // 'NPOSL-3.0',
996
- // 'NRL',
997
- // 'NTP',
998
- // 'OCCT-PL',
999
- // 'OCLC-2.0',
1000
- // 'ODbL-1.0',
1001
- // 'ODC-By-1.0',
1002
- // 'OFL-1.0',
1003
- // 'OFL-1.1',
1004
- // 'OGL-UK-1.0',
1005
- // 'OGL-UK-2.0',
1006
- // 'OGL-UK-3.0',
1007
- // 'OGTSL',
1008
- // 'OLDAP-1.1',
1009
- // 'OLDAP-1.2',
1010
- // 'OLDAP-1.3',
1011
- // 'OLDAP-1.4',
1012
- // 'OLDAP-2.0.1',
1013
- // 'OLDAP-2.0',
1014
- // 'OLDAP-2.1',
1015
- // 'OLDAP-2.2.1',
1016
- // 'OLDAP-2.2.2',
1017
- // 'OLDAP-2.2',
1018
- // 'OLDAP-2.3',
1019
- // 'OLDAP-2.4',
1020
- // 'OLDAP-2.5',
1021
- // 'OLDAP-2.6',
1022
- // 'OLDAP-2.7',
1023
- // 'OLDAP-2.8',
1024
- // 'OML',
1025
- // 'OpenSSL',
1026
- // 'OPL-1.0',
1027
- // 'OSET-PL-2.1',
1028
- // 'OSL-1.0',
1029
- // 'OSL-1.1',
1030
- // 'OSL-2.0',
1031
- // 'OSL-2.1',
1032
- // 'OSL-3.0',
1033
- // 'PDDL-1.0',
1034
- // 'PHP-3.0',
1035
- // 'PHP-3.01',
1036
- // 'Plexus',
1037
- // 'PostgreSQL',
1038
- // 'psfrag',
1039
- // 'psutils',
1040
- // 'Python-2.0',
1041
- // 'Qhull',
1042
- // 'QPL-1.0',
1043
- // 'Rdisc',
1044
- // 'RHeCos-1.1',
1045
- // 'RPL-1.1',
1046
- // 'RPL-1.5',
1047
- // 'RPSL-1.0',
1048
- // 'RSA-MD',
1049
- // 'RSCPL',
1050
- // 'Ruby',
1051
- // 'SAX-PD',
1052
- // 'Saxpath',
1053
- // 'SCEA',
1054
- // 'Sendmail-8.23',
1055
- // 'Sendmail',
1056
- // 'SGI-B-1.0',
1057
- // 'SGI-B-1.1',
1058
- // 'SGI-B-2.0',
1059
- // 'SimPL-2.0',
1060
- // 'SISSL-1.2',
1061
- // 'SISSL',
1062
- // 'Sleepycat',
1063
- // 'SMLNJ',
1064
- // 'SMPPL',
1065
- // 'SNIA',
1066
- // 'Spencer-86',
1067
- // 'Spencer-94',
1068
- // 'Spencer-99',
1069
- // 'SPL-1.0',
1070
- // 'SugarCRM-1.1.3',
1071
- // 'SWL',
1072
- // 'TCL',
1073
- // 'TCP-wrappers',
1074
- // 'TMate',
1075
- // 'TORQUE-1.1',
1076
- // 'TOSL',
1077
- // 'TU-Berlin-1.0',
1078
- // 'TU-Berlin-2.0',
1079
- // 'Unicode-DFS-2015',
1080
- // 'Unicode-DFS-2016',
1081
- // 'Unicode-TOU',
1082
- // 'Unlicense',
1083
- // 'UPL-1.0',
1084
- // 'Vim',
1085
- // 'VOSTROM',
1086
- // 'VSL-1.0',
1087
- // 'W3C-19980720',
1088
- // 'W3C-20150513',
1089
- // 'W3C',
1090
- // 'Watcom-1.0',
1091
- // 'Wsuipa',
1092
- // 'WTFPL',
1093
- // 'X11',
1094
- // 'Xerox',
1095
- // 'XFree86-1.1',
1096
- // 'xinetd',
1097
- // 'Xnet',
1098
- // 'xpp',
1099
- // 'XSkat',
1100
- // 'YPL-1.0',
1101
- // 'YPL-1.1',
1102
- // 'Zed',
1103
- // 'Zend-2.0',
1104
- // 'Zimbra-1.3',
1105
- // 'ZPL-1.1',
1106
- // 'ZPL-2.0',
1107
- // 'ZPL-2.1',
1108
- // ];
1109
-
1110
- // // E1xx
1111
- // function checkIOPackageJson(context) {
1112
- // context = context || {};
1113
- // return new Promise(resolve => {
1114
- // console.log('\ncheckIOPackageJson [E1xx]');
1115
- // if (context.ioPackageJson) {
1116
- // return resolve(context.ioPackageJson);
1117
- // } else {
1118
- // throw ('io-package.json not loaded');
1119
- // }
1120
- // })
1121
- // .then(ioPackageJson => {
1122
- // return new Promise(resolve => {
1123
- // context.ioPackageJson = ioPackageJson;
1124
- // if (typeof context.ioPackageJson === 'string') {
1125
- // try {
1126
- // context.ioPackageJson = JSON.parse(context.ioPackageJson);
1127
- // } catch (e) {
1128
- // context.errors.push(`[E100] Cannot parse io-package.json: ${e}`);
1129
- // return resolve(context);
1130
- // }
1131
- // }
1132
-
1133
- // if (!context.ioPackageJson.native) {
1134
- // context.errors.push('[E101] io-package.json must have at least empty "native" attribute');
1135
- // } else {
1136
- // context.checks.push('"native" found in io-package.json');
1137
-
1138
- // // Generic check for potential credentials that should have a counterpart in encryptedNative/protectedNative
1139
- // const suspiciousPhrases = [
1140
- // 'apikey',
1141
- // 'api_key',
1142
- // 'credential',
1143
- // 'pass',
1144
- // 'passwd',
1145
- // 'password',
1146
- // 'passwort',
1147
- // 'pin',
1148
- // 'private_pw',
1149
- // 'psk',
1150
- // 'pwd',
1151
- // 'secret',
1152
- // 'token',
1153
- // ];
1154
- // //const regex = new RegExp(suspiciousPhrases.join('|'), 'i');
1155
-
1156
- // let suspiciousKeys = Object.keys(context.ioPackageJson.native) || [];
1157
- // // console.log(`native keys: ${suspiciousKeys.join()}`);
1158
- // //suspiciousKeys = suspiciousKeys.filter( key => regex.test(key));
1159
- // suspiciousKeys = suspiciousKeys.filter( key => suspiciousPhrases.includes(key.toLowerCase()));
1160
- // // console.log(`suspicious keys: ${suspiciousKeys.join()}`);
1161
-
1162
- // if ( suspiciousKeys.length) {
1163
- // if (context.ioPackageJson.protectedNative) {
1164
- // const missingProtected = suspiciousKeys.filter( key => !context.ioPackageJson.protectedNative.includes(key));
1165
- // if (missingProtected.length) context.warnings.push( `[W173] Potential sensitive data "${missingProtected.join()}" not listed at "protectedNative" in io-package.json`);
1166
- // } else {
1167
- // context.warnings.push( `[W173] Potential sensitive data "${suspiciousKeys.join()}" not listed at "protectedNative" in io-package.json`);
1168
- // }
1169
-
1170
- // if (context.ioPackageJson.encryptedNative) {
1171
- // const missingProtected = suspiciousKeys.filter( key => !context.ioPackageJson.encryptedNative.includes(key));
1172
- // if (missingProtected.length) context.warnings.push( `[W174] Potential sensitive data "${missingProtected.join()}" not listed at "encryptedNative" in io-package.json`);
1173
- // } else {
1174
- // context.warnings.push( `[W174] Potential sensitive data "${suspiciousKeys.join()}" not listed at "encryptedNative" in io-package.json`);
1175
- // }
1176
- // }
1177
- // }
1178
-
1179
- // if (!context.ioPackageJson.common) {
1180
- // context.errors.push('[E102] io-package.json must have common object');
1181
- // return resolve(context);
1182
- // } else {
1183
- // context.checks.push('"common" found in io-package.json');
1184
- // if (!context.ioPackageJson.common.name || context.ioPackageJson.common.name !== context.adapterName.toLowerCase()) {
1185
- // context.errors.push(`[E103] "common.name" in io-package.json must be equal to "${context.adapterName.toLowerCase()}'". Now is ${context.ioPackageJson.common.name}`);
1186
- // } else {
1187
- // context.checks.push('"common.name" is valid in io-package.json');
1188
- // }
1189
-
1190
- // /*
1191
- // if (context.ioPackageJson.common.title) {
1192
- // context.warnings.push('[W171] "common.title" is deprecated in io-package.json. Please remove from io-package.json.');
1193
- // }
1194
-
1195
- // if (context.ioPackageJson.common.main) {
1196
- // 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.');
1197
- // }
1198
-
1199
- // if (context.ioPackageJson.common.materialize) {
1200
- // context.warnings.push('[W178] "common.materialize" is deprecated in io-package.json. For admin version >= 5 please use the property "common.adminUI"');
1201
- // }
1202
-
1203
- // if (context.ioPackageJson.common.materializeTab) {
1204
- // context.warnings.push('[W179] "common.materializeTab" is deprecated in io-package.json. For admin version >= 5 please use the property "common.adminUI".');
1205
- // }
1206
-
1207
- // if (context.ioPackageJson.common.noConfig) {
1208
- // context.warnings.push('[W180] "common.noConfig" is deprecated in io-package.json. For admin version >= 5 please use "common.adminUI.config":"none".');
1209
- // }
1210
- // */
1211
- // if (!context.ioPackageJson.common.titleLang) {
1212
- // context.errors.push('[E104] No "common.titleLang" found in io-package.json');
1213
- // } else {
1214
- // context.checks.push('"common.titleLang" found in io-package.json');
1215
-
1216
- // if (typeof context.ioPackageJson.common.titleLang !== 'object') {
1217
- // context.errors.push(`[E105] "common.titleLang" must be an object. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
1218
- // } else {
1219
- // let missingLang = checkLanguages(context.ioPackageJson.common.titleLang, requiredLanguages);
1220
- // if (missingLang.length) {
1221
- // context.warnings.push(`[W105] Missing mandatory translation into ${missingLang.join()} of "common.titleLang" in io-package.json.`);
1222
- // }
1223
-
1224
- // missingLang = checkLanguages(context.ioPackageJson.common.titleLang, allowedLanguages);
1225
- // missingLang = missingLang.filter( lang => !requiredLanguages.includes(lang));
1226
- // if (missingLang.length) {
1227
- // missingLang = [... new Set(missingLang)]; // make unique
1228
- // context.warnings.push(`[W105] Missing suggested translation into ${missingLang.join()} of "common.titleLang" in io-package.json.`);
1229
- // }
1230
- // }
1231
-
1232
- // Object.keys(context.ioPackageJson.common.titleLang).forEach(lang => {
1233
- // const text = context.ioPackageJson.common.titleLang[lang];
1234
- // if (text.match(/iobroker/i)) {
1235
- // context.errors.push(`[E106] "common.titleLang" must not have ioBroker in the name. It is clear, for what this adapter was created. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
1236
- // } else {
1237
- // context.checks.push('"common.titleLang" has no ioBroker in it in io-package.json');
1238
- // }
1239
-
1240
- // if (text.match(/\sadapter|adapter\s/i)) {
1241
- // context.warnings.push(`[W106] "common.titleLang" should not contain word "adapter" in the name. It is clear, that this is adapter. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
1242
- // } else {
1243
- // context.checks.push('"common.titleLang" has no "adapter" in it in io-package.json');
1244
- // }
1245
- // });
1246
- // }
1247
-
1248
- // if (!context.ioPackageJson.common.version) {
1249
- // context.errors.push('[E107] No "common.version" found in io-package.json');
1250
- // } else {
1251
- // context.checks.push('"common.version" found in io-package.json');
1252
-
1253
- // if (!context.packageJson || context.ioPackageJson.common.version !== context.packageJson.version) {
1254
- // context.errors.push('[E118] Versions in package.json and in io-package.json are different');
1255
- // } else {
1256
- // context.checks.push('"common.version" is equal in package.json adn in io-package.json');
1257
- // }
1258
- // }
1259
-
1260
- // if (!context.ioPackageJson.common.desc) {
1261
- // context.errors.push('[E108] No "common.desc" found in io-package.json');
1262
- // } else {
1263
- // context.checks.push('"common.desc" found in io-package.json');
1264
-
1265
- // if (typeof context.ioPackageJson.common.desc !== 'object') {
1266
- // context.errors.push(`[E109] "common.desc" in io-package.json should be an object for many languages. Found only "${context.ioPackageJson.common.desc}"`);
1267
- // } else {
1268
-
1269
- // let missingLang = checkLanguages(context.ioPackageJson.common.desc, requiredLanguages);
1270
- // if (missingLang.length) {
1271
- // context.warnings.push(`[E109] Missing mandatory translation into ${missingLang.join()} of "common.desc" in io-package.json.`);
1272
- // }
1273
-
1274
- // missingLang = checkLanguages(context.ioPackageJson.common.desc, allowedLanguages);
1275
- // missingLang = missingLang.filter( lang => !requiredLanguages.includes(lang));
1276
- // if (missingLang.length) {
1277
- // missingLang = [... new Set(missingLang)]; // make unique
1278
- // context.warnings.push(`[W109] Missing suggested translation into ${missingLang.join()} of "common.desc" in io-package.json.`);
1279
- // }
1280
- // }
1281
- // }
1282
-
1283
- // if (! context.ioPackageJson.common.keywords) {
1284
- // context.errors.push('[E169] "common.keywords" must be an array within io-package.json and contain some useful keywords');
1285
- // } else {
1286
- // const forbiddenKeywords = ['iobroker', 'adapter', 'smart home'];
1287
- // if (!Array.isArray(context.ioPackageJson.common.keywords)) {
1288
- // context.errors.push('[E169] "common.keywords" must be an array within io-package.json and contain some useful keywords');
1289
- // } else if (context.ioPackageJson.common.keywords.length === 0) {
1290
- // context.errors.push('[E169] "common.keywords" must be an array within io-package.json and contain some useful keywords');
1291
- // } else if (forbiddenKeywords.filter(keyword => context.ioPackageJson.common.keywords.map(k => k.toLowerCase()).includes(keyword)).length > 0) {
1292
- // context.warnings.push(`[W170] "common.keywords" should not contain "${forbiddenKeywords.join(', ')}" io-package.json`);
1293
- // }
1294
-
1295
- // context.checks.push('"common.keywords" found in io-package.json');
1296
- // }
1297
-
1298
- // if (!context.ioPackageJson.common.icon) {
1299
- // context.errors.push('[E110] Icon not found in the io-package.json');
1300
- // } else {
1301
- // context.checks.push('"common.icon" found in io-package.json');
1302
- // }
1303
-
1304
- // if (!context.ioPackageJson.common.extIcon) {
1305
- // context.errors.push('[E111] extIcon not found in the io-package.json');
1306
- // } else {
1307
- // context.checks.push('"common.extIcon" found in io-package.json');
1308
-
1309
- // // extract icon name
1310
- // let fileName = context.ioPackageJson.common.extIcon;
1311
- // let pos = fileName.indexOf('?');
1312
-
1313
- // if (pos !== -1) {
1314
- // fileName = fileName.substring(0, pos);
1315
- // }
1316
- // pos = fileName.lastIndexOf('/');
1317
- // fileName = fileName.substring(pos + 1, fileName.length);
1318
-
1319
- // if (fileName !== context.ioPackageJson.common.icon) {
1320
- // context.errors.push('[E112] extIcon must be the same as an icon but with github path');
1321
- // } else {
1322
- // context.checks.push('"common.extIcon" has same path as repo in io-package.json');
1323
- // }
1324
- // }
1325
-
1326
- // if (!context.ioPackageJson.common.compact && !context.ioPackageJson.common.onlyWWW) {
1327
- // context.warnings.push('[W113] Adapter should support compact mode');
1328
- // } else if (!context.ioPackageJson.common.onlyWWW) {
1329
- // context.checks.push('"common.compact" found in io-package.json');
1330
- // }
1331
-
1332
- // if (context.ioPackageJson.common.noConfig &&
1333
- // (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config !== 'none')
1334
- // ) {
1335
- // context.errors.push('[E114] "common.noConfig=true" requires "common.adminUI.config" to be set to "none"' );
1336
- // }
1337
- // if (!context.ioPackageJson.common.materialize &&
1338
- // !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') &&
1339
- // !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize') &&
1340
- // !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'html') &&
1341
- // !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'none')
1342
- // ) {
1343
- // context.errors.push('[E114] Admin support not specified. Please add "common.adminUI.config = json|materialize|html|none"');
1344
- // } else {
1345
- // context.checks.push('"common.materialize" or valid "common.adminUI.config:xxx" found in io-package.json');
1346
- // }
1347
-
1348
- // if (context.ioPackageJson.common.license) {
1349
- // context.warnings.push('[W181] "common.license" in io-package.json is deprecated. Please define object "common.licenseInformation"');
1350
- // }
1351
-
1352
- // if (!context.ioPackageJson.common.licenseInformation) {
1353
- // if (!context.ioPackageJson.common.license) {
1354
- // context.errors.push('[E115] "common.licenseInformation" not found in io-package.json');
1355
- // }
1356
- // } else {
1357
- // context.checks.push('"common.licenseInformation" found in io-package.json');
1358
-
1359
- // if (context.ioPackageJson.common.license) {
1360
- // context.errors.push('[E182] Please remove "common.license" from io-package.json as "common.licenseInformation" is declared.');
1361
- // }
1362
-
1363
- // // check if license valid
1364
- // if (!context.ioPackageJson.common.licenseInformation.license) {
1365
- // context.errors.push('[E183] "common.licenseInformation.license" is missing');
1366
- // } else if (!licenses.includes(context.ioPackageJson.common?.licenseInformation?.license)) {
1367
- // context.errors.push('[E116] No SPDX license found at "common.licenseInformation". Please use one of listed here: https://spdx.org/licenses/');
1368
- // } else {
1369
- // context.checks.push('"common.licenseInformation" is valid in io-package.json');
1370
- // }
1371
-
1372
- // // check if type is valid
1373
- // if (!['free', 'paid', 'commercial', 'limited'].includes(context.ioPackageJson.common?.licenseInformation?.type)) {
1374
- // context.errors.push('[E170] "common.licenseInformation.type" is invalid. Select valid type (e.g. free)');
1375
- // } else {
1376
- // context.checks.push('"common.licenseInformation.type" is valid in io-package.json');
1377
-
1378
- // if (['paid', 'commercial', 'limited'].includes(context.ioPackageJson.common?.licenseInformation?.type)) {
1379
- // if (!context.ioPackageJson.common?.licenseInformation?.link) {
1380
- // context.errors.push('[E171] "common.licenseInformation.link" is required for non-free adapters');
1381
- // } else {
1382
- // context.checks.push('"common.licenseInformation.link" is valid in io-package.json');
1383
- // }
1384
- // }
1385
- // }
1386
-
1387
- // if (!context.packageJson ||
1388
- // context.ioPackageJson.common?.licenseInformation?.license !== context.packageJson.license) {
1389
- // context.errors.push('[E117] Licenses in package.json and in io-package.json are different');
1390
- // } else {
1391
- // context.checks.push('"common.licenseInformation.license" is equal in package.json and in io-package.json');
1392
- // }
1393
- // }
1394
-
1395
- // if (!context.ioPackageJson.common.mode) {
1396
- // context.errors.push('[E165] "common.mode" not found in io-package.json');
1397
- // } else {
1398
- // context.checks.push('"common.mode" found in io-package.json');
1399
-
1400
- // if (!allowedModes[context.ioPackageJson.common.mode]) {
1401
- // context.errors.push(`[E166] "common.mode: ${context.ioPackageJson.common.mode}" is unknown in io-package.json.`);
1402
- // } else {
1403
- // context.checks.push('"common.mode" has known mode in io-package.json');
1404
-
1405
- // if (context.ioPackageJson.common.onlyWWW && context.ioPackageJson.common.mode !== 'none') {
1406
- // context.errors.push('[E162] onlyWWW should have common.mode "none" in io-package.json');
1407
- // }
1408
-
1409
- // if (context.ioPackageJson.common.mode === 'schedule' && !context.ioPackageJson.common.schedule) {
1410
- // context.errors.push('[E167] scheduled adapters must have "common.schedule" property in io-package.json');
1411
- // }
1412
- // }
1413
- // }
1414
-
1415
- // if (!context.ioPackageJson.common.type) {
1416
- // context.errors.push('[E119] No type found in io-package.json');
1417
- // } else {
1418
- // context.checks.push('"common.type" found in io-package.json');
1419
-
1420
- // if (!allowedTypes[context.ioPackageJson.common.type]) {
1421
- // context.errors.push('[E120] Unknown type found in io-package.json');
1422
- // } else {
1423
- // context.checks.push('"common.type" has known type in io-package.json');
1424
- // }
1425
- // }
1426
-
1427
- // if (!context.ioPackageJson.common.authors) {
1428
- // context.errors.push('[E121] No authors found in io-package.json');
1429
- // } else {
1430
- // context.checks.push('"common.authors" found in io-package.json');
1431
-
1432
- // if (!(context.ioPackageJson.common.authors instanceof Array)) {
1433
- // context.errors.push('[E122] authors must be an Array in io-package.json');
1434
- // } else {
1435
- // context.checks.push('"common.authors" is array in io-package.json');
1436
- // }
1437
-
1438
- // if (!context.ioPackageJson.common.authors.length) {
1439
- // context.errors.push('[E123] Authors may not be empty in io-package.json');
1440
- // } else {
1441
- // context.checks.push('"common.authors" is not empty in io-package.json');
1442
- // }
1443
- // }
1444
-
1445
- // if (context.ioPackageJson.common.localLink) {
1446
- // context.warnings.push('[W172] "common.localLink" in io-package.json is deprecated. Please define object "common.localLinks": { "_default": "..." }');
1447
- // } else {
1448
- // context.checks.push('No "common.localLink" found in io-package.json');
1449
- // }
1450
-
1451
- // if (!context.ioPackageJson.common.news) {
1452
- // context.errors.push('[E130] No "common.news" found in io-package.json');
1453
- // } else {
1454
- // context.checks.push('"common.news" found in io-package.json');
1455
-
1456
- // if (Object.keys(context.ioPackageJson.common.news).length > 20) {
1457
- // context.errors.push('[E130] Too many "common.news" found in io-package.json. Must be less than 20. Please remove old news.');
1458
- // } else if (Object.keys(context.ioPackageJson.common.news).length > 7) {
1459
- // context.warnings.push('[W130] Many "common.news" found in io-package.json. Repository builder will truncate at 7 news. Please remove old news.');
1460
- // }
1461
-
1462
- // Object.keys(context.ioPackageJson.common.news).forEach(version => {
1463
- // if (!compareVersions.validateStrict(version)) {
1464
- // context.errors.push(`[E175] Release "${version}" at "common.news" in io-package.json is malformed.`);
1465
- // }
1466
- // });
1467
-
1468
- // if (!context.ioPackageJson.common.news[context.ioPackageJson.common.version]) {
1469
- // context.errors.push(`[E145] No "common.news" found for actual version ${context.ioPackageJson.common.version} in io-package.json`);
1470
- // }
1471
-
1472
- // let missingLang =[];
1473
- // Object.keys(context.ioPackageJson.common.news).forEach(version => {
1474
- // missingLang = missingLang.concat( checkLanguages(context.ioPackageJson.common.news[version], requiredLanguages) );
1475
- // });
1476
- // if (missingLang.length) {
1477
- // missingLang = [... new Set(missingLang)]; // make unique
1478
- // context.warnings.push(`[E145] Missing mandatory translation into ${missingLang.join()} of some "common.news" in io-package.json.`);
1479
- // }
1480
-
1481
- // missingLang =[];
1482
- // Object.keys(context.ioPackageJson.common.news).forEach(version => {
1483
- // missingLang = missingLang.concat(checkLanguages(context.ioPackageJson.common.news[version], allowedLanguages));
1484
- // });
1485
- // missingLang = missingLang.filter( lang => !requiredLanguages.includes(lang));
1486
- // if (missingLang.length) {
1487
- // missingLang = [... new Set(missingLang)]; // make unique
1488
- // context.warnings.push(`[W145] Missing suggested translation into ${missingLang.join()} of some "common.news" in io-package.json.`);
1489
- // }
1490
-
1491
- // }
1492
-
1493
- // // now check the package.json again, because it is valid only for onlyWWW
1494
- // if (!context.packageJson.main) {
1495
- // !context.ioPackageJson.common.onlyWWW && context.errors.push('[E143] No main found in the package.json');
1496
- // } else {
1497
- // context.checks.push('"main" found in package.json');
1498
74
 
1499
- // if (context.ioPackageJson.common.mode !== 'none' && !context.packageJson.main.endsWith('.js')) {
1500
- // !context.ioPackageJson.common.onlyWWW && context.errors.push(`[E163] common.mode "${context.ioPackageJson.common.mode}" requires JavaScript file for "main" in package.json`);
1501
- // }
1502
- // }
1503
-
1504
- // //if (context.ioPackageJson.common.installedFrom) {
1505
- // // context.errors.push('[E144] common.installedFrom field found in io-package.json. Must be removed.');
1506
- // //}
1507
-
1508
- // if (context.ioPackageJson.instanceObjects) {
1509
- // const instanceObjects = context.ioPackageJson.instanceObjects;
1510
- // if (!(instanceObjects instanceof Array)) {
1511
- // context.errors.push('[E146] instanceObjects must be an Array in io-package.json');
1512
- // } else {
1513
- // const allowedObjectTypes = ['state', 'channel', 'device', 'enum', 'host', 'adapter', 'instance', 'meta', 'config', 'script', 'user', 'group', 'chart', 'folder'];
1514
- // const allowedStateTypes = ['number', 'string', 'boolean', 'array', 'object', 'mixed', 'file', 'json'];
1515
-
1516
- // instanceObjects.forEach(instanceObject => {
1517
- // if (instanceObject.type !== undefined && !allowedObjectTypes.includes(instanceObject.type)) {
1518
- // context.errors.push(`[E147] instanceObject type has an invalid type: ${instanceObject.type}`);
1519
- // }
1520
-
1521
- // if (instanceObject.common) {
1522
- // if (instanceObject.common.type !== undefined) {
1523
- // if (typeof instanceObject.common.type !== 'string') {
1524
- // context.errors.push(`[E148] instanceObject common.type has an invalid type! Expected "string", received "${typeof instanceObject.common.type}"`);
1525
- // }
1526
-
1527
- // if (instanceObject.type === 'state' && !allowedStateTypes.includes(instanceObject.common.type)) {
1528
- // context.errors.push(`[E149] instanceObject common.type has an invalid value: ${instanceObject.common.type}`);
1529
- // }
1530
- // }
1531
- // }
1532
- // });
1533
- // }
1534
- // }
1535
-
1536
- // if (!context.ioPackageJson.common.connectionType) {
1537
- // !context.ioPackageJson.common.onlyWWW && context.errors.push('[E150] No "common.connectionType" found in io-package.json');
1538
- // } else if (!['local', 'cloud', 'none'].includes(context.ioPackageJson.common.connectionType)) {
1539
- // context.errors.push(`[E151] "common.connectionType" type has an invalid value "${context.ioPackageJson.common.connectionType}"`);
1540
- // }
1541
-
1542
- // if (!context.ioPackageJson.common.dataSource) {
1543
- // !context.ioPackageJson.common.onlyWWW && context.errors.push('[E152] No "common.dataSource" found in io-package.json');
1544
- // } else if (!['poll', 'push', 'assumption', 'none'].includes(context.ioPackageJson.common.dataSource)) {
1545
- // context.errors.push(`[E153] "common.dataSource" type has an invalid value "${context.ioPackageJson.common.dataSource}"`);
1546
- // }
1547
-
1548
- // let currentJsControllerVersion = undefined;
1549
-
1550
- // if (context.ioPackageJson.common.dependencies) {
1551
- // if (!(context.ioPackageJson.common.dependencies instanceof Array)) {
1552
- // context.errors.push(`[E185] "common.dependencies" must be an array at io-package.json`);
1553
- // } else {
1554
- // const dependencyArray = getDependencyArray(context.ioPackageJson.common.dependencies);
1555
-
1556
- // // Admin is not allowed in dependencies (globalDependencies only)
1557
- // if (dependencyArray.includes('admin')) {
1558
- // context.errors.push(`[E160] "admin" is not allowed in common.dependencies`);
1559
- // }
1560
-
1561
- // const jsControllerDependency = context.ioPackageJson.common.dependencies.find(dep => Object.keys(dep).find(attr => attr === 'js-controller'));
1562
- // if (jsControllerDependency) {
1563
- // console.log(`Found current js-controller dependency "${jsControllerDependency['js-controller']}"`);
1564
-
1565
- // if (!jsControllerDependency['js-controller'].startsWith('>=')) {
1566
- // context.errors.push(`[E159] common.dependencies "js-controller" dependency should always allow future versions (>=x.x.x) - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
1567
- // } else {
1568
- // currentJsControllerVersion = jsControllerDependency['js-controller'].replace(/[^\d.]/g, '');
1569
- // }
1570
- // } else {
1571
- // context.errors.push(`[E162] js-controller dependency missing. js-controller ${requiredJsControllerVersion} is required as minimum, ${recommendedJsControllerVersion} is recommended. Please add to dependencies at io-package.json.`);
1572
- // }
1573
- // }
1574
- // }
1575
-
1576
- // /*
1577
- // increase dependency as required by addition features
1578
- // */
1579
- // if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.supportedMessges) {
1580
- // requiredJsControllerVersion = maxVersion( requiredJsControllerVersion, '5.0.18');
1581
- // }
1582
- // if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.nodeProcessParams) {
1583
- // requiredJsControllerVersion = maxVersion( requiredJsControllerVersion, '5.0.18');
1584
- // }
1585
-
1586
-
1587
- // if ( currentJsControllerVersion && compareVersions.compare( requiredJsControllerVersion, currentJsControllerVersion, '>' )) {
1588
- // context.errors.push(`[E162] js-controller ${currentJsControllerVersion} listed as dependency but ${requiredJsControllerVersion} is required as minimum, ${recommendedJsControllerVersion} is recommended. Please update dependency at io-package.json.`);
1589
- // } else if ( currentJsControllerVersion && compareVersions.compare( recommendedJsControllerVersion, currentJsControllerVersion, '>' )) {
1590
- // context.warnings.push(`[W162] js-controller ${currentJsControllerVersion} listed as dependency but ${recommendedJsControllerVersion} is recommended. Please consider updating dependency at io-package.json.`);
1591
- // }
1592
-
1593
- // if (context.ioPackageJson.common.globalDependencies) {
1594
- // const dependencyArray = getDependencyArray(context.ioPackageJson.common.globalDependencies);
1595
-
1596
- // if (!(context.ioPackageJson.common.globalDependencies instanceof Array)) {
1597
- // context.errors.push(`[E186] "common.globalDependencies" must be an array at io-package.json`);
1598
- // } else {
1599
- // // js-controller is not allowed in global dependencies (dependencies only)
1600
- // if (dependencyArray.includes('js-controller')) {
1601
- // context.errors.push(`[E161] "js-controller" is not allowed in common.globalDependencies`);
1602
- // }
1603
- // }
1604
-
1605
- // }
1606
-
1607
-
1608
- // if (!context.ioPackageJson.common.onlyWWW) {
1609
- // if (!context.ioPackageJson.common.tier) {
1610
- // 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.`);
1611
- // } else if (![1, 2, 3].includes(context.ioPackageJson.common.tier)) {
1612
- // context.errors.push(`[E155] Invalid "common.tier" value: ${context.ioPackageJson.common.tier} at io-package.json. Only 1, 2 or 3 are allowed!`);
1613
- // } else {
1614
- // context.checks.push('"common.tier" is valid in io-package.json');
1615
- // }
1616
- // } else {
1617
- // context.checks.push('"common.tier" check skipped for wwwOnly adapter.');
1618
- // }
1619
-
1620
- // if (context.ioPackageJson.common.automaticUpgrade) {
1621
- // context.errors.push(`[E172] "common.automaticUpgrade" will be defined by the user. Please remove from io-package.json`);
1622
- // } else {
1623
- // context.checks.push('"common.automaticUpgrade" does not exist in io-package.json');
1624
- // }
1625
-
1626
- // //if (context.ioPackageJson.common.wakeup) {
1627
- // // context.warnings.push(`[W174] "common.wakeup" is deprecated. Please remove from io-package.json`);
1628
- // //} else {
1629
- // // context.checks.push('"common.wakeup" does not exist in io-package.json');
1630
- // //}
1631
-
1632
- // if (context.ioPackageJson.common.restartAdapters) {
1633
- // const restartAdaptersArray = context.ioPackageJson.common.restartAdapters;
1634
-
1635
- // // own adapter is not allowed in a restart array
1636
- // if (restartAdaptersArray.includes(context.ioPackageJson.common.name)) {
1637
- // context.errors.push(`[E176] Own adapter is not allowed to be listed at "common.restartAdapters" in io-package.json`);
1638
- // } else {
1639
- // context.checks.push('Own adapter not listed at "common.restartAdapters".');
1640
- // }
1641
- // } else {
1642
- // context.checks.push('"restartAdapters" check skipped as object not present.');
1643
- // }
1644
-
1645
- // for (const blacklist in blacklistIOPackageJson) {
1646
- // //console.log(`checking blacklist ${blacklist}`);
1647
- // let tmp = context.ioPackageJson;
1648
- // let log = '';
1649
- // for (const element of blacklist.split('.')) {
1650
- // log = `${log}.${element}`;
1651
- // //console.log(` check ${log}`);
1652
- // tmp = tmp[element];
1653
- // if ( !tmp ) {
1654
- // //console.log(` ${log} does not exist`);
1655
- // break;
1656
- // }
1657
- // }
1658
- // if (tmp) {
1659
- // if (blacklistIOPackageJson[blacklist].err) {
1660
- // context.errors.push(`[E184] ${blacklistIOPackageJson[blacklist].msg}`);
1661
- // } else {
1662
- // context.warnings.push(`[W184] ${blacklistIOPackageJson[blacklist].msg}`);
1663
- // }
1664
- // }
1665
- // //else {
1666
- // // console.log(`blacklist ${blacklist} no match`);
1667
- // //}
1668
- // }
1669
- // context.checks.push('"blacklist (io-package)" checked.');
1670
-
1671
- // if (context.ioPackageJson.common.extIcon) {
1672
- // return downloadFile(context.ioPackageJson.common.extIcon, null, true)
1673
- // .then(icon => {
1674
- // const image = sizeOf(icon);
1675
- // if (image.width !== image.height) {
1676
- // context.errors.push('[E140] width and height of logo are not equal');
1677
- // } else {
1678
- // context.checks.push('Width and height of logo are equal');
1679
- // if (image.width < 32) {
1680
- // context.errors.push('[E141] logo is too small. It must be greater or equal than 32x32');
1681
- // } else if (image.width > 512) {
1682
- // context.errors.push('[E142] logo is too big. It must be less or equal than 512x512');
1683
- // }
1684
- // }
1685
-
1686
- // context.checks.push('"extIcon" could be downloaded');
1687
- // if (!context.ioPackageJson.common.onlyWWW && context.packageJson.main) {
1688
- // return downloadFile(context.githubUrl, `/${context.packageJson.main}`)
1689
- // .then(() => context.checks.push(`${context.packageJson.main} could be downloaded`))
1690
- // .catch(() => context.errors.push(`[E124] Main file not found under URL: ${context.githubUrl}/${context.packageJson.main}`))
1691
- // .then(() => Promise.resolve(context));
1692
- // } else {
1693
- // return Promise.resolve(context);
1694
- // }
1695
- // })
1696
- // .catch(() => context.errors.push(`[E125] External icon not found under URL: ${context.ioPackageJson.common.extIcon}`))
1697
- // .then(() => resolve(context));
1698
- // } else {
1699
- // resolve(context);
1700
- // }
1701
- // // do not put any code behind this line
1702
-
1703
- // // max number is E186
1704
- // // free 144
1705
- // // duplicates to check 145
1706
- // }
1707
- // });
1708
- // });
1709
- // }
1710
-
1711
- // E2xx
1712
- // function checkNpm(context) {
1713
- // console.log('\ncheckNpm [E2xx]');
1714
- // return axios(`https://registry.npmjs.org/iobroker.${context.adapterName}`)
1715
- // .catch(() => ({body: null}))
1716
- // .then(async response => {
1717
- // let body = response.data;
1718
- // // bug in NPM some modules could be accessed via normal web page, but not by API
1719
- // if (!body) {
1720
- // try {
1721
- // const _response = await axios(`https://www.npmjs.com/package/iobroker.${context.adapterName}`);
1722
- // if (!_response.data) {
1723
- // context.errors.push('[E200] Not found on npm. Please publish');
1724
- // return context;
1725
- // } else {
1726
- // body = _response.data;
1727
-
1728
- // context.checks.push('Adapter found on npm');
1729
- // if (!body.includes('href="/~bluefox"') && body.includes('href="/~iobluefox"')) {
1730
- // context.errors.push(`[E201] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`);
1731
- // } else {
1732
- // context.checks.push('Bluefox found in collaborators on NPM');
1733
- // }
1734
- // }
1735
- // } catch (error) {
1736
- // context.errors.push('[E200] Not found on npm. Please publish');
1737
- // return context;
1738
- // }
1739
- // } else {
1740
- // context.checks.push('Adapter found on npm');
1741
- // if (!body.maintainers ||
1742
- // !body.maintainers.length ||
1743
- // !body.maintainers.find(user => user.name === 'bluefox' || user.name === 'iobluefox')) {
1744
- // context.errors.push(`[E201] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`);
1745
- // } else {
1746
- // context.checks.push('Bluefox found in collaborators on NPM');
1747
- // }
1748
-
1749
- // if (!body['dist-tags'] ||
1750
- // context.packageJson.version !== body['dist-tags'].latest
1751
- // ) {
1752
- // if ( compareVersions.compare( body['dist-tags'].latest, context.packageJson.version, '>=' )) {
1753
- // context.errors.push(`[E203] Version of package.json (${context.packageJson.version}) lower than latest version on NPM (${
1754
- // (body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
1755
- // } else {
1756
- // context.warnings.push(`[W202] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${
1757
- // (body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
1758
- // }
1759
- // } else {
1760
- // context.checks.push(`Version of package.json ${context.packageJson.version} matches latest version on NPM`);
1761
- // }
1762
- // }
1763
-
1764
- // if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.news) {
1765
- // const missingVersions = [];
1766
- // for (const vers in context.ioPackageJson.common.news) {
1767
- // //console.log(`[DEBUG] news for ${vers}`);
1768
- // if (!body.versions[vers]) {
1769
- // missingVersions.push(vers);
1770
- // }
1771
- // }
1772
- // if (missingVersions.length) {
1773
- // if (missingVersions.length === 1) {
1774
- // context.errors.push(`[E204] Version "${missingVersions.join(', ')}" listed at common.news at io-package.json does not exist at NPM. Please remove from news section.`);
1775
- // } else {
1776
- // context.errors.push(`[E204] Versions "${missingVersions.join(', ')}" listed at common.news at io-package.json do not exist at NPM. Please remove from news section.`);
1777
- // }
1778
- // } else {
1779
- // context.checks.push(`All versions listed at news exist at npm`);
1780
- // }
1781
- // }
1782
- // return context;
1783
- // // max number is E202
1784
- // });
1785
- // }
1786
-
1787
- // // E3xx
1788
- // function checkTests(context) {
1789
- // console.log('\ncheckTests [E3xx]');
1790
- // // if found some file in `\.github\workflows` with the test inside => it is OK too
1791
- // if (context && context.filesList.find(name => name.startsWith('.github/workflows/') && name.endsWith('.yml') && name.toLowerCase().includes('test'))) {
1792
- // context.checks.push('Tests found on github actions');
1793
- // return Promise.resolve(context);
1794
- // }
1795
-
1796
- // // const travisURL = `${context.githubUrlOriginal.replace('github.com', 'api.travis-ci.org')}.png`;
1797
- // //
1798
- // // return axios(travisURL)
1799
- // // .then(response => {
1800
- // // if (!response.data) {
1801
- // // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
1802
- // // return context;
1803
- // // }
1804
- // // if (!response.headers || !response.headers['content-disposition']) {
1805
- // // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
1806
- // // return context;
1807
- // // }
1808
- // // // inline; filename="passing.png"
1809
- // // const m = response.headers['content-disposition'].match(/filename="(.+)"$/);
1810
- // // if (!m) {
1811
- // // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
1812
- // // return context;
1813
- // // }
1814
- // //
1815
- // // if (m[1] === 'unknown.png') {
1816
- // // context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
1817
- // // return context;
1818
- // // }
1819
- // //
1820
- // // context.checks.push('Found on travis-ci');
1821
- // //
1822
- // // context.warnings.push('[W302] Use github actions instead of travis-ci');
1823
- // //
1824
- // // if (m[1] !== 'passing.png') {
1825
- // // context.errors.push('[E301] Tests on Travis-ci.org are broken. Please fix.');
1826
- // // } else {
1827
- // // context.checks.push('Tests are OK on travis-ci');
1828
- // // }
1829
- // //
1830
- // // return context;
1831
- // // // max number is E302
1832
- // // });
1833
- // return Promise.resolve(context);
1834
- // }
1835
-
1836
- // E4xx
1837
- // function checkRepo(context) {
1838
- // console.log('\ncheckRepo [E4xx]');
1839
- // if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.type) {
1840
- // // download latest repo
1841
- // return axios('https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist.json')
1842
- // .then(async response => {
1843
- // let body = response.data;
1844
- // if (!body) {
1845
- // context.errors.push('[E400] Cannot download https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist.json');
1846
- // } else {
1847
- // context.latestRepo = body;
1848
- // if (!context.latestRepo[context.adapterName]) {
1849
- // context.warnings.push(`[W400] Cannot find "${context.adapterName}" in latest repository`);
1850
-
1851
- // if (context.adapterName.includes('_')) {
1852
- // context.errors.push('[E429] Adapter name should use "-" instead of "_"');
1853
- // } else {
1854
- // context.checks.push('Adapter name does not have "_"');
1855
- // }
1856
- // } else {
1857
- // context.checks.push('Adapter found in latest repository');
1858
-
1859
- // if (context.latestRepo[context.adapterName].type !== context.ioPackageJson.common.type) {
1860
- // context.errors.push(`[E402] Types of adapter in latest repository and in io-package.json are different "${context.latestRepo[context.adapterName].type}" !== "${context.ioPackageJson.common.type}"`);
1861
- // } else {
1862
- // context.checks.push(`Types of adapter in latest repository and in io-package.json are equal: "${context.latestRepo[context.adapterName].type}"`);
1863
- // }
1864
-
1865
- // if (context.latestRepo[context.adapterName].version) {
1866
- // context.errors.push('[E403] Version set in latest repository');
1867
- // } else {
1868
- // context.checks.push('Version not set in latest repository');
1869
- // }
1870
-
1871
- // const url = `https://raw.githubusercontent.com/${context.authorName}/ioBroker.${context.adapterName}/${context.branch}/`;
1872
-
1873
- // if (!context.latestRepo[context.adapterName].icon) {
1874
- // context.errors.push('[E404] Icon not found in latest repository');
1875
- // } else {
1876
- // context.checks.push('Icon found in latest repository');
1877
-
1878
- // if (!context.latestRepo[context.adapterName].icon.startsWith(url)) {
1879
- // context.errors.push(`[E405] Icon must be in the following path: ${url}; correct sources-dist.json`);
1880
- // } else {
1881
- // context.checks.push('Icon found in latest repository');
1882
- // }
1883
- // }
1884
- // if (!context.latestRepo[context.adapterName].meta) {
1885
- // context.errors.push('[E406] Meta URL not found in latest repository; correct sources-dist.json');
1886
- // } else {
1887
- // context.checks.push('Meta URL(latest) found in latest repository');
1888
-
1889
- // if (context.latestRepo[context.adapterName].meta !== `${url}io-package.json`) {
1890
- // context.errors.push(`[E407] Meta URL must be equal to ${url}io-package.json; correct sources-dist.json`);
1891
- // } else {
1892
- // context.checks.push('Meta URL (latest) is OK in latest repository');
1893
- // }
1894
- // }
1895
- // }
1896
- // }
1897
-
1898
- // // download stable repo
1899
- // let _response = await axios('https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist-stable.json');
1900
- // body = _response.data;
1901
- // if (!body) {
1902
- // context.errors.push('[E420] Cannot download https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist-stable.json');
1903
- // } else {
1904
- // context.stableRepo = body;
1905
- // if (context.stableRepo[context.adapterName]) {
1906
- // if (context.stableRepo[context.adapterName].type !== context.ioPackageJson.common.type) {
1907
- // context.errors.push(`[E422] Types of adapter in stable repository and in io-package.json are different "${context.stableRepo[context.adapterName].type}" !== "${context.ioPackageJson.common.type}"`);
1908
- // } else {
1909
- // context.checks.push(`Types of adapter in stable repository and in io-package.json are equal: "${context.stableRepo[context.adapterName].type}"`);
1910
- // }
1911
-
1912
- // if (!context.latestRepo[context.adapterName]) {
1913
- // context.errors.push('[E423] Adapter was found in stable repository but not in latest repo');
1914
- // } else {
1915
- // context.checks.push('Adapter was found in stable repository and in latest repo');
1916
- // }
1917
-
1918
- // if (!context.stableRepo[context.adapterName].version) {
1919
- // context.errors.push('[E424] No version set in stable repository');
1920
- // } else {
1921
- // context.checks.push('Version found in stable repository');
1922
- // }
1923
-
1924
- // const url = `https://raw.githubusercontent.com/${context.authorName}/ioBroker.${context.adapterName}/${context.branch}/`;
1925
-
1926
- // if (!context.stableRepo[context.adapterName].icon) {
1927
- // context.errors.push('[E425] Icon not found in stable repository');
1928
- // } else {
1929
- // context.checks.push('Icon found in stable repository');
1930
-
1931
- // if (!context.stableRepo[context.adapterName].icon.startsWith(url)) {
1932
- // context.errors.push(`[E426] Icon must be in the following path: ${url}; correct sources-dist-stable.json`);
1933
- // } else {
1934
- // context.checks.push('Icon (stable) found in latest repository');
1935
- // }
1936
- // }
1937
-
1938
- // if (!context.stableRepo[context.adapterName].meta) {
1939
- // context.errors.push('[E427] Meta URL not found in latest repository; correct sources-dist.json');
1940
- // } else {
1941
- // context.checks.push('Meta URL (stable) found in latest repository');
1942
-
1943
- // if (context.stableRepo[context.adapterName].meta !== `${url}io-package.json`) {
1944
- // context.errors.push(`[E428] Meta URL must be equal to ${url}io-package.json; correct sources-dist-stable.json`);
1945
- // } else {
1946
- // context.checks.push('Meta URL (stable) is OK in latest repository');
1947
- // }
1948
- // }
1949
- // }
1950
- // }
1951
-
1952
- // _response = await axios('http://repo.iobroker.live/sources-dist-latest.json');
1953
- // body = _response.data;
1954
- // if (!body) {
1955
- // context.errors.push('[E429] Cannot download http://repo.iobroker.live/sources-dist-latest.json');
1956
- // } else {
1957
- // context.latestRepoLive = body;
1958
- // }
1959
-
1960
- // _response = await axios('http://repo.iobroker.live/sources-dist.json');
1961
- // body = _response.data;
1962
- // if (!body) {
1963
- // context.errors.push('[E430] Cannot download http://repo.iobroker.live/sources-dist.json');
1964
- // } else {
1965
- // context.stableRepoLive = body;
1966
- // }
1967
-
1968
- // if (context.latestRepo && context.latestRepoLive && context.stableRepo && context.stableRepoLive) {
1969
- // if (context.ioPackageJson.common.dependencies) {
1970
- // const dependencies = getDependencies(context.ioPackageJson.common.dependencies);
1971
- // for ( const dependency in dependencies ) {
1972
-
1973
- // if ( !context.latestRepoLive[dependency] ) {
1974
- // context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
1975
- // } else {
1976
- // const versDependency = dependencies[dependency];
1977
- // const versRepository = context.latestRepoLive[dependency].version;
1978
- // //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
1979
- // if (!versDependency.startsWith('>=')) {
1980
- // context.warnings.push(`[W432] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
1981
- // } else {
1982
- // if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
1983
- // context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
1984
- // } else {
1985
- // context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at latest repository`);
1986
- // }
1987
- // }
1988
- // }
1989
-
1990
- // if ( !context.stableRepoLive[dependency] ) {
1991
- // context.warnings.push(`[W433] Dependency ${dependency} not available at stable repository`);
1992
- // } else {
1993
- // const versDependency = dependencies[dependency];
1994
- // const versRepository = context.stableRepoLive[dependency].version;
1995
- // //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
1996
- // if (!versDependency.startsWith('>=')) {
1997
- // context.warnings.push(`[W434] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
1998
- // } else {
1999
- // if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
2000
- // context.errors.push(`[E433] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
2001
- // } else {
2002
- // context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at stable repository`);
2003
- // }
2004
- // }
2005
- // }
2006
-
2007
- // }
2008
- // } else {
2009
- // context.checks.push('common.dependency check skipped');
2010
- // }
2011
-
2012
- // if (context.ioPackageJson.common.globalDependencies) {
2013
- // const dependencies = getDependencies(context.ioPackageJson.common.globalDependencies);
2014
- // for ( const dependency in dependencies ) {
2015
-
2016
- // if ( !context.latestRepoLive[dependency] ) {
2017
- // context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
2018
- // } else {
2019
- // const versDependency = dependencies[dependency];
2020
- // const versRepository = context.latestRepoLive[dependency].version;
2021
- // //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
2022
- // if (!versDependency.startsWith('>=')) {
2023
- // context.warnings.push(`[W432] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
2024
- // } else {
2025
- // if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
2026
- // context.errors.push(`[E431] Dependency '${dependency}':'${dependencies[dependency]}' not available at latest repository`);
2027
- // } else {
2028
- // context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at latest repository`);
2029
- // }
2030
- // }
2031
- // }
2032
-
2033
- // if ( !context.stableRepoLive[dependency] ) {
2034
- // context.warnings.push(`[W433] Dependency ${dependency} not available at stable repository`);
2035
- // } else {
2036
- // const versDependency = dependencies[dependency];
2037
- // const versRepository = context.stableRepoLive[dependency].version;
2038
- // //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`);
2039
- // if (!versDependency.startsWith('>=')) {
2040
- // context.warnings.push(`[W434] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`);
2041
- // } else {
2042
- // if ( !compareVersions.compare( versRepository, versDependency.replace('>=',''), '>=')) {
2043
- // context.errors.push(`[E433] Dependency '${dependency}':'${dependencies[dependency]}' not available at stable repository`);
2044
- // } else {
2045
- // context.checks.push(`Dependency '${dependency}':'${dependencies[dependency]}' available at stable repository`);
2046
- // }
2047
- // }
2048
- // }
2049
-
2050
- // }
2051
- // } else {
2052
- // context.checks.push('common.globalDependency check skipped');
2053
- // }
2054
-
2055
- // } else {
2056
- // context.checks.push(`Dependency checks skipped due to repository access errors`);
2057
- // }
2058
- // return context;
2059
- // });
2060
- // } else {
2061
- // return Promise.resolve(context);
2062
- // }
2063
- // // max number is E429
2064
- // }
2065
-
2066
- // function extractWords(words) {
2067
- // try {
2068
- // const lines = words.split(/\r\n|\r|\n/g);
2069
- // let i = 0;
2070
- // while (!lines[i].match(/^systemDictionary = {/)) {
2071
- // i++;
2072
- // }
2073
- // lines.splice(0, i);
2074
-
2075
- // // remove last empty lines
2076
- // i = lines.length - 1;
2077
- // while (!lines[i]) {
2078
- // i--;
2079
- // }
2080
- // if (i < lines.length - 1) {
2081
- // lines.splice(i + 1);
2082
- // }
2083
-
2084
- // lines[0] = lines[0].replace('systemDictionary = ', '');
2085
- // lines[lines.length - 1] = lines[lines.length - 1].trim().replace(/};$/, '}');
2086
- // words = lines.join('\n');
2087
- // const resultFunc = new Function(`return ${words};`);
2088
-
2089
- // return resultFunc();
2090
- // } catch (e) {
2091
- // return null;
2092
- // }
2093
- // }
2094
-
2095
- // // E5xx
2096
- // function checkCode(context) {
2097
- // const readFiles = [
2098
- // '.npmignore',
2099
- // '.gitignore',
2100
- // 'iob_npm.done',
2101
- // '.travis.yml',
2102
- // 'gulpfile.js',
2103
- // '.releaseconfig.json',
2104
-
2105
- // // Add all potential files anyway. If they exist, they must be valid.
2106
- // // If they are unnecessary, a warning could be issued
2107
- // 'admin/index_m.html',
2108
- // 'admin/words.js',
2109
- // 'admin/jsonConfig.json',
2110
- // 'admin/jsonConfig.json5',
2111
- // 'admin/jsonCustom.json',
2112
- // 'admin/jsonCustom.json5',
2113
- // 'admin/blockly.js',
2114
-
2115
- // 'src-admin/package.json', // check if react is used
2116
- // 'src-widgets/package.json', // check if react is used
2117
- // 'src/package.json', // check if react is used
2118
- // ];
2119
- // allowedLanguages.forEach(lang =>
2120
- // readFiles.push(`admin/i18n/${lang}/translations.json`));
2121
- // allowedLanguages.forEach(lang =>
2122
- // readFiles.push(`admin/i18n/${lang}.json`));
2123
-
2124
- // if (context.packageJson.main) {
2125
- // readFiles.push(context.packageJson.main);
2126
- // }
2127
-
2128
- // // if (!context.ioPackageJson.common.noConfig) {
2129
- // // if (context.ioPackageJson.common.materialize || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize')) {
2130
- // // readFiles.push('admin/index_m.html');
2131
- // // readFiles.push('admin/words.js');
2132
- // // }
2133
- // //
2134
- // // if (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') {
2135
- // // readFiles.push('admin/jsonConfig.json');
2136
- // // readFiles.push('admin/jsonConfig.json5');
2137
- // // allowedLanguages.forEach(lang =>
2138
- // // readFiles.push(`admin/i18n/${lang}/translations.json`));
2139
- // // allowedLanguages.forEach(lang =>
2140
- // // readFiles.push(`admin/i18n/${lang}.json`));
2141
- // // }
2142
- // //
2143
- // // if (context.ioPackageJson.common.supportCustoms || context.ioPackageJson.common.jsonCustom || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.custom === 'json')) {
2144
- // // readFiles.push('admin/jsonCustom.json');
2145
- // // readFiles.push('admin/jsonCustom.json5');
2146
- // // }
2147
- // // }
2148
- // //
2149
- // // if (context.ioPackageJson.common.blockly) {
2150
- // // readFiles.push('admin/blockly.js');
2151
- // // }
2152
-
2153
- // // https://github.com/userName/ioBroker.adaptername/archive/${context.branch}.zip
2154
- // return new Promise((resolve, reject) => {
2155
- // console.log('\ncheckCode [E5xx]');
2156
- // return downloadFile(context.githubUrlOriginal, `/archive/${context.branch}.zip`, true)
2157
- // .then(data => {
2158
- // console.log(`${context.branch}.zip ${data.length} bytes`);
2159
- // let found = false;
2160
- // const bufferStream = new stream.PassThrough();
2161
- // bufferStream.end(data);
2162
- // context.filesList = [];
2163
-
2164
- // const promises = [];
2165
-
2166
- // return new Promise(_resolve => {
2167
- // bufferStream
2168
- // .pipe(unzipper.Parse())
2169
- // .on('entry', entry => {
2170
- // // console.log('Check ' + entry.path);
2171
- // if (!found && entry.type === 'Directory' && entry.path.match(/\/node_modules\/$/)) {
2172
- // console.log(`Found ${entry.path}`);
2173
- // found = true;
2174
- // context.errors.push('[E500] node_modules found in repo. Please delete it');
2175
- // }
2176
- // // Get a list of all files and `.npmignore` + `.gitignore`
2177
-
2178
- // const name = entry.path.replace(/^[^/]+\//, '');
2179
- // context.filesList.push(name);
2180
-
2181
- // if (readFiles.includes(name)) {
2182
- // promises.push(new Promise(resolve => {
2183
- // const wstream = new WMStrm(name);
2184
- // wstream.on('finish', () => {
2185
- // context[`/${name}`] = memStore[name].toString();
2186
- // resolve(context[`/${name}`]);
2187
- // });
2188
- // entry.pipe(wstream);
2189
- // }));
2190
- // } else {
2191
- // entry.autodrain();
2192
- // }
2193
- // })
2194
- // .on('error', () => {
2195
- // context.errors.push(`[E501] Cannot get ${context.branch}.zip on github`);
2196
- // return Promise.all(promises).then(() => _resolve(context));
2197
- // })
2198
- // .on('close', () => {
2199
- // return Promise.all(promises).then(() => _resolve(context));
2200
- // });
2201
- // });
2202
- // })
2203
- // .then(context => {
2204
- // let usesReact = false;
2205
- // if (context.packageJson.devDependencies &&
2206
- // (context.packageJson.devDependencies['@iobroker/adapter-react-v5'] || context.packageJson.devDependencies['react'])) {
2207
- // console.log('REACT detected at package devDependencies');
2208
- // usesReact = true;
2209
- // }
2210
- // if (context.packageJson.dependencies &&
2211
- // (context.packageJson.dependencies['@iobroker/adapter-react-v5'] || context.packageJson.dependencies['react'])) {
2212
- // console.log('REACT detected at package dependencies');
2213
- // usesReact = true;
2214
- // }
2215
- // if (context['/src-admin/package.json']) {
2216
- // //console.log('"src-admin/package.json" exists');
2217
- // const packageJson = JSON.parse(context['/src-admin/package.json']);
2218
- // if (packageJson.devDependencies && packageJson.devDependencies['@iobroker/adapter-react-v5'] ) {
2219
- // console.log('REACT detected at src-admin/package devDependencies');
2220
- // usesReact = true;
2221
- // }
2222
- // if (packageJson.dependencies && packageJson.dependencies['@iobroker/adapter-react-v5'] ) {
2223
- // console.log('REACT detected at src-admin/package dependencies');
2224
- // usesReact = true;
2225
- // }
2226
- // }
2227
- // if (context['/src-widgets/package.json']) {
2228
- // //console.log('"src-widgets/package.json" exists');
2229
- // const packageJson = JSON.parse(context['/src-widgets/package.json']);
2230
- // if (packageJson.devDependencies && (
2231
- // packageJson.devDependencies['@iobroker/adapter-react-v5'] || packageJson.devDependencies['react'])) {
2232
- // console.log('REACT detected at src-widgets/package devDependencies');
2233
- // usesReact = true;
2234
- // }
2235
- // if (packageJson.dependencies && (
2236
- // packageJson.dependencies['@iobroker/adapter-react-v5'] || packageJson.dependencies['react'])) {
2237
- // console.log('REACT detected at src-widgets/package dependencies');
2238
- // usesReact = true;
2239
- // }
2240
- // }
2241
- // if (context['/src/package.json']) {
2242
- // //console.log('"src/package.json" exists');
2243
- // const packageJson = JSON.parse(context['/src/package.json']);
2244
- // if (packageJson.devDependencies && packageJson.devDependencies['@iobroker/adapter-react-v5'] ) {
2245
- // // console.log('REACT detected');
2246
- // usesReact = true;
2247
- // }
2248
- // if (packageJson.dependencies && packageJson.dependencies['@iobroker/adapter-react-v5'] ) {
2249
- // // console.log('REACT detected');
2250
- // usesReact = true;
2251
- // }
2252
- // }
2253
-
2254
- // if (! usesReact && !context.ioPackageJson.common.noConfig &&
2255
- // (!context.ioPackageJson.common.adminUI ||
2256
- // (context.ioPackageJson.common.adminUI.config !== 'json' && context.ioPackageJson.common.adminUI.config !== 'none')
2257
- // )) {
2258
- // context.warnings.push('[S522] Please consider migrating to admin 5 UI (jsonConfig).');
2259
- // }
2260
-
2261
- // if (context.ioPackageJson.common.materialize || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize')) {
2262
- // if (context['/admin/index_m.html'] && context['/admin/index_m.html'].includes('selectID.js') && !context.filesList.includes('admin/img/info-big.png')) {
2263
- // context.errors.push('[E502] "admin/img/info-big.png" not found, but selectID.js used in index_m.html ');
2264
- // }
2265
-
2266
- // if (context['/admin/words.js']) {
2267
- // // at least 3 languages must be in
2268
- // const words = extractWords(context['/admin/words.js']);
2269
- // if (words) {
2270
- // const problem = Object.keys(words).filter(word => !words[word].de || !words[word].ru);
2271
- // if (problem.length > 3) {
2272
- // context.errors.push(`[E506] More non translated in german or russian words found in admin/words.js. You can use https://translator.iobroker.in/ for translations`);
2273
- // } else {
2274
- // problem.forEach(word => {
2275
- // if (!words[word].de) {
2276
- // context.errors.push(`[E506] Word "${word}" is not translated to german in admin/words.js. You can use https://translator.iobroker.in/ for translations`);
2277
- // }
2278
- // if (!words[word].ru) {
2279
- // context.errors.push(`[E506] Word "${word}" is not translated to russian in admin/words.js. You can use https://translator.iobroker.in/ for translations`);
2280
- // }
2281
- // });
2282
- // }
2283
- // }
2284
- // } else {
2285
- // context.checks.push('admin/words.js found.');
2286
- // }
2287
- // }
2288
-
2289
- // if (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') {
2290
- // let jsonConfig;
2291
- // if (context['/admin/jsonConfig.json'] || context['/admin/jsonConfig.json5']) {
2292
- // try {
2293
- // jsonConfig = context['/admin/jsonConfig.json'] ? JSON.parse(context['/admin/jsonConfig.json']) : JSON5.parse(context['/admin/jsonConfig.json5']);
2294
- // } catch (e) {
2295
- // context.errors.push(`[E507] Cannot parse "admin/jsonConfig.json${context['/admin/jsonConfig.json'] ? '' : '5'}": ${e}`);
2296
- // }
2297
- // } else {
2298
- // context.errors.push(`[E508] "admin/jsonConfig.json${context['/admin/jsonConfig.json'] ? '' : '5'}" not found, but admin support is declared`);
2299
- // }
2300
-
2301
- // if (jsonConfig && jsonConfig.i18n === true) {
2302
- // allowedLanguages.forEach(lang => {
2303
- // if (context[`/admin/i18n/${lang}/translations.json`]) {
2304
- // try {
2305
- // JSON.parse(context[`/admin/i18n/${lang}/translations.json`]);
2306
- // } catch (e) {
2307
- // context.errors.push(`[E509] Cannot parse "admin/i18n/${lang}/translations.json": ${e}`);
2308
- // }
2309
- // } else if (context[`/admin/i18n/${lang}.json`]) {
2310
- // try {
2311
- // JSON.parse(context[`/admin/i18n/${lang}.json`]);
2312
- // } catch (e) {
2313
- // context.errors.push(`[E509] Cannot parse "admin/i18n/${lang}.json": ${e}`);
2314
- // }
2315
- // } else {
2316
- // context.warnings.push(`[W510] "/admin/i18n/${lang}/translations.json" or "admin/i18n/${lang}.json" not found, but admin support is declared. Please add.`);
2317
- // }
2318
- // });
2319
- // }
2320
- // if (jsonConfig && jsonConfig.i18n === false) {
2321
- // context.warnings.push(`[W515] Why did you decide to disable i18n support?`);
2322
- // }
2323
- // }
2324
-
2325
- // if (context.ioPackageJson.common.supportCustoms || context.ioPackageJson.common.jsonCustom || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.custom === 'json')) {
2326
- // if (context['/admin/jsonCustom.json'] || context['/admin/jsonCustom.json5']) {
2327
- // try {
2328
- // context['/admin/jsonCustom.json'] ? JSON.parse(context['/admin/jsonCustom.json']) : JSON5.parse(context['/admin/jsonCustom.json5']);
2329
- // } catch (e) {
2330
- // context.errors.push(`[E511] Cannot parse "admin/jsonCustom.json${context['/admin/jsonCustom.json'] ? '' : '5'}": ${e}`);
2331
- // }
2332
- // } else {
2333
- // context.errors.push(`[E512] "admin/jsonCustom.json${context['/admin/jsonCustom.json'] ? '' : '5'}" not found, but custom support is declared`);
2334
- // }
2335
- // }
2336
-
2337
- // if (context.ioPackageJson.common.blockly && !context['/admin/blockly.js']) {
2338
- // context.errors.push('[E514] "admin/blockly.js" not found, but blockly support is declared');
2339
- // }
2340
-
2341
- // if (context.ioPackageJson.common.javascriptRules) {
2342
- // if (!context.ioPackageJson.common.javascriptRules.url) {
2343
- // context.errors.push('[E515] JavaScript-Rules support is declared, but no location in property url defined');
2344
- // }
2345
- // if (!context.filesList.includes('admin/' + context.ioPackageJson.common.javascriptRules.url)) {
2346
- // context.errors.push(`[E516] "${context.ioPackageJson.common.javascriptRules.url}" not found, but JavaScript-Rules support is declared`);
2347
- // }
2348
- // }
2349
-
2350
- // const forbiddenFiles = [
2351
- // 'iob_npm.done',
2352
- // 'iob',
2353
- // 'iobroker'
2354
- // ];
2355
-
2356
- // forbiddenFiles.forEach( file => {
2357
- // if (context.filesList.includes(file)) {
2358
- // context.errors.push(`[E503] File "${file}" found in repo! Please remove file.`);
2359
- // }
2360
- // });
2361
-
2362
- // //if (context['/iob_npm.done']) {
2363
- // // context.errors.push('[E503] File "iob_npm.done" found in repo! Remove that file');
2364
- // //}
2365
-
2366
- // if (!context.filesList.includes('package-lock.json')) {
2367
- // context.warnings.push('[W523] "package-lock.json" not found in repo! Please remove from .gitignore!');
2368
- // }
2369
-
2370
- // if (context['/.travis.yml']) {
2371
- // context.hasTravis = true;
2372
- // }
2373
-
2374
- // if (context['/gulpfile.js']) {
2375
- // if (!usesReact) {
2376
- // context.warnings.push('[W513] "gulpfile.js" found in repo! Think about migrating to @iobroker/adapter-dev package');
2377
- // }
2378
- // if (!context.packageJson.devDependencies['gulp']) {
2379
- // context.warnings.push('[W520] "gulpfile.js" found in repo but "gulp" not found at devDependencies at package.json. Check whether it can be removed.');
2380
- // }
2381
- // } else {
2382
- // if (context.packageJson.devDependencies['gulp']) {
2383
- // context.warnings.push('[W521] "gulp" found at devDependencies at package.json but no "gulpfile.js" found. Is this dependency really required?');
2384
- // }
2385
- // }
2386
-
2387
- // if (context.packageJson.devDependencies && context.packageJson.devDependencies['@alcalzone/release-script'] ) {
2388
- // const version = context.packageJson.devDependencies['@alcalzone/release-script'];
2389
- // if ( compareVersions.compareVersions( version, '3.0.0' ) >= 0) {
2390
- // if (!context['/.releaseconfig.json']) {
2391
- // context.errors.push('[E518] "@alcalzone/release-script" (>=3.0.0) is used, but ".releaseconfig.json" not found. Please create.');
2392
- // } else {
2393
- // console.log('context[/.releaseconfig.json: '+ context['/.releaseconfig.json']);
2394
- // const releaseConfigJson = JSON.parse(context['/.releaseconfig.json']);
2395
- // console.log(`releaseConfigJson: ${releaseConfigJson}`);
2396
- // const plugins = releaseConfigJson.plugins;
2397
- // console.log(`plugins: ${plugins}`);
2398
- // if (!context.packageJson.devDependencies['@alcalzone/release-script-plugin-iobroker']) {
2399
- // context.errors.push('[E519] "@alcalzone/release-script" requires plugin "@alcalzone/release-script-plugin-iobroker". Please add.');
2400
- // } else {
2401
- // if (!plugins.includes('iobroker')) {
2402
- // context.errors.push('[E520] Plugin "iobroker" missing at .releaseconfig.json. Please add.');
2403
- // }
2404
- // }
2405
- // if (!context.packageJson.devDependencies['@alcalzone/release-script-plugin-license']) {
2406
- // context.errors.push('[E519] "@alcalzone/release-script" requires plugin "@alcalzone/release-script-plugin-license". Please add.');
2407
- // } else {
2408
- // if (!plugins.includes('license')) {
2409
- // context.errors.push('[E520] Plugin "license" missing at .releaseconfig.json. Please add.');
2410
- // }
2411
- // }
2412
- // if (!context.packageJson.devDependencies['@alcalzone/release-script-plugin-manual-review']) {
2413
- // context.warnings.push('[S519] Consider adding plugin "@alcalzone/release-script-plugin-manual-review".');
2414
- // } else {
2415
- // if (!plugins.includes('manual-review')) {
2416
- // context.warnings.push('[W520] Plugin "manual-review" missing at .releaseconfig.json. Please add.');
2417
- // }
2418
- // }
2419
- // }
2420
- // }
2421
- // }
2422
-
2423
- // if (context.packageJson.main && context.packageJson.main.endsWith('.js')) {
2424
- // if (!context[`/${context.packageJson.main}`]) {
2425
- // if (!context.ioPackageJson.common.nogit) {
2426
- // context.errors.push(`[E519] "${context.packageJson.main}" found in package.json, but not found as file`);
2427
- // }
2428
- // } else {
2429
- // if (context[`/${context.packageJson.main}`].includes('setInterval(') && !context[`/${context.packageJson.main}`].includes('clearInterval(')) {
2430
- // if (context.ioPackageJson.common.compact) {
2431
- // // if compact mode supported, it is critical
2432
- // context.errors.push(`[E504] setInterval found in "${context.packageJson.main}", but no clearInterval detected`);
2433
- // } else {
2434
- // context.warnings.push(`[W504] setInterval found in "${context.packageJson.main}", but no clearInterval detected`);
2435
- // }
2436
- // }
2437
- // if (context['/' + context.packageJson.main].includes('setTimeout(') && !context['/' + context.packageJson.main].includes('clearTimeout(')) {
2438
- // if (context.ioPackageJson.common.compact) {
2439
- // // if compact mode supported, it is critical
2440
- // // context.errors.push(`[E505] setTimeout found in "${context.packageJson.main}", but no clearTimeout detected`);
2441
- // context.warnings.push(`[W505] setTimeout found in "${context.packageJson.main}", but no clearTimeout detected`);
2442
- // } else {
2443
- // context.warnings.push(`[W505] setTimeout found in "${context.packageJson.main}", but no clearTimeout detected`);
2444
- // }
2445
- // }
2446
- // }
2447
- // }
2448
- // // max E523
2449
- // resolve(context);
2450
- // })
2451
- // .catch(e => reject(e));
2452
- // });
2453
- // }
2454
-
2455
- // function getAuthor(author) {
2456
- // if (author && typeof author === 'object') {
2457
- // return `${author.name} <${author.email}>`;
2458
- // } else {
2459
- // return author;
2460
- // }
2461
- // }
2462
-
2463
- // function checkCommits(context) {
2464
- // console.log('checkCommits');
2465
- // return downloadFile(context.githubUrlOriginal, `/commits/${context.branch}`)
2466
- // .then(data => {
2467
- // const m = data.match(/Commits on [\w\s\d]+, (\d\d\d\d)/);
2468
- // if (m) {
2469
- // context.lastCommitYear = Number(m[1]);
2470
- // }
2471
- // return context;
2472
- // });
2473
- // }
2474
-
2475
- // // E6xx
2476
- // function checkReadme(context) {
2477
- // // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/README.md
2478
- // return new Promise((resolve, reject) => {
2479
- // console.log('\ncheckReadme [E6xx]');
2480
- // downloadFile(context.githubUrl, '/README.md')
2481
- // .then(data => {
2482
- // if (!data) {
2483
- // context.errors.push('[E601] No README.md found');
2484
- // } else {
2485
- // context.checks.push('README.md found');
2486
-
2487
- // if (!data.includes('## Changelog')) {
2488
- // context.errors.push('[E603] NO "## Changelog" found in README.md');
2489
- // } else {
2490
- // context.checks.push('README.md contains Changelog');
2491
-
2492
- // if (!data.includes(`### ${context.packageJson.version}`)) {
2493
- // context.errors.push(`[E606] Current adapter version ${context.packageJson.version} not found in README.md`);
2494
- // } else {
2495
- // context.checks.push('README.md contains current adapter version');
2496
- // }
2497
- // }
2498
-
2499
- // let npmYear = 0;
2500
- // try {
2501
- // const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' });
2502
- // const npmJson = JSON.parse(result);
2503
- // //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`);
2504
- // if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) {
2505
- // const latest = npmJson['dist-tags'].latest;
2506
- // const timeStr = npmJson.time[latest];
2507
- // npmYear = new Date(timeStr).getFullYear();
2508
- // console.log(`[DEBUG] ${latest} - ${timeStr} - ${npmYear}`);
2509
- // }
2510
- // } catch (e) {
2511
- // context.warnings.push('[W606] Could not retrieve timestamp of LATEST revision at npm.');
2512
- // console.log(`Error executing "npm view"`);
2513
- // }
2514
-
2515
- // const pos = data.indexOf('## License');
2516
- // if (pos === -1) {
2517
- // context.errors.push('[E604] No "## License" found in README.md');
2518
- // } else {
2519
- // context.checks.push('## License found in README.md');
2520
- // const text = data.substring(pos);
2521
- // const year = new Date().getFullYear();
2522
- // const commitYear = context.lastCommitYear || 0;
2523
- // let readmeYear = 0;
2524
- // let m = text.match(/\d\d\d\d\s*-\s*(\d\d\d\d)/);
2525
- // if (m) {
2526
- // readmeYear = Number(m[1]);
2527
- // }
2528
- // m = text.match(/(\d\d\d\d)/); /* both variants could be present */
2529
- // if (m) {
2530
- // if (Number(m[1]) > readmeYear) {
2531
- // readmeYear = Number(m[1]);
2532
- // }
2533
- // }
2534
-
2535
- // console.log(`README year ${readmeYear}`);
2536
- // console.log(`Current year ${year}`);
2537
- // console.log(`Commit year ${commitYear}`);
2538
- // console.log(`NPM year ${npmYear}`);
2539
-
2540
- // const valid = (readmeYear === year || readmeYear >= commitYear || readmeYear >=npmYear);
2541
- // if (!valid) {
2542
- // const m = text.match(/(\d\d\commitd\d)-\d\d\d\d/);
2543
- // if (m) {
2544
- // context.errors.push(`[E605] No actual year found in copyright. Please add "Copyright (c) ${m[1]}-${year} ${getAuthor(context.packageJson.author)}" at the end of README.md`);
2545
- // } else {
2546
- // context.errors.push(`[E605] No actual year found in copyright. Please add "Copyright (c) ${year} ${getAuthor(context.packageJson.author)}" at the end of README.md`);
2547
- // }
2548
- // } else {
2549
- // context.checks.push('Valid copyright year found in README.md');
2550
- // }
2551
- // }
2552
-
2553
- // // languages = languagedetect.detect(data, 3);
2554
- // //console.log(JSON.stringify(languages));
2555
- // }
2556
-
2557
- // // max E606
2558
- // resolve(context);
2559
- // })
2560
- // .catch(e => reject(e));
2561
- // });
2562
- // }
2563
-
2564
- // // E7xx
2565
- // function checkLicenseFile(context) {
2566
- // // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/LICENSE
2567
- // return new Promise((resolve, reject) => {
2568
- // console.log('\ncheckLicenseFile [E7xx]');
2569
- // downloadFile(context.githubUrl, '/LICENSE')
2570
- // .then(data => {
2571
- // if (!data) {
2572
- // context.errors.push('[E701] NO LICENSE file found');
2573
- // } else {
2574
- // context.checks.push('LICENSE file found');
2575
-
2576
- // let npmYear = 0;
2577
- // try {
2578
- // const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' });
2579
- // const npmJson = JSON.parse(result);
2580
- // //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`);
2581
- // if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) {
2582
- // const latest = npmJson['dist-tags'].latest;
2583
- // const timeStr = npmJson.time[latest];
2584
- // npmYear = new Date(timeStr).getFullYear();
2585
- // }
2586
- // } catch (e) {
2587
- // console.log(`Error executing "npm view" - ${e}`);
2588
- // }
2589
-
2590
- // if (context.packageJson.license === 'MIT') {
2591
- // const text = data;
2592
- // const year = new Date().getFullYear();
2593
- // const commitYear = context.lastCommitYear || 0;
2594
- // let licenseYear = 0;
2595
- // let m = text.match(/\d\d\d\d\s*-\s*(\d\d\d\d)/);
2596
- // if (m) {
2597
- // licenseYear = Number(m[1]);
2598
- // }
2599
- // m = text.match(/(\d\d\d\d)/);
2600
- // if (m) {
2601
- // if (Number(m[1])>licenseYear) {
2602
- // licenseYear = Number(m[1]);
2603
- // }
2604
- // }
2605
-
2606
- // console.log(`License year ${licenseYear}`);
2607
- // console.log(`Current year ${year}`);
2608
- // console.log(`Commit year ${commitYear}`);
2609
- // console.log(`NPM year ${npmYear}`);
2610
-
2611
- // const valid = (licenseYear === year || licenseYear >= commitYear || licenseYear >=npmYear);
2612
- // if (!valid) {
2613
- // const m = text.match(/(\d\d\d\d)-\d\d\d\d/);
2614
- // if (m) {
2615
- // context.errors.push(`[E701] No actual year found in LICENSE. Please add "Copyright (c) ${m[1]}-${year} ${getAuthor(context.packageJson.author)}" at the start of LICENSE`);
2616
- // } else {
2617
- // context.errors.push(`[E701] No actual year found in LICENSE. Please add "Copyright (c) ${year} ${getAuthor(context.packageJson.author)}" at the start of LICENSE`);
2618
- // }
2619
- // } else {
2620
- // context.checks.push('Valid copyright year found in LICENSE');
2621
- // }
2622
- // }
2623
- // }
2624
- // resolve(context);
2625
- // })
2626
- // .catch(e => reject(e));
2627
- // });
2628
- // }
2629
-
2630
- // // E80x
2631
- // function checkGithubRepo(context) {
2632
- // return new Promise((resolve) => {
2633
- // console.log('\ncheckGithubRepo [E8xx]');
2634
-
2635
- // if (!context.githubApiData.description) {
2636
- // context.errors.push(`[E801] No repository about text found. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add the description.`);
2637
- // } else {
2638
- // context.checks.push('Github repository about found.');
2639
- // }
2640
-
2641
- // if (!context.githubApiData.topics || context.githubApiData.topics.length === 0) {
2642
- // context.errors.push(`[E802] No topics found in the repository. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add some topics.`);
2643
- // } else {
2644
- // context.checks.push('Github repository about found.');
2645
- // }
2646
-
2647
- // if (context.githubApiData.archived) {
2648
- // context.errors.push(`[E803] Archived repositories are not allowed.`);
2649
- // }
2650
-
2651
- // // max E803 - limited to 849
2652
- // resolve(context);
2653
- // });
2654
- // }
2655
-
2656
- // function paddingNum(num) {
2657
- // if (num >= 10) return num;
2658
- // return '0' + num;
2659
- // }
2660
-
2661
- // // E85x
2662
- // function checkNpmIgnore(context) {
2663
- // const checkFiles = [
2664
- // 'node_modules/',
2665
- // 'test/',
2666
- // 'src/',
2667
- // 'appveyor.yml',
2668
- // '.travis.yml',
2669
- // 'tsconfig.json',
2670
- // 'tsconfig.build.json',
2671
- // 'iob_npm.done',
2672
- // // '.git/',
2673
- // // '.github/',
2674
- // // '.idea/',
2675
- // // '.gitignore',
2676
- // // '.npmignore',
2677
- // // '.travis.yml',
2678
- // // '.babelrc',
2679
- // // '.editorconfig',
2680
- // // '.eslintignore',
2681
- // // '.eslintrc.js',
2682
- // // '.fimbullinter.yaml',
2683
- // // '.lgtm.yml',
2684
- // // '.prettierignore',
2685
- // // '.prettierignore',
2686
- // // '.prettierrc.js',
2687
- // // '.vscode/',
2688
- // ];
2689
-
2690
- // // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.npmignore
2691
- // console.log('checkNpmIgnore [E85x]');
2692
- // if (context.packageJson.files && context.packageJson.files.length) {
2693
- // if (context.filesList.includes('.npmignore')) {
2694
- // context.warnings.push(`[E851] .npmignore found but "files" is used at package.json. Please remove .npmignore.`);
2695
- // } else {
2696
- // context.checks.push('package.json "files" already used.');
2697
- // }
2698
- // return Promise.resolve(context);
2699
- // }
2700
-
2701
- // // package.json files section is NOT used
2702
- // if (!context.filesList.includes('.npmignore')) {
2703
- // context.warnings.push(`[E852] .npmignore not found`);
2704
- // } else {
2705
- // context.warnings.push(`[W853] .npmignore found - consider using package.json object "files" instead.`);
2706
-
2707
- // const rules = (context['/.npmignore'] || '').split('\n').map(line => line.trim().replace('\r', '')).filter(line => line);
2708
- // let tooComplexToCheck = false;
2709
- // rules.forEach((name, i) => {
2710
- // if (name.includes('*')) {
2711
- // rules[i] = new RegExp(name
2712
- // .replace('.', '\\.')
2713
- // .replace('/', '\\/')
2714
- // .replace('**', '.*')
2715
- // .replace('*', '[^\\/]*')
2716
- // );
2717
- // }
2718
- // if (name.startsWith('!')) {
2719
- // tooComplexToCheck = true;
2720
- // }
2721
- // });
2722
-
2723
- // // There's no need to put node_modules in `.npmignore`. npm will never publish node_modules in the package, except if one of the modules is explicitly mentioned in bundledDependencies.
2724
- // /*if (!rules.includes('node_modules') && !rules.includes('/node_modules') && !rules.includes('/node_modules/*') && !rules.includes('node_modules/*')) {
2725
- // !check && context.errors.push(`[E854] node_modules not found in `.npmignore``);
2726
- // }*/
2727
- // if (!tooComplexToCheck) {
2728
- // if (!rules.includes('iob_npm.done') && !rules.includes('/iob_npm.done')) {
2729
- // !check && context.errors.push(`[E853] iob_npm.done not found in .npmignore`);
2730
- // }
2731
-
2732
- // checkFiles.forEach((file, i) => {
2733
- // if (context.filesList.includes(file)) {
2734
- // // maybe it is with regex
2735
- // const check = rules.some(rule => {
2736
- // if (typeof rule === 'string') {
2737
- // return rule === file || rule === file.replace(/\/$/, '');
2738
- // } else {
2739
- // return rule.test(file);
2740
- // }
2741
- // });
2742
-
2743
- // !check && context.errors.push(`[E8${paddingNum(i + 61)}] file ${file} found in repository, but not found in .npmignore`);
2744
- // }
2745
- // });
2746
- // }
2747
- // }
2748
- // return Promise.resolve(context);
2749
- // }
2750
-
2751
- // // E9xx
2752
- // function checkGitIgnore(context) {
2753
- // const checkFiles = [
2754
- // '.idea',
2755
- // 'tmp',
2756
- // 'node_modules',
2757
- // 'iob_npm.done',
2758
- // ];
2759
-
2760
- // // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.gitignore
2761
- // console.log('\ncheckGitIgnore [E9xx]');
2762
- // if (!context.filesList.includes('.gitignore')) {
2763
- // context.errors.push(`[E901] .gitignore not found`);
2764
- // } else {
2765
- // const rules = (context['/.gitignore'] || '').split('\n').map(line => line.trim().replace('\r', '')).filter(line => line);
2766
- // rules.forEach((name, i) => {
2767
- // if (name.includes('*')) {
2768
- // rules[i] = new RegExp(name
2769
- // .replace('.', '\\.')
2770
- // .replace('/', '\\/')
2771
- // .replace('**', '.*')
2772
- // .replace('*', '[^\\/]*')
2773
- // );
2774
- // }
2775
- // });
2776
-
2777
- // if (!rules.includes('node_modules') && !rules.includes('/node_modules') && !rules.includes('/node_modules/*') && !rules.includes('node_modules/*')) {
2778
- // !check && context.errors.push(`[E902] node_modules not found in .npmignore`);
2779
- // }
2780
- // if (!rules.includes('iob_npm.done') && !rules.includes('/iob_npm.done')) {
2781
- // !check && context.errors.push(`[E903] iob_npm.done not found in .gitignore`);
2782
- // }
75
+ function getGithubApiData(context) {
76
+ return new Promise((resolve, reject) => {
77
+ console.log('\ngetGithubApiData');
78
+ axios.get(context.githubUrlApi, { cache: false })
79
+ .then(response => {
80
+ context.githubApiData = response.data;
81
+ // console.log(`API Data: ${JSON.stringify(context.githubApiData)}`);
2783
82
 
2784
- // checkFiles.forEach(file => {
2785
- // if (context.filesList.includes(file)) {
2786
- // // maybe it is with regex
2787
- // const check = rules.some(rule => {
2788
- // if (typeof rule === 'string') {
2789
- // return rule === file || rule === file.replace(/\/$/, '');
2790
- // } else {
2791
- // return rule.test(file);
2792
- // }
2793
- // });
83
+ if (!context.branch) {
84
+ context.branch = context.githubApiData.default_branch; // main vs. master
85
+ console.log(`Branch was not defined by user - checking branch: ${context.branch}`);
86
+ }
2794
87
 
2795
- // !check && context.errors.push(`[E904] file ${file} found in repository, but not found in .gitignore`);
2796
- // }
2797
- // });
2798
- // }
88
+ context.githubUrl = `${context.githubUrlOriginal.replace('https://github.com', 'https://raw.githubusercontent.com')}/${context.branch}`;
89
+ console.log(`Original URL: ${context.githubUrlOriginal}`);
90
+ console.log(`raw: ${context.githubUrl}`);
91
+ console.log(`api: ${context.githubUrlApi}`);
2799
92
 
2800
- // return Promise.resolve(context);
2801
- // }
93
+ resolve(context);
94
+ })
95
+ .catch(e => {
96
+ context.errors.push(`[E000] FATAL: cannot access repository ${context.githubUrlApi}`);
97
+ reject(e.toJSON());
98
+ });// E0xx
99
+ });
100
+ }
2802
101
 
2803
102
  function makeResponse(code, data) {
2804
103
  return {