MCPcopy Create free account
hub / github.com/bigcommerce/stencil-cli / validateObjects

Method validateObjects

lib/bundle-validator.js:81–112  ·  view source on GitHub ↗

* Validates that required objects/properties exist in theme * @param {array} assembledTemplates * @param {function} callback

(assembledTemplates, callback)

Source from the content-addressed store, hash-verified

79 * @param {function} callback
80 */
81 validateObjects(assembledTemplates, callback) {
82 async.map(
83 assembledTemplates,
84 (template, cb) => {
85 const validated = [];
86 for (const templateString of Object.keys(template)) {
87 const matches = this.objectsToValidate.filter(
88 (element) =>
89 template[templateString].search(
90 new RegExp(`{+\\s*${element}\\s*}+`),
91 ) !== -1,
92 );
93 validated.push(...matches);
94 }
95 cb(null, validated);
96 },
97 (err, validationRes) => {
98 if (err) {
99 callback(err);
100 return;
101 }
102 const results = difference(this.objectsToValidate, uniq(flatten(validationRes)));
103 if (results.length !== 0) {
104 callback(
105 new Error(`Missing required objects/properties: ${results.join('\n')}`),
106 );
107 return;
108 }
109 callback(null, !!results);
110 },
111 );
112 }
113
114 /**
115 * Wrapper to enable testability.

Callers 1

_checkObjectsMethod · 0.80

Calls 1

cbFunction · 0.85

Tested by

no test coverage detected