feat: add option to only include listed types and config
parent
10ef97a4d4
commit
7f72442c54
|
@ -2,6 +2,7 @@
|
|||
|
||||
import fs from 'fs';
|
||||
|
||||
import { isEmpty } from 'lodash';
|
||||
import ConfigType from './config/type';
|
||||
import defaultTypes from './config/types';
|
||||
import { logMessage } from './utils';
|
||||
|
@ -23,21 +24,27 @@ export default async () => {
|
|||
|
||||
// The default types provided by the plugin.
|
||||
defaultTypes(strapi).map((type) => {
|
||||
if (!strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName)) {
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedTypes')) || strapi.config.get('plugin::config-sync.includedTypes').includes(type.configName);
|
||||
const shouldExclude = strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName);
|
||||
if (shouldInclude && !shouldExclude) {
|
||||
types[type.configName] = new ConfigType(type);
|
||||
}
|
||||
});
|
||||
|
||||
// The types provided by other plugins.
|
||||
strapi.plugin('config-sync').pluginTypes.map((type) => {
|
||||
if (!strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName)) {
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedTypes')) || strapi.config.get('plugin::config-sync.includedTypes').includes(type.configName);
|
||||
const shouldExclude = strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName);
|
||||
if (shouldInclude && !shouldExclude) {
|
||||
types[type.configName] = new ConfigType(type);
|
||||
}
|
||||
});
|
||||
|
||||
// The custom types provided by the user.
|
||||
strapi.config.get('plugin::config-sync.customTypes').map((type) => {
|
||||
if (!strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName)) {
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedTypes')) || strapi.config.get('plugin::config-sync.includedTypes').includes(type.configName);
|
||||
const shouldExclude = strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName);
|
||||
if (shouldInclude && !shouldExclude) {
|
||||
types[type.configName] = new ConfigType(type);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
"use strict";
|
||||
|
||||
export default {
|
||||
default: {
|
||||
|
@ -7,7 +7,9 @@ export default {
|
|||
soft: false,
|
||||
importOnBootstrap: false,
|
||||
customTypes: [],
|
||||
includedTypes: [],
|
||||
excludedTypes: [],
|
||||
includedConfig: [],
|
||||
excludedConfig: [
|
||||
"core-store.plugin_users-permissions_grant",
|
||||
"core-store.plugin_upload_metrics",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import fs from 'fs';
|
||||
import util from 'util';
|
||||
import AdmZip from 'adm-zip';
|
||||
import fs from 'fs';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import util from 'util';
|
||||
|
||||
import difference from '../utils/getObjectDiff';
|
||||
import { logMessage } from '../utils';
|
||||
import difference from '../utils/getObjectDiff';
|
||||
|
||||
/**
|
||||
* Main services for config import/export.
|
||||
|
@ -23,8 +23,9 @@ export default () => ({
|
|||
*/
|
||||
writeConfigFile: async (configType, configName, fileContents) => {
|
||||
// Check if the config should be excluded.
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedConfig')) || !isEmpty(strapi.config.get('plugin::config-sync.includedConfig').filter((option) => `${configType}.${configName}`.startsWith(option)));
|
||||
const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => `${configType}.${configName}`.startsWith(option)));
|
||||
if (shouldExclude) return;
|
||||
if (!shouldInclude || shouldExclude) return;
|
||||
|
||||
// Replace reserved characters in filenames.
|
||||
configName = configName.replace(/:/g, "#").replace(/\//g, "$");
|
||||
|
@ -58,8 +59,9 @@ export default () => ({
|
|||
*/
|
||||
deleteConfigFile: async (configName) => {
|
||||
// Check if the config should be excluded.
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedConfig')) || !isEmpty(strapi.config.get('plugin::config-sync.includedConfig').filter((option) => configName.startsWith(option)));
|
||||
const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
|
||||
if (shouldExclude) return;
|
||||
if (!shouldInclude || shouldExclude) return;
|
||||
|
||||
// Replace reserved characters in filenames.
|
||||
configName = configName.replace(/:/g, "#").replace(/\//g, "$");
|
||||
|
@ -128,10 +130,14 @@ export default () => ({
|
|||
// Put back reserved characters from filenames.
|
||||
const formattedName = name.replace(/#/g, ":").replace(/\$/g, "/");
|
||||
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedConfig')) || !isEmpty(strapi.config.get('plugin::config-sync.includedConfig').filter((option) => `${type}.${name}`.startsWith(option)));
|
||||
const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => `${type}.${name}`.startsWith(option)));
|
||||
|
||||
if (
|
||||
configType && configType !== type
|
||||
|| !strapi.plugin('config-sync').types[type]
|
||||
|| !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => `${type}.${name}`.startsWith(option)))
|
||||
|| !shouldInclude
|
||||
|| shouldExclude
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -237,8 +243,9 @@ export default () => ({
|
|||
*/
|
||||
importSingleConfig: async (configName, onSuccess, force) => {
|
||||
// Check if the config should be excluded.
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedConfig')) || !isEmpty(strapi.config.get('plugin::config-sync.includedConfig').filter((option) => configName.startsWith(option)));
|
||||
const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
|
||||
if (shouldExclude) return;
|
||||
if (!shouldInclude || shouldExclude) return;
|
||||
|
||||
const type = configName.split('.')[0]; // Grab the first part of the filename.
|
||||
const name = configName.split(/\.(.+)/)[1]; // Grab the rest of the filename.
|
||||
|
@ -261,9 +268,11 @@ export default () => ({
|
|||
* @returns {void}
|
||||
*/
|
||||
exportSingleConfig: async (configName, onSuccess) => {
|
||||
// Check if the config should be excluded.
|
||||
console.log(configName);
|
||||
// Check if the config should be excluded.
|
||||
const shouldInclude = isEmpty(strapi.config.get('plugin::config-sync.includedConfig')) || !isEmpty(strapi.config.get('plugin::config-sync.includedConfig').filter((option) => configName.startsWith(option)));
|
||||
const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => configName.startsWith(option)));
|
||||
if (shouldExclude) return;
|
||||
if (!shouldInclude || shouldExclude) return;
|
||||
|
||||
const type = configName.split('.')[0]; // Grab the first part of the filename.
|
||||
const name = configName.split(/\.(.+)/)[1]; // Grab the rest of the filename.
|
||||
|
|
Loading…
Reference in New Issue