2021-03-20 01:30:37 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
2021-12-28 22:10:04 +01:00
|
|
|
const ConfigType = require('./config/type');
|
|
|
|
const defaultTypes = require('./config/types');
|
|
|
|
|
2021-03-20 01:30:37 +01:00
|
|
|
/**
|
|
|
|
* An asynchronous bootstrap function that runs before
|
|
|
|
* your application gets started.
|
|
|
|
*
|
|
|
|
* This gives you an opportunity to set up your data model,
|
|
|
|
* run jobs, or perform some special logic.
|
|
|
|
*
|
|
|
|
* See more details here: https://strapi.io/documentation/v3.x/concepts/configurations.html#bootstrap
|
|
|
|
*/
|
|
|
|
|
2021-03-24 16:22:03 +01:00
|
|
|
module.exports = async () => {
|
2021-11-10 19:51:00 +01:00
|
|
|
// Import on bootstrap.
|
2021-12-01 14:01:56 +01:00
|
|
|
if (strapi.config.get('plugin.config-sync.importOnBootstrap')) {
|
2021-12-28 22:10:04 +01:00
|
|
|
if (fs.existsSync(strapi.config.get('plugin.config-sync.syncDir'))) {
|
2021-12-01 14:01:56 +01:00
|
|
|
await strapi.plugin('config-sync').service('main').importAllConfig();
|
2021-03-20 01:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-10 19:51:00 +01:00
|
|
|
|
2021-12-28 22:10:04 +01:00
|
|
|
// Register config types.
|
|
|
|
const registerTypes = () => {
|
|
|
|
const types = {};
|
|
|
|
|
|
|
|
defaultTypes(strapi).map((type) => {
|
|
|
|
if (!strapi.config.get('plugin.config-sync.excludedTypes').includes(type.configName)) {
|
|
|
|
types[type.configName] = new ConfigType(type);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return types;
|
|
|
|
};
|
|
|
|
strapi.plugin('config-sync').types = registerTypes();
|
|
|
|
|
2021-11-10 19:51:00 +01:00
|
|
|
// Register permission actions.
|
|
|
|
const actions = [
|
|
|
|
{
|
|
|
|
section: 'plugins',
|
|
|
|
displayName: 'Access the plugin settings',
|
|
|
|
uid: 'settings.read',
|
|
|
|
pluginName: 'config-sync',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
section: 'plugins',
|
2021-11-11 22:43:52 +01:00
|
|
|
displayName: 'Menu link to plugin settings',
|
|
|
|
uid: 'menu-link',
|
2021-11-10 19:51:00 +01:00
|
|
|
pluginName: 'config-sync',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
await strapi.admin.services.permission.actionProvider.registerMany(actions);
|
2021-03-20 01:30:37 +01:00
|
|
|
};
|