Skip to content

Commit

Permalink
chore: improve icon builder validation closes carbon-design-system#6555
Browse files Browse the repository at this point in the history
  • Loading branch information
vpicone committed Jul 24, 2020
1 parent a118f5f commit 29357bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const pictograms = () => {
Joi.object().keys({
name: Joi.string().required(),
friendly_name: Joi.string().required(),
aliases: Joi.array(),
aliases: Joi.array().items(Joi.string(), Joi.number()),
})
),

Expand Down
14 changes: 12 additions & 2 deletions packages/icon-build-helpers/src/metadata/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'use strict';

const Joi = require('joi');
const { reporter } = require('@carbon/cli-reporter');

/**
* Validate the given icons and extension metadata against the asset registry
Expand All @@ -21,9 +22,18 @@ const Joi = require('joi');
function validate(registry, extensions = []) {
for (const extension of extensions) {
if (extension.schema) {
const { error } = Joi.validate(extension.data, extension.schema);
const { error, value } = Joi.validate(extension.data, extension.schema);
if (error) {
throw new Error(error.annotate());
const failedAssets = error.details.map(({ path, message }) => ({
index: path[0],
message,
}));
reporter.error(`Unable to validate the ${extension.name} extension:`);
failedAssets.forEach((asset) => {
reporter.error(`Error: ${asset.message}`);
reporter.info(JSON.stringify(value[asset.index], null, 2));
});
process.exit(1);
}
}

Expand Down

0 comments on commit 29357bf

Please sign in to comment.