mirror of
https://github.com/benjaminion/upgrading-ethereum-book.git
synced 2026-01-09 22:47:55 -05:00
Simplify reporting handling
This commit is contained in:
@@ -99,26 +99,27 @@ function printLines(s, reporter) {
|
|||||||
s.split(/\r?\n/).forEach((line) => line && reporter.warn(line));
|
s.split(/\r?\n/).forEach((line) => line && reporter.warn(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runCheck({ name, enabled, checker }) {
|
async function runCheck({ name, enabled, checker }, reporter) {
|
||||||
let info = '';
|
|
||||||
let warn = '';
|
|
||||||
let success = true;
|
let success = true;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
info += `Doing ${name} check`;
|
|
||||||
try {
|
try {
|
||||||
const out = await checker();
|
const out = await checker();
|
||||||
if (out !== '' && out !== null) {
|
if (out === '' || out === null) {
|
||||||
warn += `Issues were found by ${name} check:\n` + out;
|
reporter.info(`The ${name} check passed`);
|
||||||
|
} else {
|
||||||
|
reporter.warn(`Issues were found by ${name} check:`);
|
||||||
|
printLines(out, reporter);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
warn += `An error occurred during ${name} check:\n` + err.toString();
|
reporter.warn(`An error occurred during ${name} check:`);
|
||||||
|
printLines(err.toString(), reporter);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn += `Skipping ${name} check`;
|
reporter.warn(`Skipping ${name} check`);
|
||||||
}
|
}
|
||||||
return { success: success, info: info, warn: warn };
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set `exitToShell` to false to continue processing after running checks (e.g. while building)
|
// Set `exitToShell` to false to continue processing after running checks (e.g. while building)
|
||||||
@@ -126,14 +127,11 @@ export default async function runChecks(
|
|||||||
reporter = customReporter,
|
reporter = customReporter,
|
||||||
exitToShell = true,
|
exitToShell = true,
|
||||||
) {
|
) {
|
||||||
const results = await Promise.all(checks.map((check) => runCheck(check)));
|
const results = await Promise.all(
|
||||||
|
checks.map((check) => runCheck(check, reporter)),
|
||||||
results.forEach(({ info, warn }) => {
|
);
|
||||||
info && reporter.info(info);
|
|
||||||
warn && printLines(warn, reporter);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (exitToShell) {
|
if (exitToShell) {
|
||||||
process.exit(results.every(({ success }) => success) ? 0 : 2);
|
process.exit(results.every((x) => x) ? 0 : 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user