From ab82a0dbf6e9d1a55fd1f09edf1c4a408fa93c6f Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Wed, 8 May 2024 20:48:33 +0200 Subject: [PATCH] fix: deprecation warning regarding plugin config --- server/bootstrap.js | 12 ++++++------ server/cli.js | 2 +- server/config/type.js | 8 ++++---- server/controllers/config.js | 8 ++++---- server/services/main.js | 26 +++++++++++++------------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/bootstrap.js b/server/bootstrap.js index 2f88ee4..3b2a612 100644 --- a/server/bootstrap.js +++ b/server/bootstrap.js @@ -23,21 +23,21 @@ module.exports = async () => { // The default types provided by the plugin. defaultTypes(strapi).map((type) => { - if (!strapi.config.get('plugin.config-sync.excludedTypes').includes(type.configName)) { + if (!strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName)) { 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)) { + if (!strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName)) { 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)) { + strapi.config.get('plugin::config-sync.customTypes').map((type) => { + if (!strapi.config.get('plugin::config-sync.excludedTypes').includes(type.configName)) { types[type.configName] = new ConfigType(type); } }); @@ -47,10 +47,10 @@ module.exports = async () => { strapi.plugin('config-sync').types = registerTypes(); // Import on bootstrap. - if (strapi.config.get('plugin.config-sync.importOnBootstrap')) { + if (strapi.config.get('plugin::config-sync.importOnBootstrap')) { if (strapi.server.app.env === 'development') { strapi.log.warn(logMessage(`You can't use the 'importOnBootstrap' setting in the development env.`)); - } else if (fs.existsSync(strapi.config.get('plugin.config-sync.syncDir'))) { + } else if (fs.existsSync(strapi.config.get('plugin::config-sync.syncDir'))) { await strapi.plugin('config-sync').service('main').importAllConfig(); } } diff --git a/server/cli.js b/server/cli.js index 22b90c7..7e7d751 100644 --- a/server/cli.js +++ b/server/cli.js @@ -98,7 +98,7 @@ const getConfigState = (diff, configName, syncType) => { const handleAction = async (syncType, skipConfirm, configType, partials, force) => { const app = await getStrapiApp(); - const hasSyncDir = fs.existsSync(app.config.get('plugin.config-sync.syncDir')); + const hasSyncDir = fs.existsSync(app.config.get('plugin::config-sync.syncDir')); // No import with empty sync dir. if (!hasSyncDir && syncType === 'import') { diff --git a/server/config/type.js b/server/config/type.js index 3bb3b46..c768e49 100644 --- a/server/config/type.js +++ b/server/config/type.js @@ -39,10 +39,10 @@ const ConfigType = class ConfigType { */ importSingle = async (configName, configContent, force) => { // Check if the config should be excluded. - const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${configName}`.startsWith(option))); + const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${configName}`.startsWith(option))); if (shouldExclude) return; - const softImport = strapi.config.get('plugin.config-sync.soft'); + const softImport = strapi.config.get('plugin::config-sync.soft'); const queryAPI = strapi.query(this.queryString); const uidParams = getUidParamsFromName(this.uidKeys, configName); const combinedUidWhereFilter = getCombinedUidWhereFilter(this.uidKeys, uidParams); @@ -174,7 +174,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 = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option))); + const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => configName.startsWith(option))); if (shouldExclude) return; const currentConfig = formattedDiff.databaseConfig[configName]; @@ -211,7 +211,7 @@ const ConfigType = class ConfigType { } // Check if the config should be excluded. - const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${combinedUid}`.startsWith(option))); + const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => `${this.configPrefix}.${combinedUid}`.startsWith(option))); if (shouldExclude) return; const formattedConfig = { ...sanitizeConfig(config) }; diff --git a/server/controllers/config.js b/server/controllers/config.js index 4de75ee..3c8000f 100644 --- a/server/controllers/config.js +++ b/server/controllers/config.js @@ -25,7 +25,7 @@ module.exports = { ctx.send({ - message: `Config was successfully exported to ${strapi.config.get('plugin.config-sync.syncDir')}.`, + message: `Config was successfully exported to ${strapi.config.get('plugin::config-sync.syncDir')}.`, }); }, @@ -37,7 +37,7 @@ module.exports = { */ importAll: async (ctx) => { // Check for existance of the config file sync dir. - if (!fs.existsSync(strapi.config.get('plugin.config-sync.syncDir'))) { + if (!fs.existsSync(strapi.config.get('plugin::config-sync.syncDir'))) { ctx.send({ message: 'No config files were found.', }); @@ -73,7 +73,7 @@ module.exports = { */ getDiff: async (ctx) => { // Check for existance of the config file sync dir. - if (!fs.existsSync(strapi.config.get('plugin.config-sync.syncDir'))) { + if (!fs.existsSync(strapi.config.get('plugin::config-sync.syncDir'))) { ctx.send({ message: 'No config files were found.', }); @@ -91,7 +91,7 @@ module.exports = { getAppEnv: async () => { return { env: strapi.server.app.env, - config: strapi.config.get('plugin.config-sync'), + config: strapi.config.get('plugin::config-sync'), }; }, }; diff --git a/server/services/main.js b/server/services/main.js index c603f62..1486795 100644 --- a/server/services/main.js +++ b/server/services/main.js @@ -21,23 +21,23 @@ module.exports = () => ({ */ writeConfigFile: async (configType, configName, fileContents) => { // Check if the config should be excluded. - const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').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; // Replace reserved characters in filenames. configName = configName.replace(/:/g, "#").replace(/\//g, "$"); // Check if the JSON content should be minified. - const json = !strapi.config.get('plugin.config-sync').minify + const json = !strapi.config.get('plugin::config-sync').minify ? JSON.stringify(fileContents, null, 2) : JSON.stringify(fileContents); - if (!fs.existsSync(strapi.config.get('plugin.config-sync.syncDir'))) { - fs.mkdirSync(strapi.config.get('plugin.config-sync.syncDir'), { recursive: true }); + if (!fs.existsSync(strapi.config.get('plugin::config-sync.syncDir'))) { + fs.mkdirSync(strapi.config.get('plugin::config-sync.syncDir'), { recursive: true }); } const writeFile = util.promisify(fs.writeFile); - await writeFile(`${strapi.config.get('plugin.config-sync.syncDir')}${configType}.${configName}.json`, json) + await writeFile(`${strapi.config.get('plugin::config-sync.syncDir')}${configType}.${configName}.json`, json) .then(() => { // @TODO: // Add logging for successfull config export. @@ -56,13 +56,13 @@ module.exports = () => ({ */ deleteConfigFile: async (configName) => { // Check if the config should be excluded. - const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option))); + const shouldExclude = !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => configName.startsWith(option))); if (shouldExclude) return; // Replace reserved characters in filenames. configName = configName.replace(/:/g, "#").replace(/\//g, "$"); - fs.unlinkSync(`${strapi.config.get('plugin.config-sync.syncDir')}${configName}.json`); + fs.unlinkSync(`${strapi.config.get('plugin::config-sync.syncDir')}${configName}.json`); }, /** @@ -77,7 +77,7 @@ module.exports = () => ({ configName = configName.replace(/:/g, "#").replace(/\//g, "$"); const readFile = util.promisify(fs.readFile); - return readFile(`${strapi.config.get('plugin.config-sync.syncDir')}${configType}.${configName}.json`) + return readFile(`${strapi.config.get('plugin::config-sync.syncDir')}${configType}.${configName}.json`) .then((data) => { return JSON.parse(data); }) @@ -94,11 +94,11 @@ module.exports = () => ({ * @returns {object} Object with key value pairs of configs. */ getAllConfigFromFiles: async (configType = null) => { - if (!fs.existsSync(strapi.config.get('plugin.config-sync.syncDir'))) { + if (!fs.existsSync(strapi.config.get('plugin::config-sync.syncDir'))) { return {}; } - const configFiles = fs.readdirSync(strapi.config.get('plugin.config-sync.syncDir')); + const configFiles = fs.readdirSync(strapi.config.get('plugin::config-sync.syncDir')); const getConfigs = async () => { const fileConfigs = {}; @@ -113,7 +113,7 @@ module.exports = () => ({ if ( configType && configType !== type || !strapi.plugin('config-sync').types[type] - || !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => `${type}.${name}`.startsWith(option))) + || !isEmpty(strapi.config.get('plugin::config-sync.excludedConfig').filter((option) => `${type}.${name}`.startsWith(option))) ) { return; } @@ -219,7 +219,7 @@ module.exports = () => ({ */ importSingleConfig: async (configName, onSuccess, force) => { // Check if the config should be excluded. - const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option))); + 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. @@ -244,7 +244,7 @@ module.exports = () => ({ */ exportSingleConfig: async (configName, onSuccess) => { // Check if the config should be excluded. - const shouldExclude = !isEmpty(strapi.config.get('plugin.config-sync.excludedConfig').filter((option) => configName.startsWith(option))); + 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.