balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

helpers.js (2043B)


      1 import { Plugins } from '../api/Plugins'
      2 
      3 let installedPlugins = []
      4 let activatedPlugins = []
      5 
      6 export async function checkIfUserNeedsToInstallPlugins(template) {
      7     let required = template?.fields?.required_plugins ?? []
      8     // Hardcoded temporarily to not force EP install
      9     required = required.filter((p) => p !== 'editorplus')
     10     if (!required.length) {
     11         return false
     12     }
     13 
     14     if (!installedPlugins.length) {
     15         installedPlugins = Object.keys(await Plugins.getInstalled())
     16     }
     17     // if no dependencies are required, then this will be false automatically
     18     const weNeedInstalls = required.length
     19         ? required.filter((plugin) => {
     20             // TODO: if we have better data to work with this can be more literal
     21             return !installedPlugins.some((k) => {
     22                 return k.includes(plugin)
     23             })
     24         })
     25         : false
     26 
     27     return weNeedInstalls.length
     28 }
     29 
     30 export async function checkIfUserNeedsToActivatePlugins(template) {
     31     let required = template?.fields?.required_plugins ?? []
     32 
     33     // Hardcoded temporarily to not force EP install
     34     required = required.filter((p) => p !== 'editorplus')
     35     if (!required.length) {
     36         return false
     37     }
     38 
     39     if (!activatedPlugins.length) {
     40         activatedPlugins = Object.values(await Plugins.getActivated())
     41     }
     42 
     43     // if no dependencies are required, then this will be false automatically
     44     const weNeedActivations = required.length
     45         ? required.filter((plugin) => {
     46             // TODO: if we have better data to work with this can be more literal
     47             return !activatedPlugins.some((k) => {
     48                 return k.includes(plugin)
     49             })
     50         })
     51         : false
     52 
     53     // if the plugins we need to have activated are not even installed, handle them elsewhere
     54     if (weNeedActivations) {
     55         // This call is a bit more expensive so only run it if needed
     56         if (await checkIfUserNeedsToInstallPlugins(template)) {
     57             return false
     58         }
     59     }
     60     return weNeedActivations.length
     61 }