feat: Dynamically use types based on plugin dependency
parent
b8b187acf7
commit
5cdf4de4fb
|
@ -2,7 +2,8 @@
|
|||
|
||||
const ConfigType = require("./type");
|
||||
|
||||
module.exports = {
|
||||
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(
|
||||
|
@ -15,7 +16,7 @@ module.exports = {
|
|||
relationName: 'permissions',
|
||||
parentName: 'role',
|
||||
relationSortField: 'action',
|
||||
}]
|
||||
}],
|
||||
),
|
||||
'admin-role': new ConfigType(
|
||||
'admin::role',
|
||||
|
@ -27,6 +28,22 @@ module.exports = {
|
|||
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;
|
||||
|
|
|
@ -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}`);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue