Skip to content

Commit

Permalink
chore: improve icon builder validation closes #6555 (#6556)
Browse files Browse the repository at this point in the history
* chore: improve icon builder validation closes #6555

* chore: update schemas and fix error

* fix: duplicate softlayer--enablement

Co-authored-by: Vince Picone <[email protected]>
  • Loading branch information
vpicone and vpicone authored Jul 27, 2020
1 parent 6b68b55 commit fa022be
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const icons = () => {
Joi.string().valid('glyph'),
Joi.number().valid([16, 20, 24, 32])
),
aliases: Joi.array(),
aliases: Joi.array().items(Joi.string()),
})
),

Expand Down
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()),
})
),

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
15 changes: 6 additions & 9 deletions packages/pictograms/pictograms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3269,16 +3269,13 @@
- soft ice cream
- ice cream
- food
- name: softlayer--enablement
friendly_name: Softlayer enablement
aliases:
- softlayer enablement
- enablement
- softlayer
- cloud
- name: softlayer--enablement
friendly_name: softlayer--enablement
aliases: []
friendly_name: Softlayer enablement
aliases:
- softlayer enablement
- enablement
- softlayer
- cloud
- name: solar--field
friendly_name: Solar field
aliases:
Expand Down

0 comments on commit fa022be

Please sign in to comment.