From c269b4847e8d0804940156d6bb2275d584d2720b Mon Sep 17 00:00:00 2001 From: ppaoli Date: Mon, 4 Sep 2023 13:04:08 +0200 Subject: [PATCH] Fixed ESLint warnings, change property naming Fixed ESLint Warnings Add Documentation for Components under "Custom types" Change property populate to components --- README.md | 15 +++++++++++++++ server/config/type.js | 18 +++++++++--------- server/utils/index.js | 18 +++++++++--------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index be43f24..fc5346f 100644 --- a/README.md +++ b/README.md @@ -354,6 +354,21 @@ This property can accept an array of field names from the type. It is meant to s > `required:` NO | `type:` array +#### Components + +This property can accept an array of component names from the type. Strapi Components can be included in the export/import process. With "." nested components can also be included in the process. +``` +customTypes: [{ + configName: 'webhook', + queryString: 'webhook', + uid: 'name', + components: ['ParentComponentA', 'ParentComponentA.ChildComponent', 'ParentComponentB'] +}], + +###### Key: `components` + +> `required:` NO | `type:` array + ## 🔍 Naming convention All the config files written in the sync directory have the same naming convention. It goes as follows: diff --git a/server/config/type.js b/server/config/type.js index 7371a19..7c53d53 100644 --- a/server/config/type.js +++ b/server/config/type.js @@ -3,7 +3,7 @@ const { logMessage, sanitizeConfig, dynamicSort, noLimit, getCombinedUid, getCom const { difference, same } = require('../utils/getArrayDiff'); const ConfigType = class ConfigType { - constructor({ queryString, configName, uid, jsonFields, relations, populate }) { + constructor({ queryString, configName, uid, jsonFields, relations, components }) { if (!configName) { strapi.log.error(logMessage('A config type was registered without a config name.')); process.exit(0); @@ -25,7 +25,7 @@ const ConfigType = class ConfigType { this.configPrefix = configName; this.jsonFields = jsonFields || []; this.relations = relations || []; - this.populate = populate || null; + this.components = components || null; } /** @@ -202,7 +202,7 @@ const ConfigType = class ConfigType { */ getAllFromDatabase = async () => { const AllConfig = await noLimit(strapi.query(this.queryString), { - populate: this.populate, + populate: this.components, }); const configs = {}; @@ -232,12 +232,12 @@ const ConfigType = class ConfigType { formattedConfig[relationName] = relations; })); - if (Array.isArray(this.populate)) { - this.populate - .filter((populatedFields) => !populatedFields.includes(".")) - .map((populatedFields) => { - formattedConfig[populatedFields] = formattedConfig[ - populatedFields + if (Array.isArray(this.components)) { + this.components + .filter((componentFields) => !componentFields.includes(".")) + .map((componentFields) => { + formattedConfig[componentFields] = formattedConfig[ + componentFields ].map((fields) => { sanitizeConfig(fields); return fields; diff --git a/server/utils/index.js b/server/utils/index.js index ca61959..19291d1 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -69,19 +69,19 @@ const sanitizeConfig = (config, relation, relationSortFields) => { config[relation] = formattedRelations; } - const sanitizeRecursive = (config) => { - delete config._id; - delete config.id; - delete config.updatedAt; - delete config.createdAt; + const recursiveSanitizeConfig = (recursivedSanitizedConfig) => { + delete recursivedSanitizedConfig._id; + delete recursivedSanitizedConfig.id; + delete recursivedSanitizedConfig.updatedAt; + delete recursivedSanitizedConfig.createdAt; - Object.keys(config).map((key, index) => { - if (config[key] && typeof config[key] === "object") { - sanitizeRecursive(config[key]); + Object.keys(recursivedSanitizedConfig).map((key, index) => { + if (recursivedSanitizedConfig[key] && typeof recursivedSanitizedConfig[key] === "object") { + recursiveSanitizeConfig(recursivedSanitizedConfig[key]); } }); }; - sanitizeRecursive(config); + recursiveSanitizeConfig(config); return config; };