Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.x.x - split index.js into modules #291

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,435 changes: 2,727 additions & 2,708 deletions index.js

Large diffs are not rendered by default.

401 changes: 401 additions & 0 deletions lib/M000_PackageJson.js

Large diffs are not rendered by default.

658 changes: 658 additions & 0 deletions lib/M100_IOPackageJson.js

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions lib/M200_Npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';
/*
This module is a support module for iobroker.repochecker

Area checked: NPM
Numbering : 200 - 299

*/

const axios = require('axios');

// disable axios caching
axios.defaults.headers = {
'Cache-Control': 'no-cache',
'Pragma': 'no-cache',
'Expires': '0',
};


// const common = require('./common.js');

async function checkNpm(context) {
console.log('\ncheckNpm [E2xx]');
const response = await axios(`https://registry.npmjs.org/iobroker.${context.adapterName}`)
let body = response.data;
// bug in NPM some modules could be accessed via normal web page, but not by API
if (!body) {
try {
const _response = await axios(`https://www.npmjs.com/package/iobroker.${context.adapterName}`);
if (!_response.data) {
context.errors.push('[E200] Not found on npm. Please publish');
return context;
} else {
body = _response.data;

context.checks.push('Adapter found on npm');
if (!body.includes('href="/~bluefox"') && body.includes('href="/~iobluefox"')) {
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}"`);
} else {
context.checks.push('Bluefox found in collaborators on NPM');
}
}
} catch (error) {
context.errors.push('[E200] Not found on npm. Please publish');
return context;
}
} else {
context.checks.push('Adapter found on npm');
if (!body.maintainers ||
!body.maintainers.length ||
!body.maintainers.find(user => user.name === 'bluefox' || user.name === 'iobluefox')) {
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}"`);
} else {
context.checks.push('Bluefox found in collaborators on NPM');
}

if (!body['dist-tags'] ||
context.packageJson.version !== body['dist-tags'].latest
) {
if ( compareVersions.compare( body['dist-tags'].latest, context.packageJson.version, '>=' )) {
context.errors.push(`[E203] Version of package.json (${context.packageJson.version}) lower than latest version on NPM (${
(body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
} else {
context.warnings.push(`[W202] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${
(body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`);
}
} else {
context.checks.push(`Version of package.json ${context.packageJson.version} matches latest version on NPM`);
}
}

if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.news) {
const missingVersions = [];
for (const vers in context.ioPackageJson.common.news) {
//console.log(`[DEBUG] news for ${vers}`);
if (!body.versions[vers]) {
missingVersions.push(vers);
}
}
if (missingVersions.length) {
if (missingVersions.length === 1) {
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.`);
} else {
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.`);
}
} else {
context.checks.push(`All versions listed at news exist at npm`);
}
}

return context;
}

exports.checkNpm = checkNpm;
62 changes: 62 additions & 0 deletions lib/M300_Testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';
/*
This module is a support module for iobroker.repochecker

Area checked: Testing
Numbering : 300 - 399

*/

// const common = require('./common.js');

async function checkTests(context) {
console.log('\ncheckTests [E3xx]');
// if found some file in `\.github\workflows` with the test inside => it is OK too
if (context && context.filesList.find(name => name.startsWith('.github/workflows/') && name.endsWith('.yml') && name.toLowerCase().includes('test'))) {
context.checks.push('Tests found on github actions');
return context;
}

// const travisURL = `${context.githubUrlOriginal.replace('github.com', 'api.travis-ci.org')}.png`;
//
// return axios(travisURL)
// .then(response => {
// if (!response.data) {
// context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
// return context;
// }
// if (!response.headers || !response.headers['content-disposition']) {
// context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
// return context;
// }
// // inline; filename="passing.png"
// const m = response.headers['content-disposition'].match(/filename="(.+)"$/);
// if (!m) {
// context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
// return context;
// }
//
// if (m[1] === 'unknown.png') {
// context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
// return context;
// }
//
// context.checks.push('Found on travis-ci');
//
// context.warnings.push('[W302] Use github actions instead of travis-ci');
//
// if (m[1] !== 'passing.png') {
// context.errors.push('[E301] Tests on Travis-ci.org are broken. Please fix.');
// } else {
// context.checks.push('Tests are OK on travis-ci');
// }
//
// return context;
// // max number is E302
// });
// return Promise.resolve(context);

return context;
}

exports.checkTests = checkTests;
Loading