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

Method _getVariation

lib/theme-config.js:289–312  ·  view source on GitHub ↗

* Grabs out a variation based on a name. Or if the name is not passed in, the very first one in the list. * * @private * @param config * @param variationIndex * @returns {object}

(config, variationIndex)

Source from the content-addressed store, hash-verified

287 * @returns {object}
288 */
289 _getVariation(config, variationIndex) {
290 let variation;
291 if (!Array.isArray(config.variations) || config.variations.length === 0) {
292 throw new Error('Your theme must have at least one variation in the config.json file.');
293 }
294 if (!variationIndex) {
295 [variation] = config.variations;
296 } else {
297 variation = config.variations[variationIndex];
298 if (!variation) {
299 throw new Error(`Variation index: ${variationIndex} not found theme's config.json`);
300 }
301 }
302 if (!isObject(variation.settings)) {
303 variation.settings = {};
304 }
305 if (!isObject(variation.images)) {
306 variation.images = {};
307 }
308 if (!isObject(variation.meta)) {
309 variation.meta = {};
310 }
311 return variation;
312 }
313
314 /**
315 * Scan file for theme_settings.*

Callers 3

getConfigMethod · 0.95
updateConfigMethod · 0.95
getVariationMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected