feat: Allow excluding configs by giving part of the config name

pull/33/head
Boaz Poolman 2021-12-29 00:38:25 +01:00
parent 724f56f20b
commit c93546b594
2 changed files with 10 additions and 8 deletions

View File

@ -1,3 +1,4 @@
const { isEmpty } = require('lodash');
const { logMessage, sanitizeConfig, dynamicSort, noLimit } = require('../utils');
const difference = require('../utils/getArrayDiff');
@ -31,7 +32,7 @@ const ConfigType = class ConfigType {
*/
importSingle = async (configName, configContent) => {
// Check if the config should be excluded.
const shouldExclude = strapi.config.get('plugin.config-sync.excludedConfig').includes(`${this.configPrefix}.${configName}`);
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${configName}`.startsWith(option)));
if (shouldExclude) return;
const queryAPI = strapi.query(this.queryString);
@ -134,7 +135,7 @@ const ConfigType = class ConfigType {
const formattedDiff = await strapi.plugin('config-sync').service('main').getFormattedDiff(this.configPrefix);
// Check if the config should be excluded.
const shouldExclude = strapi.config.get('plugin.config-sync.excludedConfig').includes(`${configName}`);
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
if (shouldExclude) return;
const currentConfig = formattedDiff.databaseConfig[configName];
@ -160,7 +161,7 @@ const ConfigType = class ConfigType {
await Promise.all(Object.values(AllConfig).map(async (config) => {
// Check if the config should be excluded.
const shouldExclude = strapi.config.get('plugin.config-sync.excludedConfig').includes(`${this.configPrefix}.${config[this.uid]}`);
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${config[this.uid]}`.startsWith(option)));
if (shouldExclude) return;
const formattedConfig = { ...sanitizeConfig(config) };

View File

@ -1,5 +1,6 @@
'use strict';
const { isEmpty } = require('lodash');
const fs = require('fs');
const util = require('util');
const difference = require('../utils/getObjectDiff');
@ -19,7 +20,7 @@ module.exports = () => ({
*/
writeConfigFile: async (configType, configName, fileContents) => {
// Check if the config should be excluded.
const shouldExclude = strapi.config.get('plugin.config-sync.excludedConfig').includes(`${configType}.${configName}`);
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${configType}.${configName}`.startsWith(option)));
if (shouldExclude) return;
// Replace ':' with '#' in filenames for Windows support.
@ -54,7 +55,7 @@ module.exports = () => ({
*/
deleteConfigFile: async (configName) => {
// Check if the config should be excluded.
const shouldExclude = strapi.config.get('plugin.config-sync.excludedConfig').includes(`${configName}`);
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
if (shouldExclude) return;
// Replace ':' with '#' in filenames for Windows support.
@ -111,7 +112,7 @@ module.exports = () => ({
if (
configType && configType !== type
|| !strapi.plugin('config-sync').types[type]
|| strapi.config.get('plugin.config-sync.excludedConfig').includes(`${type}.${name}`)
|| !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${type}.${name}`.startsWith(option)))
) {
return;
}
@ -210,7 +211,7 @@ module.exports = () => ({
*/
importSingleConfig: async (configName, onSuccess) => {
// Check if the config should be excluded.
const shouldExclude = strapi.config.get('plugin.config-sync.excludedConfig').includes(configName);
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
if (shouldExclude) return;
const type = configName.split('.')[0]; // Grab the first part of the filename.
@ -236,7 +237,7 @@ module.exports = () => ({
*/
exportSingleConfig: async (configName, onSuccess) => {
// Check if the config should be excluded.
const shouldExclude = strapi.config.get('plugin.config-sync.excludedConfig').includes(configName);
const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
if (shouldExclude) return;
const type = configName.split('.')[0]; // Grab the first part of the filename.