fix: deprecation warning regarding plugin config

pull/126/head
Boaz Poolman 2024-05-08 20:48:33 +02:00
parent 9178f1e902
commit ab82a0dbf6
5 changed files with 28 additions and 28 deletions

View File

@ -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();
}
}

View File

@ -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') {

View File

@ -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) };

View File

@ -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'),
};
},
};

View File

@ -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.