From 0c8c064bf9b60a91e00fa27fb5ba5e1e7a86b081 Mon Sep 17 00:00:00 2001 From: oweitman Date: Tue, 12 Nov 2024 18:51:24 +0100 Subject: [PATCH] streamlining the log and debug output --- index.js | 44 ++++++------ lib/M000_PackageJson.js | 12 ++-- lib/M100_IOPackageJson.js | 18 ++--- lib/M250_Npm.js | 6 +- lib/M300_Testing.js | 4 +- lib/M400_Repository.js | 14 ++-- lib/M500_Code.js | 36 +++++----- lib/M500__JsonConfig.js | 142 +++++++++++++++++++------------------- lib/M600_Readme.js | 20 +++--- lib/M700_License.js | 14 ++-- lib/M800_Github.js | 10 +-- lib/M900_GitNpmIgnore.js | 6 +- lib/common.js | 19 +++-- lib/config.js | 8 +-- 14 files changed, 180 insertions(+), 173 deletions(-) diff --git a/index.js b/index.js index 00b4592..c73e4d9 100644 --- a/index.js +++ b/index.js @@ -71,22 +71,22 @@ axios.defaults.headers = { function getGithubApiData(context) { return new Promise((resolve, reject) => { - console.log('\ngetGithubApiData'); + common.debug('\ngetGithubApiData'); axios .get(context.githubUrlApi, { cache: false }) .then((response) => { context.githubApiData = response.data; - // console.log(`API Data: ${JSON.stringify(context.githubApiData)}`); + // common.log(`API Data: ${JSON.stringify(context.githubApiData)}`); if (!context.branch) { context.branch = context.githubApiData.default_branch; // main vs. master - console.log(`Branch was not defined by user - checking branch: ${context.branch}`); + common.log(`Branch was not defined by user - checking branch: ${context.branch}`); } context.githubUrl = `${context.githubUrlOriginal.replace('https://github.com', 'https://raw.githubusercontent.com')}/${context.branch}`; - console.log(`Original URL: ${context.githubUrlOriginal}`); - console.log(`raw: ${context.githubUrl}`); - console.log(`api: ${context.githubUrlApi}`); + common.debug(`Original URL: ${context.githubUrlOriginal}`); + common.debug(`raw: ${context.githubUrl}`); + common.debug(`api: ${context.githubUrlApi}`); resolve(context); }) @@ -109,7 +109,7 @@ function makeResponse(code, data) { } function check(request, ctx, callback) { - // console.log('PROCESS: ' + JSON.stringify(request)); + // common.log('PROCESS: ' + JSON.stringify(request)); if (!request.queryStringParameters.url) { return callback(null, makeResponse(500, { error: 'No github URL provided' })); } else { @@ -163,7 +163,7 @@ function check(request, ctx, callback) { ); }) .catch((err) => { - console.error(`GLOBAL ERROR: ${err.toString()}, ${JSON.stringify(err)}`); + common.error(`GLOBAL ERROR: ${err.toString()}, ${JSON.stringify(err)}`); context.errors.push(`[E999] GLOBAL ERROR: ${err.toString()}, ${JSON.stringify(err)}`); return callback( @@ -225,7 +225,7 @@ if (typeof module !== 'undefined' && module.parent) { repoUrl = `https://github.com/${repoUrl}`; } } else { - console.log('ERROR: No repository specified'); + common.log('ERROR: No repository specified'); process.exit(1); } @@ -234,7 +234,7 @@ if (typeof module !== 'undefined' && module.parent) { repoBranch = process.argv[3]; } - console.log(`Checking repository ${repoUrl} (branch ${repoBranch})`); + common.log(`Checking repository ${repoUrl} (branch ${repoBranch})`); check( { queryStringParameters: { @@ -245,34 +245,34 @@ if (typeof module !== 'undefined' && module.parent) { null, (err, data) => { const context = JSON.parse(data.body); - console.log(context.result); + common.debug(context.result); - console.log('\n\n########## SUMMARY ##########'); + common.log('\n########## SUMMARY ##########'); if (context.errors.length) { - console.log('\n\nErrors:'); + common.log('\n\nErrors:'); context.errors.sort().forEach((err) => { const issue = err.substring(1, 5); - console.error(err); + common.error(err); if (issues[issue]) { //if (issues[issue].title) { - // console.error(getText(issues[issue].title, 'en')); + // common.error(getText(issues[issue].title, 'en')); //} if (issues[issue].explanation) { - console.error(getText(issues[issue].explanation, 'en')); + common.error(getText(issues[issue].explanation, 'en')); } if (issues[issue].resolving) { - console.error(getText(issues[issue].resolving, 'en')); + common.error(getText(issues[issue].resolving, 'en')); } if (issues[issue].notes) { - console.error(getText(issues[issue].notes, 'en')); + common.error(getText(issues[issue].notes, 'en')); } } }); } else { - console.log('\n\nNO errors encountered.'); + common.log('NO errors encountered.'); } if (context.warnings.length) { - console.log('\nWarnings:'); + common.log('Warnings:'); context.warnings.sort().forEach((err) => { const issue = err.substring(1, 5); console.warn(err); @@ -292,9 +292,9 @@ if (typeof module !== 'undefined' && module.parent) { } }); } else { - console.log('\n\nNO warnings encountered.'); + common.log('\n\nNO warnings encountered.'); } - console.log(`\ncreated by repochecker ${context.version} based on commit ${context.lastCommitSha}`); + common.log(`\ncreated by repochecker ${context.version} based on commit ${context.lastCommitSha}`); }, ); } diff --git a/lib/M000_PackageJson.js b/lib/M000_PackageJson.js index 15dd712..9431467 100644 --- a/lib/M000_PackageJson.js +++ b/lib/M000_PackageJson.js @@ -103,7 +103,7 @@ const blacklistPackageJson = { }; async function getPackageJson(context) { - console.log('\ngetPackageJson'); + common.debug('\ngetPackageJson'); const packageJson = await common.downloadFile(context.githubUrl, '/package.json'); context.packageJson = packageJson; @@ -118,7 +118,7 @@ async function getPackageJson(context) { } async function checkPackageJson(context) { - console.log('\ncheckPackageJson [E001 - E099]'); + common.log('[E001 - E099] checkPackageJson'); if (!context.githubUrlOriginal.match(/\/iobroker\./i)) { context.errors.push('[E002] No "ioBroker." found in the name of repository'); @@ -429,15 +429,15 @@ async function checkPackageJson(context) { } for (const blacklist in blacklistPackageJson) { - // console.log(`checking blacklist ${blacklist}`); + // common.log(`checking blacklist ${blacklist}`); let tmp = context.packageJson; let log = ''; for (const element of blacklist.split('.')) { log = `${log}.${element}`; - //console.log(` check ${log}`); + //common.log(` check ${log}`); tmp = tmp[element]; if (!tmp) { - //console.log(` ${log} does not exist`); + //common.log(` ${log} does not exist`); break; } } @@ -449,7 +449,7 @@ async function checkPackageJson(context) { } } // else { - // console.log(`blacklist ${blacklist} no match`); + // common.log(`blacklist ${blacklist} no match`); // } } context.checks.push('"blacklist (package)" checked.'); diff --git a/lib/M100_IOPackageJson.js b/lib/M100_IOPackageJson.js index ed07496..7644066 100644 --- a/lib/M100_IOPackageJson.js +++ b/lib/M100_IOPackageJson.js @@ -13,7 +13,7 @@ const sizeOf = require('image-size'); const common = require('./common.js'); async function getIOPackageJson(context) { - console.log('\ngetIOPackageJson'); + common.debug('\ngetIOPackageJson'); const ioPackageJson = await common.downloadFile(context.githubUrl, '/io-package.json'); context.ioPackageJson = ioPackageJson; @@ -71,7 +71,7 @@ const blacklistIOPackageJson = { async function checkIOPackageJson(context) { - console.log('\ncheckIOPackage [E100 - E249]'); + common.log('[E100 - E249] checkIOPackage'); if (!context.ioPackageJson.native) { context.errors.push('[E101] io-package.json must have at least empty "native" attribute'); @@ -97,10 +97,10 @@ async function checkIOPackageJson(context) { //const regex = new RegExp(suspiciousPhrases.join('|'), 'i'); let suspiciousKeys = Object.keys(context.ioPackageJson.native) || []; - // console.log(`native keys: ${suspiciousKeys.join()}`); + // common.log(`native keys: ${suspiciousKeys.join()}`); //suspiciousKeys = suspiciousKeys.filter( key => regex.test(key)); suspiciousKeys = suspiciousKeys.filter(key => suspiciousPhrases.includes(key.toLowerCase())); - // console.log(`suspicious keys: ${suspiciousKeys.join()}`); + // common.log(`suspicious keys: ${suspiciousKeys.join()}`); if (suspiciousKeys.length) { if (context.ioPackageJson.protectedNative) { @@ -510,7 +510,7 @@ async function checkIOPackageJson(context) { const jsControllerDependency = context.ioPackageJson.common.dependencies.find(dep => Object.keys(dep).find(attr => attr === 'js-controller')); if (jsControllerDependency) { - console.log(`Found current js-controller dependency "${jsControllerDependency['js-controller']}"`); + common.debug(`Found current js-controller dependency "${jsControllerDependency['js-controller']}"`); if (!jsControllerDependency['js-controller'].startsWith('>=')) { context.errors.push(`[E159] common.dependencies "js-controller" dependency should always allow future versions (>=x.x.x) - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`); @@ -589,15 +589,15 @@ async function checkIOPackageJson(context) { } for (const blacklist in blacklistIOPackageJson) { - //console.log(`checking blacklist ${blacklist}`); + //common.log(`checking blacklist ${blacklist}`); let tmp = context.ioPackageJson; let log = ''; for (const element of blacklist.split('.')) { log = `${log}.${element}`; - //console.log(` check ${log}`); + //common.log(` check ${log}`); tmp = tmp[element]; if (!tmp) { - //console.log(` ${log} does not exist`); + //common.log(` ${log} does not exist`); break; } } @@ -609,7 +609,7 @@ async function checkIOPackageJson(context) { } } //else { - // console.log(`blacklist ${blacklist} no match`); + // common.log(`blacklist ${blacklist} no match`); //} } context.checks.push('"blacklist (io-package)" checked.'); diff --git a/lib/M250_Npm.js b/lib/M250_Npm.js index a35ec3a..ba3b403 100644 --- a/lib/M250_Npm.js +++ b/lib/M250_Npm.js @@ -9,7 +9,7 @@ const axios = require('axios'); const compareVersions = require('compare-versions'); - +const common = require('./common.js'); // disable axios caching axios.defaults.headers = { @@ -22,7 +22,7 @@ axios.defaults.headers = { // const common = require('./common.js'); async function checkNpm(context) { - console.log('\ncheckNpm [E250 - 299]'); + common.log('[E250 - E299] checkNpm'); let body; try { const response = await axios(`https://registry.npmjs.org/iobroker.${context.adapterName}`); @@ -77,7 +77,7 @@ async function checkNpm(context) { 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}`); + //common.log(`[DEBUG] news for ${vers}`); if (!body.versions[vers]) { missingVersions.push(vers); } diff --git a/lib/M300_Testing.js b/lib/M300_Testing.js index 5fbe7b3..534dbfd 100644 --- a/lib/M300_Testing.js +++ b/lib/M300_Testing.js @@ -7,10 +7,10 @@ */ -// const common = require('./common.js'); +const common = require('./common.js'); async function checkTests(context) { - console.log('\ncheckTests [E300 - E399]'); + common.log('[E300 - E399] checkTests'); // 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'); diff --git a/lib/M400_Repository.js b/lib/M400_Repository.js index 93717e3..737651b 100644 --- a/lib/M400_Repository.js +++ b/lib/M400_Repository.js @@ -20,7 +20,7 @@ axios.defaults.headers = { const common = require('./common.js'); async function checkRepository(context) { - console.log('\ncheckRepository [E400 - E499]'); + common.log('[E400 - E499] checkRepository'); if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.type) { /* TODO: why check type here ? */ // download latest repo @@ -138,7 +138,7 @@ async function checkRepository(context) { body = _response.data; if (!body) { context.errors.push('[E429] Cannot download http://repo.iobroker.live/sources-dist-latest.json'); - throw('Cannot download http://repo.iobroker.live/sources-dist-latest.json'); // ABORT to avoid generating unuseable report + throw ('Cannot download http://repo.iobroker.live/sources-dist-latest.json'); // ABORT to avoid generating unuseable report } else { context.latestRepoLive = body; } @@ -147,7 +147,7 @@ async function checkRepository(context) { body = _response.data; if (!body) { context.errors.push('[E430] Cannot download http://repo.iobroker.live/sources-dist.json'); - throw('Cannot download http://repo.iobroker.live/sources-dist.json'); // ABORT to avoid generating unuseable report + throw ('Cannot download http://repo.iobroker.live/sources-dist.json'); // ABORT to avoid generating unuseable report } else { context.stableRepoLive = body; } @@ -162,7 +162,7 @@ async function checkRepository(context) { } else { const versDependency = dependencies[dependency]; const versRepository = context.latestRepoLive[dependency].version; - //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); + //common.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); if (!versDependency.startsWith('>=')) { context.warnings.push(`[W432] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`); } else { @@ -183,7 +183,7 @@ async function checkRepository(context) { } else { const versDependency = dependencies[dependency]; const versRepository = context.stableRepoLive[dependency].version; - //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); + //common.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); if (!versDependency.startsWith('>=')) { context.warnings.push(`[W434] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`); } else { @@ -213,7 +213,7 @@ async function checkRepository(context) { } else { const versDependency = dependencies[dependency]; const versRepository = context.latestRepoLive[dependency].version; - //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); + //common.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); if (!versDependency.startsWith('>=')) { context.warnings.push(`[W432] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`); } else { @@ -234,7 +234,7 @@ async function checkRepository(context) { } else { const versDependency = dependencies[dependency]; const versRepository = context.stableRepoLive[dependency].version; - //console.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); + //common.log( `DEBUG: dependency ${dependency} - ${versDependency} - latest ${versRepository}`); if (!versDependency.startsWith('>=')) { context.warnings.push(`[W434] Dependency '${dependency}':'${dependencies[dependency]}' should specify '>='`); } else { diff --git a/lib/M500_Code.js b/lib/M500_Code.js index 7510783..383cc86 100644 --- a/lib/M500_Code.js +++ b/lib/M500_Code.js @@ -98,7 +98,7 @@ function getAllFiles(context, dirPath, root, filesList) { // E5xx async function checkCode(context) { - console.log('\ncheckCode [E5xx]'); + common.log('[E5xx] checkCode'); const readFiles = [ '.npmignore', @@ -165,7 +165,7 @@ async function checkCode(context) { getAllFiles(context, process.cwd(), '', context.filesList); } else { const data = await common.downloadFile(context.githubUrlOriginal, `/archive/${context.branch}.zip`, true); - console.log(`${context.branch}.zip ${data.length} bytes`); + common.log(`${context.branch}.zip ${data.length} bytes`); let found = false; const bufferStream = new stream.PassThrough(); @@ -184,11 +184,11 @@ async function checkCode(context) { common.debug('on.entry ' + entry.path); if (root === '') { root = entry.path; - console.log(`Directory root set to ${root}`); + common.log(`Directory root set to ${root}`); } //if (!found && entry.type === 'Directory' && entry.path.match(/\/node_modules\/$/)) { if (!found && entry.type === 'Directory' && entry.path === `${root}node_modules/`) { - console.log(`Found ${entry.path}`); + common.log(`Found ${entry.path}`); found = true; context.errors.push( '[E500] Directory node_modules found in root of repository. Please delete directory.', @@ -233,55 +233,55 @@ async function checkCode(context) { (context.packageJson.devDependencies['@iobroker/adapter-react-v5'] || context.packageJson.devDependencies['react']) ) { - console.log('REACT detected at package devDependencies'); + common.log('REACT detected at package devDependencies'); usesReact = true; } if ( context.packageJson.dependencies && (context.packageJson.dependencies['@iobroker/adapter-react-v5'] || context.packageJson.dependencies['react']) ) { - console.log('REACT detected at package dependencies'); + common.log('REACT detected at package dependencies'); usesReact = true; } if (context['/src-admin/package.json']) { - //console.log('"src-admin/package.json" exists'); + //common.log('"src-admin/package.json" exists'); const packageJson = JSON.parse(context['/src-admin/package.json']); if (packageJson.devDependencies && packageJson.devDependencies['@iobroker/adapter-react-v5']) { - console.log('REACT detected at src-admin/package devDependencies'); + common.log('REACT detected at src-admin/package devDependencies'); usesReact = true; } if (packageJson.dependencies && packageJson.dependencies['@iobroker/adapter-react-v5']) { - console.log('REACT detected at src-admin/package dependencies'); + common.log('REACT detected at src-admin/package dependencies'); usesReact = true; } } if (context['/src-widgets/package.json']) { - //console.log('"src-widgets/package.json" exists'); + //common.log('"src-widgets/package.json" exists'); const packageJson = JSON.parse(context['/src-widgets/package.json']); if ( packageJson.devDependencies && (packageJson.devDependencies['@iobroker/adapter-react-v5'] || packageJson.devDependencies['react']) ) { - console.log('REACT detected at src-widgets/package devDependencies'); + common.log('REACT detected at src-widgets/package devDependencies'); usesReact = true; } if ( packageJson.dependencies && (packageJson.dependencies['@iobroker/adapter-react-v5'] || packageJson.dependencies['react']) ) { - console.log('REACT detected at src-widgets/package dependencies'); + common.log('REACT detected at src-widgets/package dependencies'); usesReact = true; } } if (context['/src/package.json']) { - //console.log('"src/package.json" exists'); + //common.log('"src/package.json" exists'); const packageJson = JSON.parse(context['/src/package.json']); if (packageJson.devDependencies && packageJson.devDependencies['@iobroker/adapter-react-v5']) { - // console.log('REACT detected'); + // common.log('REACT detected'); usesReact = true; } if (packageJson.dependencies && packageJson.dependencies['@iobroker/adapter-react-v5']) { - // console.log('REACT detected'); + // common.log('REACT detected'); usesReact = true; } } @@ -471,13 +471,13 @@ async function checkCode(context) { '[E518] "@alcalzone/release-script" (>=3.0.0) is used, but ".releaseconfig.json" not found. Please create.', ); } else { - console.log('context[/.releaseconfig.json: ' + context['/.releaseconfig.json']); + common.debug('context[/.releaseconfig.json: ' + context['/.releaseconfig.json']); try { const releaseConfigJson = JSON.parse(context['/.releaseconfig.json']); - console.log(`releaseConfigJson: ${releaseConfigJson}`); + common.debug(`releaseConfigJson: ${releaseConfigJson}`); const plugins = releaseConfigJson.plugins; - console.log(`plugins: ${plugins}`); + common.debug(`plugins: ${plugins}`); if (!context.packageJson.devDependencies['@alcalzone/release-script-plugin-iobroker']) { context.errors.push( '[E524] "@alcalzone/release-script" requires plugin "@alcalzone/release-script-plugin-iobroker". Please add.', diff --git a/lib/M500__JsonConfig.js b/lib/M500__JsonConfig.js index b05346c..d2f02a3 100644 --- a/lib/M500__JsonConfig.js +++ b/lib/M500__JsonConfig.js @@ -54,7 +54,7 @@ const stdAttributes = [ ]; const validComponents = { - 'accordion':check_accordion, + 'accordion': check_accordion, 'alive': check_alive, 'autocomplete': check_autocomplete, 'autocompleteSendTo': check_autocompleteSendTo, @@ -141,7 +141,7 @@ function handleResponsiveWarning(context, msg) { } } -function chk_responsive (context, path, jsonConfig, component, opts){ +function chk_responsive(context, path, jsonConfig, component, opts) { common.debug(`chk_responsive ${path}`); if (!opts || !opts.sizesOptional) { @@ -156,283 +156,283 @@ function chk_responsive (context, path, jsonConfig, component, opts){ } } - if ( jsonConfig.xs && jsonConfig.xs != 12) { + if (jsonConfig.xs && jsonConfig.xs != 12) { handleResponsiveWarning(context, `[W508] attribute "xs" for ${component} should specify a value of "12" at ${path}`); } let ii = 12; if (jsonConfig.xs) ii = jsonConfig.xs; - if (jsonConfig.sm && jsonConfig.sm > ii ) { + if (jsonConfig.sm && jsonConfig.sm > ii) { handleResponsiveError(context, `[E509] "sm" value (${jsonConfig.sm}) for ${component} greater then value for smaller displays`); } else { ii = jsonConfig.sm; } - if (jsonConfig.md && jsonConfig.md > ii ) { + if (jsonConfig.md && jsonConfig.md > ii) { handleResponsiveError(context, `[E509] "md" value (${jsonConfig.md}) for ${component} greater then value for smaller displays`); } else { ii = jsonConfig.md; } - if (jsonConfig.lg && jsonConfig.lg > ii ) { + if (jsonConfig.lg && jsonConfig.lg > ii) { handleResponsiveError(context, `[E509] "lg" value (${jsonConfig.lg}) for ${component} greater then value for smaller displays`); } else { ii = jsonConfig.lg; } - if (jsonConfig.xl && jsonConfig.xl > ii ) { + if (jsonConfig.xl && jsonConfig.xl > ii) { handleResponsiveError(context, `[E509] "xl" value (${jsonConfig.xl}) for ${component} greater then value for smaller displays`); } } -function check_accordion (context, path, jsonConfig, inTable){ +function check_accordion(context, path, jsonConfig, inTable) { common.debug(`check_accordion ${path}`); chk_responsive(context, path, jsonConfig, 'accordion'); } -function check_alive(context, path, jsonConfig, inTable){ +function check_alive(context, path, jsonConfig, inTable) { common.debug(`check_alive ${path}`); chk_responsive(context, path, jsonConfig, 'alive'); } -function check_autocomplete(context, path, jsonConfig, inTable){ +function check_autocomplete(context, path, jsonConfig, inTable) { common.debug(`check_autocomplete ${path}`); chk_responsive(context, path, jsonConfig, 'autocomplete'); } -function check_autocompleteSendTo(context, path, jsonConfig, inTable){ +function check_autocompleteSendTo(context, path, jsonConfig, inTable) { common.debug(`check_autocompleteSendTo ${path}`); chk_responsive(context, path, jsonConfig, 'autocompleteSendTo'); } -function check_certificate(context, path, jsonConfig, inTable){ +function check_certificate(context, path, jsonConfig, inTable) { common.debug(`check_certificate ${path}`); chk_responsive(context, path, jsonConfig, 'certificate'); } -function check_certificates(context, path, jsonConfig, inTable){ +function check_certificates(context, path, jsonConfig, inTable) { common.debug(`check_certificates ${path}`); chk_responsive(context, path, jsonConfig, 'certificates'); } -function check_certificateCollection(context, path, jsonConfig, inTable){ +function check_certificateCollection(context, path, jsonConfig, inTable) { common.debug(`check_certificateCollection ${path}`); chk_responsive(context, path, jsonConfig, 'certificateCollection'); } -function check_checkbox(context, path, jsonConfig, inTable){ +function check_checkbox(context, path, jsonConfig, inTable) { common.debug(`check_checkbox ${path}`); chk_responsive(context, path, jsonConfig, 'checkbox'); } -function check_checkLicense(context, path, jsonConfig, inTable){ +function check_checkLicense(context, path, jsonConfig, inTable) { common.debug(`check_checkLicense ${path}`); chk_responsive(context, path, jsonConfig, 'checkLicense'); } -function check_chips(context, path, jsonConfig, inTable){ +function check_chips(context, path, jsonConfig, inTable) { common.debug(`check_chips ${path}`); chk_responsive(context, path, jsonConfig, 'chips'); } -function check_color(context, path, jsonConfig, inTable){ +function check_color(context, path, jsonConfig, inTable) { common.debug(`check_color ${path}`); chk_responsive(context, path, jsonConfig, 'color'); } -function check_coordinates(context, path, jsonConfig, inTable){ +function check_coordinates(context, path, jsonConfig, inTable) { common.debug(`check_coordinates ${path}`); chk_responsive(context, path, jsonConfig, 'coordinates'); } -function check_cron(context, path, jsonConfig, inTable){ +function check_cron(context, path, jsonConfig, inTable) { common.debug(`check_staticText ${path}`); chk_responsive(context, path, jsonConfig, 'cron'); } -function check_custom(context, path, jsonConfig, inTable){ +function check_custom(context, path, jsonConfig, inTable) { common.debug(`check_custom ${path}`); - chk_responsive(context, path, jsonConfig, 'custom', {sizesOptional:true}); + chk_responsive(context, path, jsonConfig, 'custom', { sizesOptional: true }); } -function check_datePicker(context, path, jsonConfig, inTable){ +function check_datePicker(context, path, jsonConfig, inTable) { common.debug(`check_datePicker ${path}`); chk_responsive(context, path, jsonConfig, 'datePicker'); } -function check_deviceManager(context, path, jsonConfig, inTable){ +function check_deviceManager(context, path, jsonConfig, inTable) { common.debug(`check_deviceManager ${path}`); - chk_responsive(context, path, jsonConfig, 'deviceManager', {sizesOptional:true}); + chk_responsive(context, path, jsonConfig, 'deviceManager', { sizesOptional: true }); } -function check_divider(context, path, jsonConfig, inTable){ +function check_divider(context, path, jsonConfig, inTable) { common.debug(`check_divider ${path}`); - chk_responsive(context, path, jsonConfig, 'divider', {sizesOptional:true}); + chk_responsive(context, path, jsonConfig, 'divider', { sizesOptional: true }); } -function check_file(context, path, jsonConfig, inTable){ +function check_file(context, path, jsonConfig, inTable) { common.debug(`check_file ${path}`); chk_responsive(context, path, jsonConfig, 'file'); } -function check_fileSelector(context, path, jsonConfig, inTable){ +function check_fileSelector(context, path, jsonConfig, inTable) { common.debug(`check_fileSelector ${path}`); chk_responsive(context, path, jsonConfig, 'fileSelector'); } -function check_func(context, path, jsonConfig, inTable){ +function check_func(context, path, jsonConfig, inTable) { common.debug(`check_func ${path}`); chk_responsive(context, path, jsonConfig, 'func'); } -function check_header(context, path, jsonConfig, inTable){ +function check_header(context, path, jsonConfig, inTable) { common.debug(`check_header ${path}`); - chk_responsive(context, path, jsonConfig, 'header', {sizesOptional:true}); + chk_responsive(context, path, jsonConfig, 'header', { sizesOptional: true }); } -function check_image(context, path, jsonConfig, inTable){ +function check_image(context, path, jsonConfig, inTable) { common.debug(`check_image ${path}`); chk_responsive(context, path, jsonConfig, 'image'); } -function check_imageSendTo(context, path, jsonConfig, inTable){ +function check_imageSendTo(context, path, jsonConfig, inTable) { common.debug(`check_imageSendTo ${path}`); chk_responsive(context, path, jsonConfig, 'imageSendTo'); } -function check_instance(context, path, jsonConfig, inTable){ +function check_instance(context, path, jsonConfig, inTable) { common.debug(`check_instance ${path}`); chk_responsive(context, path, jsonConfig, 'instance'); } -function check_interface(context, path, jsonConfig, inTable){ +function check_interface(context, path, jsonConfig, inTable) { common.debug(`check_interface ${path}`); chk_responsive(context, path, jsonConfig, 'interface'); } -function check_ip(context, path, jsonConfig, inTable){ +function check_ip(context, path, jsonConfig, inTable) { common.debug(`check_ip ${path}`); chk_responsive(context, path, jsonConfig, 'ip'); } -function check_jsonEditor(context, path, jsonConfig, inTable){ +function check_jsonEditor(context, path, jsonConfig, inTable) { common.debug(`check_jsonEditor ${path}`); chk_responsive(context, path, jsonConfig, 'jsonEditor'); } -function check_language(context, path, jsonConfig, inTable){ +function check_language(context, path, jsonConfig, inTable) { common.debug(`check_language ${path}`); chk_responsive(context, path, jsonConfig, 'language'); } -function check_license(context, path, jsonConfig, inTable){ +function check_license(context, path, jsonConfig, inTable) { common.debug(`check_license ${path}`); chk_responsive(context, path, jsonConfig, 'license'); } -function check_number(context, path, jsonConfig, inTable){ +function check_number(context, path, jsonConfig, inTable) { common.debug(`check_number ${path}`); chk_responsive(context, path, jsonConfig, 'number'); } -function check_objectId(context, path, jsonConfig, inTable){ +function check_objectId(context, path, jsonConfig, inTable) { common.debug(`check_objectId ${path}`); chk_responsive(context, path, jsonConfig, 'objectId'); } -function check_password(context, path, jsonConfig, inTable){ +function check_password(context, path, jsonConfig, inTable) { common.debug(`check_password ${path}`); chk_responsive(context, path, jsonConfig, 'password'); } -function check_pattern(context, path, jsonConfig, inTable){ +function check_pattern(context, path, jsonConfig, inTable) { common.debug(`check_pattern ${path}`); chk_responsive(context, path, jsonConfig, 'pattern'); } -function check_port(context, path, jsonConfig, inTable){ +function check_port(context, path, jsonConfig, inTable) { common.debug(`check_port ${path}`); chk_responsive(context, path, jsonConfig, 'port'); } -function check_qrCode(context, path, jsonConfig, inTable){ +function check_qrCode(context, path, jsonConfig, inTable) { common.debug(`check_qrCode ${path}`); chk_responsive(context, path, jsonConfig, 'qrCode'); } -function check_room(context, path, jsonConfig, inTable){ +function check_room(context, path, jsonConfig, inTable) { common.debug(`check_room ${path}`); chk_responsive(context, path, jsonConfig, 'room'); } -function check_select(context, path, jsonConfig, inTable){ +function check_select(context, path, jsonConfig, inTable) { common.debug(`check_select ${path}`); chk_responsive(context, path, jsonConfig, 'select'); } -function check_selectSendTo(context, path, jsonConfig, inTable){ +function check_selectSendTo(context, path, jsonConfig, inTable) { common.debug(`check_selectSendTo ${path}`); chk_responsive(context, path, jsonConfig, 'selectSendTo'); } -function check_sendTo(context, path, jsonConfig, inTable){ +function check_sendTo(context, path, jsonConfig, inTable) { common.debug(`check_sendTo ${path}`); chk_responsive(context, path, jsonConfig, 'sendTo'); } -function check_setState(context, path, jsonConfig, inTable){ +function check_setState(context, path, jsonConfig, inTable) { common.debug(`check_setState ${path}`); chk_responsive(context, path, jsonConfig, 'setState'); } -function check_slider(context, path, jsonConfig, inTable){ +function check_slider(context, path, jsonConfig, inTable) { common.debug(`check_slider ${path}`); chk_responsive(context, path, jsonConfig, 'slider'); } -function check_state(context, path, jsonConfig, inTable){ +function check_state(context, path, jsonConfig, inTable) { common.debug(`check_state ${path}`); chk_responsive(context, path, jsonConfig, 'state'); } -function check_staticImage(context, path, jsonConfig, inTable){ +function check_staticImage(context, path, jsonConfig, inTable) { common.debug(`check_staticImage ${path}`); - chk_responsive(context, path, jsonConfig, 'staticImage', {sizesOptional:true}); + chk_responsive(context, path, jsonConfig, 'staticImage', { sizesOptional: true }); } -function check_staticLink(context, path, jsonConfig, inTable){ +function check_staticLink(context, path, jsonConfig, inTable) { common.debug(`check_staticLink ${path}`); chk_responsive(context, path, jsonConfig, 'staticLink'); } -function check_staticText(context, path, jsonConfig, inTable){ +function check_staticText(context, path, jsonConfig, inTable) { common.debug(`check_staticText ${path}`); chk_responsive(context, path, jsonConfig, 'staticText'); } -function check_table(context, path, jsonConfig, inTable){ +function check_table(context, path, jsonConfig, inTable) { common.debug(`check_table ${path}`); chk_responsive(context, path, jsonConfig, 'table'); } -function check_text(context, path, jsonConfig, inTable){ +function check_text(context, path, jsonConfig, inTable) { common.debug(`check_text ${path}`); chk_responsive(context, path, jsonConfig, 'text'); } -function check_textSendTo(context, path, jsonConfig, inTable){ +function check_textSendTo(context, path, jsonConfig, inTable) { common.debug(`check_textSendTo ${path}`); chk_responsive(context, path, jsonConfig, 'testSendTo'); } -function check_timePicker(context, path, jsonConfig, inTable){ +function check_timePicker(context, path, jsonConfig, inTable) { common.debug(`check_timePicker ${path}`); chk_responsive(context, path, jsonConfig, 'timePicker'); } -function check_user(context, path, jsonConfig, inTable){ +function check_user(context, path, jsonConfig, inTable) { common.debug(`check_user ${path}`); chk_responsive(context, path, jsonConfig, 'user'); } -function check_uuid(context, path, jsonConfig, inTable){ +function check_uuid(context, path, jsonConfig, inTable) { common.debug(`check_uuid ${path}`); chk_responsive(context, path, jsonConfig, 'uuid'); } @@ -449,7 +449,7 @@ function checkComponent(context, path, jsonConfig) { if (validComponents[type] === undefined) { context.errors.push(`[E504] unexpected component "${type}" detected at ${path}`); - } else if (typeof(validComponents[type]) === 'function') { + } else if (typeof (validComponents[type]) === 'function') { (validComponents[type])(context, path, jsonConfig, false); } else { common.debug(`no checks defined for component ${type}`); @@ -475,10 +475,10 @@ function checkPanel(context, path, jsonConfig, isRoot) { 'label', ]; - //console.log('on PANEL entry'); - //console.log(jsonConfig); + //common.log('on PANEL entry'); + //common.log(jsonConfig); - const validAttributes = stdAttributes.concat(myAttributes).concat(isRoot?rootAttributes:[]); + const validAttributes = stdAttributes.concat(myAttributes).concat(isRoot ? rootAttributes : []); for (const key in jsonConfig) { common.debug(` scanning ${key}`); @@ -489,7 +489,7 @@ function checkPanel(context, path, jsonConfig, isRoot) { if (key === 'type') { if (jsonConfig[key] !== 'panel') { - console.log( `INTERNAL ERROR: unexpected type ${jsonConfig[key]} encountered while scanning "panel"`); + common.log(`INTERNAL ERROR: unexpected type ${jsonConfig[key]} encountered while scanning "panel"`); return; } } @@ -575,7 +575,7 @@ function checkJsonConfig(context, path, jsonConfig) { let baseType = 'panel'; if (!jsonConfig['type']) { - console.log(`*ERROR* base type (panel / tabs) not specified`); + common.log(`*ERROR* base type (panel / tabs) not specified`); } else { baseType = jsonConfig['type']; common.debug(` base type ${baseType}`); @@ -596,9 +596,9 @@ function checkJsonConfig(context, path, jsonConfig) { } if (key === 'items') { if (baseType == 'panel') { - checkPanel( context, `${path}/items`, jsonConfig, true); + checkPanel(context, `${path}/items`, jsonConfig, true); } else if (baseType == 'tabs') { - checkTabs( context, `${path}/items`, jsonConfig['items'], false); + checkTabs(context, `${path}/items`, jsonConfig['items'], false); } } } diff --git a/lib/M600_Readme.js b/lib/M600_Readme.js index b8a5a14..11022c4 100644 --- a/lib/M600_Readme.js +++ b/lib/M600_Readme.js @@ -21,7 +21,7 @@ function getAuthor(author) { async function checkReadme(context) { // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/README.md - console.log('\ncheckReadme [E600 - E699]'); + common.log('[E600 - E699] checkReadme'); const data = await common.downloadFile(context.githubUrl, '/README.md'); if (!data) { @@ -45,16 +45,16 @@ async function checkReadme(context) { try { const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' }); const npmJson = JSON.parse(result); - //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`); + //common.debug(`[DEBUG] ${JSON.stringify(npmJson)}`); if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) { const latest = npmJson['dist-tags'].latest; const timeStr = npmJson.time[latest]; npmYear = new Date(timeStr).getFullYear(); - // console.log(`${latest} - ${timeStr} - ${npmYear}`); + // common.debug(`${latest} - ${timeStr} - ${npmYear}`); } } catch (e) { context.warnings.push('[W606] Could not retrieve timestamp of LATEST revision at npm.'); - console.log(`Error executing "npm view"`); + common.debug(`Error executing "npm view"`); } const pos = data.indexOf('## License'); @@ -77,12 +77,12 @@ async function checkReadme(context) { } } - console.log(`README year ${readmeYear}`); - console.log(`Current year ${year}`); - console.log(`Commit year ${commitYear}`); - console.log(`NPM year ${npmYear}`); + common.debug(`README year ${readmeYear}`); + common.debug(`Current year ${year}`); + common.debug(`Commit year ${commitYear}`); + common.debug(`NPM year ${npmYear}`); - const valid = (readmeYear === year || readmeYear >= commitYear || readmeYear >=npmYear); + const valid = (readmeYear === year || readmeYear >= commitYear || readmeYear >= npmYear); if (!valid) { const m = text.match(/(\d\d\commitd\d)-\d\d\d\d/); if (m) { @@ -96,7 +96,7 @@ async function checkReadme(context) { } // languages = languagedetect.detect(data, 3); - //console.log(JSON.stringify(languages)); + //common.debug(JSON.stringify(languages)); } return context; diff --git a/lib/M700_License.js b/lib/M700_License.js index 776a71d..453e12a 100644 --- a/lib/M700_License.js +++ b/lib/M700_License.js @@ -21,7 +21,7 @@ function getAuthor(author) { async function checkLicenseFile(context) { // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/LICENSE - console.log('\ncheckLicenseFile [E7xx]'); + common.log('[E7xx] checkLicenseFile'); let data; try { @@ -40,14 +40,14 @@ async function checkLicenseFile(context) { try { const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' }); const npmJson = JSON.parse(result); - //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`); + //common.debug(`[DEBUG] ${JSON.stringify(npmJson)}`); if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) { const latest = npmJson['dist-tags'].latest; const timeStr = npmJson.time[latest]; npmYear = new Date(timeStr).getFullYear(); } } catch (e) { - console.log(`Error executing "npm view" - ${e}`); + common.debug(`Error executing "npm view" - ${e}`); } if (context.packageJson.license === 'MIT') { @@ -66,10 +66,10 @@ async function checkLicenseFile(context) { } } - console.log(`License year ${licenseYear}`); - console.log(`Current year ${year}`); - console.log(`Commit year ${commitYear}`); - console.log(`NPM year ${npmYear}`); + common.debug(`License year ${licenseYear}`); + common.debug(`Current year ${year}`); + common.debug(`Commit year ${commitYear}`); + common.debug(`NPM year ${npmYear}`); const valid = (licenseYear === year || licenseYear >= commitYear || licenseYear >= npmYear); if (!valid) { diff --git a/lib/M800_Github.js b/lib/M800_Github.js index f84b336..29fe072 100644 --- a/lib/M800_Github.js +++ b/lib/M800_Github.js @@ -23,13 +23,13 @@ axios.defaults.headers = { const common = require('./common.js'); async function getAllIssues(context) { - //console.log('\ngetAllIssues'); + //common.log('\ngetAllIssues'); const response = await axios(`${context.githubUrlApi}/issues`, {}); return response.data; } async function getCommitInfos(context) { - console.log('\ngetCommitInfos'); + common.debug('\ngetCommitInfos'); context.lastCommitSha = ''; context.lastCommitYear = 0; @@ -39,7 +39,7 @@ async function getCommitInfos(context) { common.debug(`reading github commits from ${url}`); response = await axios(url); } catch (e) { - console.log(`[INTERNAL] error downloading commit info from ${url} - ${e}`); + common.log(`[INTERNAL] error downloading commit info from ${url} - ${e}`); throw e; } @@ -56,7 +56,7 @@ async function getCommitInfos(context) { } async function checkGithubRepo(context) { - console.log('\ncheckGithubRepo [E8xx]'); + common.log('[E8xx] checkGithubRepo'); if (!context.githubApiData.description) { 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.`); @@ -75,7 +75,7 @@ async function checkGithubRepo(context) { } const issues = await getAllIssues(context); - for (const issue of issues){ + for (const issue of issues) { if (issue.pull_request) continue; if (issuesToWatch.includes(issue.title)) { context.errors.push(`[E804] Please process issue [[#${issue.number}] "${issue.title}"](${context.githubUrlOriginal}/issues/${issue.number})`); diff --git a/lib/M900_GitNpmIgnore.js b/lib/M900_GitNpmIgnore.js index 1489f20..9edb26f 100644 --- a/lib/M900_GitNpmIgnore.js +++ b/lib/M900_GitNpmIgnore.js @@ -14,7 +14,7 @@ - conversion of github to regex is wrong with multiple stars */ -// const common = require('./common.js'); +const common = require('./common.js'); function paddingNum(num) { if (num >= 10) return num; @@ -31,7 +31,7 @@ async function checkGitIgnore(context) { ]; // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.gitignore - console.log('\ncheckGitIgnore [E9xx]'); + common.log('[E9xx] checkGitIgnore'); if (!context.filesList) { throw ('FATAL:context.fileslist is undefined'); @@ -117,7 +117,7 @@ async function checkNpmIgnore(context) { ]; // https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.npmignore - console.log('\ncheckNpmIgnore [E95x]'); + common.log('[E95x] checkNpmIgnore'); if (context.packageJson.files && context.packageJson.files.length) { if (context.filesList.includes('.npmignore')) { context.warnings.push(`[W951] .npmignore found but "files" is used at package.json. Please remove .npmignore.`); diff --git a/lib/common.js b/lib/common.js index 646fec0..505d68e 100644 --- a/lib/common.js +++ b/lib/common.js @@ -23,11 +23,16 @@ function setDebug(flag) { function debug(msg) { gDebug && console.log(`[DEBUG] ${msg}`); } - +function log(msg) { + console.log(`${msg}`); +} +function error(msg) { + console.error(`${msg}`); +} let gLocal = false; function setLocal(flag) { gLocal = flag; - console.log(`[INFO] running in LOCAL mode`); + log(`[INFO] running in LOCAL mode`); } function isLocal() { @@ -40,7 +45,7 @@ function checkLanguages(langObj, languages) { async function downloadFile(githubUrl, path, binary, noError) { if (!isLocal()) { - console.log(`Download ${githubUrl}${path || ''}`); + log(`Download ${githubUrl}${path || ''}`); const options = {}; if (binary) { options.responseType = 'arraybuffer'; @@ -54,7 +59,7 @@ async function downloadFile(githubUrl, path, binary, noError) { throw e; } } else { - console.log(`Download local ${path || ''}`); + debug(`Download local ${path || ''}`); // remove first / from path path = path.replace(/^\/+/, ''); const file = await fs.readFile(path, binary ? null : 'utf8'); @@ -90,7 +95,7 @@ function getDependencyArray(deps) { // ] function getDependencies(deps) { const ret = {}; - console.log(`deps: ${JSON.stringify(deps)}, type ${typeof deps}`); + debug(`deps: ${JSON.stringify(deps)}, type ${typeof deps}`); if (deps instanceof Array) { for (const dep of deps) { if (typeof dep === 'object') { @@ -102,7 +107,7 @@ function getDependencies(deps) { } } } - console.log(`ret: ${JSON.stringify(ret)}`); + debug(`ret: ${JSON.stringify(ret)}`); return ret; } @@ -118,6 +123,8 @@ function maxVersion(v1, v2) { exports.setDebug = setDebug; exports.debug = debug; +exports.log = log; +exports.error = error; exports.setLocal = setLocal; exports.isLocal = isLocal; diff --git a/lib/config.js b/lib/config.js index 7e72350..ac53d04 100644 --- a/lib/config.js +++ b/lib/config.js @@ -4,6 +4,7 @@ */ +const common = require('./common.js'); const allowedLanguages = [ 'en', @@ -22,7 +23,7 @@ const allowedLanguages = [ const requiredLanguages = [ 'en', 'de', -// 'xx' // TESTING ONLY + // 'xx' // TESTING ONLY ]; const allowedLicenses = [ @@ -433,8 +434,7 @@ const reservedAdapterNames = [ function initConfig(context) { - console.log(`initConfig}`); - + common.debug(`initConfig`); context.cfg = {}; context.cfg.allowedLanguages = allowedLanguages; context.cfg.allowedLicenses = allowedLicenses; @@ -446,5 +446,5 @@ function initConfig(context) { return context; } -exports.initConfig=initConfig; +exports.initConfig = initConfig;