dependencyHelper.js (1973B)
1 const getPluginInstance = (pluginKey) => { 2 return redux_templates.supported_plugins[pluginKey]; 3 } 4 5 const needsPluginInstall = (pluginKey) => { 6 const pluginInstance = getPluginInstance(pluginKey); 7 return !pluginInstance || pluginInstance.hasOwnProperty('version') === false; 8 } 9 10 const needsPluginPro = (pluginKey) => { 11 const pluginInstance = getPluginInstance(pluginKey); 12 return (pluginInstance && pluginInstance.hasOwnProperty('has_pro') && pluginInstance.has_pro && 13 (pluginInstance.hasOwnProperty('is_pro') === false || pluginInstance.is_pro === false)); 14 } 15 16 17 const checkTemplateDependencies = (data) => { 18 let missingPluginArray = [], missingProArray = []; 19 20 if (data !== undefined && 'source' in data && data.source !== 'wp_block_patterns') { // We only want to check non wp-block-patterns. 21 // Template itself check 22 if ('pro' in data && data.pro) { 23 if (redux_templates.mokama !== '1' && data.source === redux_templates.i18n) 24 missingProArray.push(redux_templates.i18n); 25 } 26 27 // dependency blocks check 28 if ('blocks' in data) { 29 Object.keys(data.blocks).forEach(pluginKey => { 30 if (pluginKey === 'core') { 31 pluginKey = 'gutenberg'; 32 } 33 if (needsPluginInstall(pluginKey)) missingPluginArray.push(pluginKey); 34 if (needsPluginPro(pluginKey) && data.blocks[pluginKey].pro) missingProArray.push(pluginKey); 35 }); 36 } 37 } 38 39 return {missingPluginArray, missingProArray}; 40 } 41 42 const pluginInfo = (pluginKey) => { 43 const pluginInstance = getPluginInstance(pluginKey); 44 if (!pluginInstance) return {name: null, slug: null, url: null}; 45 const name = pluginInstance.name; 46 const slug = pluginInstance.slug ? pluginInstance.slug : pluginKey; 47 const url = pluginInstance.url; 48 return {name, slug, url}; 49 } 50 51 export default {checkTemplateDependencies, pluginInfo};