Skip to content

Commit

Permalink
feat: improve error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Oct 13, 2019
1 parent e5fe68d commit 0bc687e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/Adio.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class Adio {
try {
packageJson = fs.readFileSync(path.join(dir, "package.json"), "utf8");
} catch (e) {
throw Error("Could not open package.json located at " + dir);
throw Error(`Could not open package.json located at ${dir}.`);
}

try {
packageJson = JSON.parse(packageJson);
} catch (e) {
throw Error("Could not parse package.json located at " + dir);
throw Error(`Could not parse package.json located at ${dir}.`);
}

let adioRc = explorer.searchSync(dir);
Expand Down
84 changes: 44 additions & 40 deletions src/bin/adio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,50 @@ const rootConfig = explorer.searchSync(process.cwd()) || {};

const adio = new Adio({ ...rootConfig.config, ...argv });

const results = adio.test();
try {
const results = adio.test();

const packagesWithErrors = results.filter(r => r.errors.count);
if (packagesWithErrors.length === 0) {
console.log(chalk.green("✅ All dependencies in order!"));
return process.exit(0);
}

packagesWithErrors.forEach((pckg, index) => {
console.log(chalk.red(`${index + 1}. ${pckg.packageJson.name} (${pckg.dir})`));

if (pckg.errors.deps.src.length) {
console.log(chalk.gray("[src] Source code"));
pckg.errors.deps.src.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
const packagesWithErrors = results.filter(r => r.errors.count);
if (packagesWithErrors.length === 0) {
console.log(chalk.green("✅ All dependencies in order!"));
return process.exit(0);
}

if (pckg.errors.deps.dependencies.length) {
console.log(chalk.gray("[package.json] dependencies:"));
pckg.errors.deps.dependencies.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

if (pckg.errors.deps.devDependencies.length) {
console.log(chalk.gray("[package.json] devDependencies:"));
pckg.errors.deps.devDependencies.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

if (pckg.errors.deps.peerDependencies.length) {
console.log(chalk.gray("[package.json] peerDependencies:"));
pckg.errors.deps.peerDependencies.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

console.log();
});

process.exit(1);
packagesWithErrors.forEach((pckg, index) => {
console.log(chalk.red(`${index + 1}. ${pckg.packageJson.name} (${pckg.dir})`));

if (pckg.errors.deps.src.length) {
console.log(chalk.gray("[src] Source code"));
pckg.errors.deps.src.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

if (pckg.errors.deps.dependencies.length) {
console.log(chalk.gray("[package.json] dependencies:"));
pckg.errors.deps.dependencies.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

if (pckg.errors.deps.devDependencies.length) {
console.log(chalk.gray("[package.json] devDependencies:"));
pckg.errors.deps.devDependencies.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

if (pckg.errors.deps.peerDependencies.length) {
console.log(chalk.gray("[package.json] peerDependencies:"));
pckg.errors.deps.peerDependencies.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

console.log();
});

process.exit(1);
} catch (e) {
console.log(chalk.red(e.message));
}

0 comments on commit 0bc687e

Please sign in to comment.