diff --git a/server/config/types.js b/server/config/types.js index b84ec08..5b8cb28 100644 --- a/server/config/types.js +++ b/server/config/types.js @@ -2,31 +2,48 @@ const ConfigType = require("./type"); -module.exports = { - 'i18n-locale': new ConfigType('plugin::i18n.locale', 'i18n-locale', 'code'), - 'core-store': new ConfigType('strapi::core-store', 'core-store', 'key', ['value']), - 'user-role': new ConfigType( - 'plugin::users-permissions.role', - 'user-role', - 'type', - [], - [{ - queryString: 'plugin::users-permissions.permission', - relationName: 'permissions', - parentName: 'role', - relationSortField: 'action', - }] - ), - 'admin-role': new ConfigType( - 'admin::role', - 'admin-role', - 'code', - [], - [{ - queryString: 'admin::permission', - relationName: 'permissions', - parentName: 'role', - relationSortField: 'action', - }] - ), +const types = (strapi) => { + const typesObject = { + 'i18n-locale': new ConfigType('plugin::i18n.locale', 'i18n-locale', 'code'), + 'core-store': new ConfigType('strapi::core-store', 'core-store', 'key', ['value']), + 'user-role': new ConfigType( + 'plugin::users-permissions.role', + 'user-role', + 'type', + [], + [{ + queryString: 'plugin::users-permissions.permission', + relationName: 'permissions', + parentName: 'role', + relationSortField: 'action', + }], + ), + 'admin-role': new ConfigType( + 'admin::role', + 'admin-role', + 'code', + [], + [{ + queryString: 'admin::permission', + relationName: 'permissions', + parentName: 'role', + relationSortField: 'action', + }], + ), + }; + + // Remove types for which the corresponding plugin is not installed. + Object.keys(typesObject).map((type) => { + if (type === 'i18n-locale' && !strapi.plugin('i18n')) { + delete typesObject[type]; + } + + if (type === 'user-role' && !strapi.plugin('users-permissions')) { + delete typesObject[type]; + } + }); + + return typesObject; }; + +module.exports = types; diff --git a/server/services/main.js b/server/services/main.js index e2338a1..d7cbab9 100644 --- a/server/services/main.js +++ b/server/services/main.js @@ -112,6 +112,7 @@ module.exports = () => ({ if ( configType && configType !== type || !strapi.config.get('plugin.config-sync.include').includes(type) + || !types(strapi)[type] || strapi.config.get('plugin.config-sync.exclude').includes(`${type}.${name}`) ) { return; @@ -138,11 +139,11 @@ module.exports = () => ({ let databaseConfigs = {}; await Promise.all(strapi.config.get('plugin.config-sync.include').map(async (type) => { - if (configType && configType !== type) { + if (configType && configType !== type || !types(strapi)[type]) { return; } - const config = await types[type].getAllFromDatabase(); + const config = await types(strapi)[type].getAllFromDatabase(); databaseConfigs = Object.assign(config, databaseConfigs); })); @@ -218,7 +219,7 @@ module.exports = () => ({ const fileContents = await strapi.plugin('config-sync').service('main').readConfigFile(type, name); try { - await types[type].importSingle(name, fileContents); + await types(strapi)[type].importSingle(name, fileContents); if (onSuccess) { onSuccess(`${type}.${name}`); } @@ -242,7 +243,7 @@ module.exports = () => ({ const [type, name] = configName.split('.'); // Split the configName. try { - await types[type].exportSingle(configName); + await types(strapi)[type].exportSingle(configName); if (onSuccess) { onSuccess(`${type}.${name}`); }