@iobroker/repochecker 3.1.4 → 3.2.0

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
@@ -31,7 +31,6 @@ const M700_License = require('./lib/M700_License.js');
31
31
  const M800_Github = require('./lib/M800_Github.js');
32
32
  const M900_GitNpmIgnore = require('./lib/M900_GitNpmIgnore.js');
33
33
 
34
-
35
34
  // disable axios caching
36
35
  axios.defaults.headers = {
37
36
  'Cache-Control': 'no-cache',
@@ -39,7 +38,6 @@ axios.defaults.headers = {
39
38
  'Expires': '0',
40
39
  };
41
40
 
42
-
43
41
  // Error ranges
44
42
  // E0xx
45
43
  // check package.json
@@ -71,12 +69,12 @@ axios.defaults.headers = {
71
69
  // E9xx
72
70
  // check .gitignore file
73
71
 
74
-
75
72
  function getGithubApiData(context) {
76
73
  return new Promise((resolve, reject) => {
77
74
  console.log('\ngetGithubApiData');
78
- axios.get(context.githubUrlApi, { cache: false })
79
- .then(response => {
75
+ axios
76
+ .get(context.githubUrlApi, { cache: false })
77
+ .then((response) => {
80
78
  context.githubApiData = response.data;
81
79
  // console.log(`API Data: ${JSON.stringify(context.githubApiData)}`);
82
80
 
@@ -92,10 +90,10 @@ function getGithubApiData(context) {
92
90
 
93
91
  resolve(context);
94
92
  })
95
- .catch(e => {
93
+ .catch((e) => {
96
94
  context.errors.push(`[E000] FATAL: cannot access repository ${context.githubUrlApi}`);
97
95
  reject(e);
98
- });// E0xx
96
+ }); // E0xx
99
97
  });
100
98
  }
101
99
 
@@ -104,18 +102,18 @@ function makeResponse(code, data) {
104
102
  statusCode: code || 200,
105
103
  headers: {
106
104
  'Access-Control-Allow-Origin': '*', // Required for CORS support to work
107
- 'Access-Control-Allow-Credentials': true // Required for cookies, authorization headers with HTTPS
105
+ 'Access-Control-Allow-Credentials': true, // Required for cookies, authorization headers with HTTPS
108
106
  },
109
- body: typeof data === 'string' ? data : JSON.stringify(data)
107
+ body: typeof data === 'string' ? data : JSON.stringify(data),
110
108
  };
111
109
  }
112
110
 
113
111
  function check(request, ctx, callback) {
114
- // console.log('PROCESS: ' + JSON.stringify(request));
112
+ // console.log('PROCESS: ' + JSON.stringify(request));
115
113
  if (!request.queryStringParameters.url) {
116
- return callback(null, makeResponse(500, {error: 'No github URL provided'}));
114
+ return callback(null, makeResponse(500, { error: 'No github URL provided' }));
117
115
  } else {
118
- const context = {checks: [], errors: [], warnings: []};
116
+ const context = { checks: [], errors: [], warnings: [] };
119
117
  let githubUrl = request.queryStringParameters.url;
120
118
  const githubBranch = request.queryStringParameters.branch;
121
119
 
@@ -136,46 +134,52 @@ function check(request, ctx, callback) {
136
134
  context.branch = githubBranch || null;
137
135
 
138
136
  getGithubApiData(context)
139
- .then(context => M800_Github.getCommitInfos(context))
140
- .then(context => M000_PackageJson.getPackageJson(context))
141
- .then(context => M100_IOPackageJson.getIOPackageJson(context))
142
- .then(context => M000_PackageJson.checkPackageJson(context))
143
- .then(context => M100_IOPackageJson.checkIOPackageJson(context))
144
- .then(context => M250_Npm.checkNpm(context))
145
- .then(context => M400_Repository.checkRepository(context))
146
- .then(context => M500_Code.checkCode(context))
147
- .then(context => M300_Testing.checkTests(context))
148
- .then(context => M800_Github.checkGithubRepo(context))
149
- .then(context => M600_Readme.checkReadme(context))
150
- .then(context => M700_License.checkLicenseFile(context))
151
- .then(context => M900_GitNpmIgnore.checkNpmIgnore(context))
152
- .then(context => M900_GitNpmIgnore.checkGitIgnore(context))
153
- .then(context => {
154
- return callback(null, makeResponse(200, {
155
- result: 'OK',
156
- checks: context.checks,
157
- errors: context.errors,
158
- warnings: context.warnings,
159
- version,
160
- hasTravis: context.hasTravis,
161
- lastCommitSha: context.lastCommitSha,
162
- }));
137
+ .then((context) => M800_Github.getCommitInfos(context))
138
+ .then((context) => M000_PackageJson.getPackageJson(context))
139
+ .then((context) => M100_IOPackageJson.getIOPackageJson(context))
140
+ .then((context) => M000_PackageJson.checkPackageJson(context))
141
+ .then((context) => M100_IOPackageJson.checkIOPackageJson(context))
142
+ .then((context) => M250_Npm.checkNpm(context))
143
+ .then((context) => M400_Repository.checkRepository(context))
144
+ .then((context) => M500_Code.checkCode(context))
145
+ .then((context) => M300_Testing.checkTests(context))
146
+ .then((context) => M800_Github.checkGithubRepo(context))
147
+ .then((context) => M600_Readme.checkReadme(context))
148
+ .then((context) => M700_License.checkLicenseFile(context))
149
+ .then((context) => M900_GitNpmIgnore.checkNpmIgnore(context))
150
+ .then((context) => M900_GitNpmIgnore.checkGitIgnore(context))
151
+ .then((context) => {
152
+ return callback(
153
+ null,
154
+ makeResponse(200, {
155
+ result: 'OK',
156
+ checks: context.checks,
157
+ errors: context.errors,
158
+ warnings: context.warnings,
159
+ version,
160
+ hasTravis: context.hasTravis,
161
+ lastCommitSha: context.lastCommitSha,
162
+ }),
163
+ );
163
164
  })
164
- .catch(err => {
165
+ .catch((err) => {
165
166
  console.error(`GLOBAL ERROR: ${err.toString()}, ${JSON.stringify(err)}`);
166
167
  context.errors.push(`[E999] GLOBAL ERROR: ${err.toString()}, ${JSON.stringify(err)}`);
167
168
 
168
- return callback(null, makeResponse(200, {
169
- result: 'Errors found',
170
- checks: context.checks,
171
- errors: context.errors,
172
- issues,
173
- warnings: context.warnings,
174
- version,
175
- hasTravis: context.hasTravis,
176
- lastCommitSha: context.lastCommitSha,
177
- error: `${err.request ? err.request.path : ''} ${err.message}`,
178
- }));
169
+ return callback(
170
+ null,
171
+ makeResponse(200, {
172
+ result: 'Errors found',
173
+ checks: context.checks,
174
+ errors: context.errors,
175
+ issues,
176
+ warnings: context.warnings,
177
+ version,
178
+ hasTravis: context.hasTravis,
179
+ lastCommitSha: context.lastCommitSha,
180
+ error: `${err.request ? err.request.path : ''} ${err.message}`,
181
+ }),
182
+ );
179
183
  });
180
184
  }
181
185
  }
@@ -191,17 +195,38 @@ function getText(text, lang) {
191
195
  return text;
192
196
  }
193
197
 
194
- common.setDebug(true); /* DEBUG*/
195
-
196
198
  if (typeof module !== 'undefined' && module.parent) {
197
199
  exports.handler = check;
198
200
  } else {
199
- let repoUrl = 'https://github.com/klein0r/ioBroker.luftdaten';
201
+ let repoUrl = null;
200
202
  let repoBranch = null;
201
203
 
204
+ // check options
205
+ if (process.argv.includes('-d')) {
206
+ process.argv.splice(process.argv.indexOf('-d'), 1);
207
+ common.setDebug(true);
208
+ }
209
+
210
+ if (process.argv.includes('--debug')) {
211
+ process.argv.splice(process.argv.indexOf('--debug'), 1);
212
+ common.setDebug(true);
213
+ }
214
+
215
+ if (process.argv.includes('--local')) {
216
+ process.argv.splice(process.argv.indexOf('--local'), 1);
217
+ common.setLocal(true);
218
+ }
219
+
202
220
  // Get url from parameters if possible
203
221
  if (process.argv.length > 2) {
204
222
  repoUrl = process.argv[2];
223
+
224
+ if (!repoUrl.toLowerCase().includes('github.com')) {
225
+ repoUrl = `https://github.com/${repoUrl}`;
226
+ }
227
+ } else {
228
+ console.log('ERROR: No repository specified');
229
+ process.exit(1);
205
230
  }
206
231
 
207
232
  // Get branch from parameters if possible
@@ -210,65 +235,66 @@ if (typeof module !== 'undefined' && module.parent) {
210
235
  }
211
236
 
212
237
  console.log(`Checking repository ${repoUrl} (branch ${repoBranch})`);
213
- check({
214
- queryStringParameters: {
215
- url: repoUrl,
216
- branch: repoBranch,
217
- }
218
- }, null, (err, data) => {
219
- const context = JSON.parse(data.body);
220
- console.log(context.result);
221
-
222
- console.log('\n\n########## SUMMARY ##########');
223
- if (context.errors.length) {
224
- console.log('\n\nErrors:');
225
- context.errors.sort().forEach(err => {
226
- const issue = err.substring(1, 5);
227
- console.error(err);
228
- if (issues[issue]) {
229
- //if (issues[issue].title) {
230
- // console.error(getText(issues[issue].title, 'en'));
231
- //}
232
- if (issues[issue].explanation) {
233
- console.error(getText(issues[issue].explanation, 'en'));
234
- }
235
- if (issues[issue].resolving) {
236
- console.error(getText(issues[issue].resolving, 'en'));
237
- }
238
- if (issues[issue].notes) {
239
- console.error(getText(issues[issue].notes, 'en'));
240
- }
241
- }
238
+ check(
239
+ {
240
+ queryStringParameters: {
241
+ url: repoUrl,
242
+ branch: repoBranch,
243
+ },
244
+ },
245
+ null,
246
+ (err, data) => {
247
+ const context = JSON.parse(data.body);
248
+ console.log(context.result);
242
249
 
243
- });
244
- } else {
245
- console.log('\n\nNO errors encountered.');
246
- }
247
- if (context.warnings.length) {
248
- console.log('\nWarnings:');
249
- context.warnings.sort().forEach(err => {
250
- const issue = err.substring(1, 5);
251
- console.warn(err);
252
- if (issues[issue]) {
253
- //if (issues[issue].title) {
254
- // console.warn(getText(issues[issue].title, 'en'));
255
- //}
256
- if (issues[issue].explanation) {
257
- console.warn(getText(issues[issue].explanation, 'en'));
258
- }
259
- if (issues[issue].resolving) {
260
- console.warn(getText(issues[issue].resolving, 'en'));
250
+ console.log('\n\n########## SUMMARY ##########');
251
+ if (context.errors.length) {
252
+ console.log('\n\nErrors:');
253
+ context.errors.sort().forEach((err) => {
254
+ const issue = err.substring(1, 5);
255
+ console.error(err);
256
+ if (issues[issue]) {
257
+ //if (issues[issue].title) {
258
+ // console.error(getText(issues[issue].title, 'en'));
259
+ //}
260
+ if (issues[issue].explanation) {
261
+ console.error(getText(issues[issue].explanation, 'en'));
262
+ }
263
+ if (issues[issue].resolving) {
264
+ console.error(getText(issues[issue].resolving, 'en'));
265
+ }
266
+ if (issues[issue].notes) {
267
+ console.error(getText(issues[issue].notes, 'en'));
268
+ }
261
269
  }
262
- if (issues[issue].notes) {
263
- console.warn(getText(issues[issue].notes, 'en'));
270
+ });
271
+ } else {
272
+ console.log('\n\nNO errors encountered.');
273
+ }
274
+ if (context.warnings.length) {
275
+ console.log('\nWarnings:');
276
+ context.warnings.sort().forEach((err) => {
277
+ const issue = err.substring(1, 5);
278
+ console.warn(err);
279
+ if (issues[issue]) {
280
+ //if (issues[issue].title) {
281
+ // console.warn(getText(issues[issue].title, 'en'));
282
+ //}
283
+ if (issues[issue].explanation) {
284
+ console.warn(getText(issues[issue].explanation, 'en'));
285
+ }
286
+ if (issues[issue].resolving) {
287
+ console.warn(getText(issues[issue].resolving, 'en'));
288
+ }
289
+ if (issues[issue].notes) {
290
+ console.warn(getText(issues[issue].notes, 'en'));
291
+ }
264
292
  }
265
- }
266
-
267
- });
268
- } else {
269
- console.log('\n\nNO warnings encountered.');
270
- }
271
- console.log(`\ncreated by repochecker ${context.version} based on commit ${context.lastCommitSha}`);
272
- });
293
+ });
294
+ } else {
295
+ console.log('\n\nNO warnings encountered.');
296
+ }
297
+ console.log(`\ncreated by repochecker ${context.version} based on commit ${context.lastCommitSha}`);
298
+ },
299
+ );
273
300
  }
274
-
@@ -271,7 +271,7 @@ async function checkPackageJson(context) {
271
271
  if (context.packageJson.dependencies) {
272
272
  for (const blacklist in blacklistedDependenciesPackageJson) {
273
273
  if (context.packageJson.dependencies[blacklist]) {
274
- if (blacklistedDependenciesPackageJson[blacklist].err){
274
+ if (blacklistedDependenciesPackageJson[blacklist].err) {
275
275
  context.errors.push(`[E050] ${blacklistedDependenciesPackageJson[blacklist].msg}`);
276
276
  } else {
277
277
  context.warnings.push(`[W051] ${blacklistedDependenciesPackageJson[blacklist].msg}`);
@@ -283,7 +283,7 @@ async function checkPackageJson(context) {
283
283
  if (context.packageJson.devDependencies) {
284
284
  for (const blacklist in blacklistedDevDependenciesPackageJson) {
285
285
  if (context.packageJson.devDependencies[blacklist]) {
286
- if (blacklistedDevDependenciesPackageJson[blacklist].err){
286
+ if (blacklistedDevDependenciesPackageJson[blacklist].err) {
287
287
  context.errors.push(`[E052] ${blacklistedDevDependenciesPackageJson[blacklist].msg}`);
288
288
  } else {
289
289
  context.warnings.push(`[W053] ${blacklistedDevDependenciesPackageJson[blacklist].msg}`);
@@ -328,16 +328,16 @@ async function checkPackageJson(context) {
328
328
  // 'engines': { 'node': '>= 18.1.2 < 19' }
329
329
  const nodeVal = context.packageJson.engines.node;
330
330
  const match = nodeVal.match(/^(?<cmp>[<>=~]+)?\s*(?<vers>\d+(\.\d+(\.\d+)?)?(-\w+\.\d+)?)/m);
331
- if ( ! match ) {
331
+ if (!match) {
332
332
  context.warnings.push(`[W027] Engines clause at at package.json ({'engines' : { 'node' : '${nodeVal}' } }") is not parseable.`);
333
333
  } else {
334
- common.debug( `node check: ${JSON.stringify(match.groups)}`);
335
- if ( match.groups.cmp !== '>' && match.groups.cmp !== '>=' ) {
334
+ common.debug(`node check: ${JSON.stringify(match.groups)}`);
335
+ if (match.groups.cmp !== '>' && match.groups.cmp !== '>=') {
336
336
  context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
337
337
  } else {
338
- if ( ! compareVersions.compare( match.groups.vers, requiredNodeVersion, '>=')) {
338
+ if (!compareVersions.compare(match.groups.vers, requiredNodeVersion, '>=')) {
339
339
  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.`);
340
- } else if ( ! compareVersions.compare( match.groups.vers, recommendedNodeVersion, '>=')) {
340
+ } else if (!compareVersions.compare(match.groups.vers, recommendedNodeVersion, '>=')) {
341
341
  context.warnings.push(`[W028] Minimum node.js version ${recommendedNodeVersion} recommended. Please adapt "{'engines' : { 'node' >= '${match.groups.vers}' } }" at package.json.`);
342
342
  } else {
343
343
  context.checks.push(`Correct node.js version ${match.groups.vers} requested by "engines" attribute at package.json.`);
@@ -355,12 +355,12 @@ async function checkPackageJson(context) {
355
355
  const requiredVersion = dependenciesPackageJson[dependency].required;
356
356
  const recommendedVersion = dependenciesPackageJson[dependency].recommended;
357
357
  let dependencyVersion = context.packageJson.dependencies[`${dependency}`] || '';
358
- dependencyVersion = dependencyVersion.replace(/[\^~]/,'' );
358
+ dependencyVersion = dependencyVersion.replace(/[\^~]/, '');
359
359
  if (!dependencyVersion) {
360
360
  context.errors.push(`[E032] No dependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to dependencies at package.json`);
361
- } else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
361
+ } else if (!compareVersions.compare(dependencyVersion, requiredVersion, '>=')) {
362
362
  context.errors.push(`[E033] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update dependencies at package.json`);
363
- } else if (! compareVersions.compare( dependencyVersion, recommendedVersion, '>=' )) {
363
+ } else if (!compareVersions.compare(dependencyVersion, recommendedVersion, '>=')) {
364
364
  context.warnings.push(`[W034] ${dependency} ${dependencyVersion} specified. ${recommendedVersion} is recommended. Please consider updating dependencies at package.json`);
365
365
  } else {
366
366
  context.checks.push('dependency ${dependency} ${dependencyVersion} is ok');
@@ -376,12 +376,12 @@ async function checkPackageJson(context) {
376
376
  const requiredVersion = devDependenciesPackageJson[dependency].required;
377
377
  const recommendedVersion = devDependenciesPackageJson[dependency].recommended;
378
378
  let dependencyVersion = context.packageJson.devDependencies[`${dependency}`] || '';
379
- dependencyVersion = dependencyVersion.replace(/[\^~]/,'' );
379
+ dependencyVersion = dependencyVersion.replace(/[\^~]/, '');
380
380
  if (!dependencyVersion) {
381
381
  context.errors.push(`[E035] No devDependency declared for ${dependency}. Please add "${dependency}":"${recommendedVersion}" to devDependencies at package.json`);
382
- } else if (! compareVersions.compare( dependencyVersion, requiredVersion, '>=' )) {
382
+ } else if (!compareVersions.compare(dependencyVersion, requiredVersion, '>=')) {
383
383
  context.errors.push(`[E036] ${dependency} ${dependencyVersion} specified. ${requiredVersion} is required as minimum, ${recommendedVersion} is recommended. Please update devDependencies at package.json`);
384
- } else if (! compareVersions.compare( dependencyVersion, recommendedVersion, '>=' )) {
384
+ } else if (!compareVersions.compare(dependencyVersion, recommendedVersion, '>=')) {
385
385
  context.warnings.push(`[W037] ${dependency} ${dependencyVersion} specified. ${recommendedVersion} is recommended. Please consider updating devDependencies at package.json`);
386
386
  } else {
387
387
  context.checks.push('devDependency ${dependency} ${dependencyVersion} is ok');
@@ -400,8 +400,8 @@ async function checkPackageJson(context) {
400
400
  ];
401
401
  for (const dependency in context.packageJson.dependencies) {
402
402
  if (!context.packageJson.dependencies[dependency].startsWith('^') &&
403
- !context.packageJson.dependencies[dependency].startsWith('~') &&
404
- !context.packageJson.dependencies[dependency].startsWith('>')
403
+ !context.packageJson.dependencies[dependency].startsWith('~') &&
404
+ !context.packageJson.dependencies[dependency].startsWith('>')
405
405
  ) {
406
406
  if (context.packageJson.dependencies[dependency].toLowerCase().includes('github.com')) {
407
407
  context.warnings.push(`[W043] dependency should not require a github version. Please change "${dependency}:${context.packageJson.dependencies[dependency]}"`);
@@ -415,8 +415,8 @@ async function checkPackageJson(context) {
415
415
 
416
416
  for (const dependency in context.packageJson.devDependencies) {
417
417
  if (!context.packageJson.devDependencies[dependency].startsWith('^') &&
418
- !context.packageJson.devDependencies[dependency].startsWith('~') &&
419
- !context.packageJson.devDependencies[dependency].startsWith('>')
418
+ !context.packageJson.devDependencies[dependency].startsWith('~') &&
419
+ !context.packageJson.devDependencies[dependency].startsWith('>')
420
420
  ) {
421
421
  if (context.packageJson.devDependencies[dependency].toLowerCase().includes('github.com')) {
422
422
  context.warnings.push(`[W045] devDependency should not require github versions. Please change "${dependency}:${context.packageJson.devDependencies[dependency]}"`);
@@ -437,7 +437,7 @@ async function checkPackageJson(context) {
437
437
  //console.log(` check ${log}`);
438
438
  tmp = tmp[element];
439
439
  if (!tmp) {
440
- //console.log(` ${log} does not exist`);
440
+ //console.log(` ${log} does not exist`);
441
441
  break;
442
442
  }
443
443
  }
@@ -448,9 +448,9 @@ async function checkPackageJson(context) {
448
448
  context.warnings.push(`[W038] ${blacklistPackageJson[blacklist].msg}`);
449
449
  }
450
450
  }
451
- // else {
452
- // console.log(`blacklist ${blacklist} no match`);
453
- // }
451
+ // else {
452
+ // console.log(`blacklist ${blacklist} no match`);
453
+ // }
454
454
  }
455
455
  context.checks.push('"blacklist (package)" checked.');
456
456
 
@@ -462,10 +462,10 @@ async function checkPackageJson(context) {
462
462
  const recommendedKeywords = ['ioBroker'];
463
463
  common.debug(`package.keywords: "${context.packageJson.keywords.join(', ')}"`);
464
464
  common.debug(`filtered: "${context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase()))}"`);
465
- if (context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase())).length === 0 ) {
465
+ if (context.packageJson.keywords.filter(keyword => !ignoredKeywords.includes(keyword.toLowerCase())).length === 0) {
466
466
  context.errors.push(`[E049] "keywords" within package.json must contain some keywords besides "${context.packageJson.keywords.join(', ')}" related to adapter`);
467
467
  }
468
- if (! recommendedKeywords.filter(keyword => context.packageJson.keywords.includes(keyword)).length > 0) {
468
+ if (!recommendedKeywords.filter(keyword => context.packageJson.keywords.includes(keyword)).length > 0) {
469
469
  context.warnings.push(`[W040] "keywords" within package.json should contain "${recommendedKeywords.join(', ')}"`);
470
470
  }
471
471
  if (forbiddenKeywords.filter(keyword => context.packageJson.keywords.map(k => k.toLowerCase()).includes(keyword)).length > 0) {