refactor(v4): Get config diff in admin
parent
41a9bfdf6c
commit
d5b8b0b719
|
@ -24,8 +24,8 @@ const ActionButtons = ({ diff }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionButtonsStyling>
|
<ActionButtonsStyling>
|
||||||
<Button disabled={isEmpty(diff.diff)} label="Import" onClick={() => openModal('import')} />
|
<Button disabled={isEmpty(diff.diff)} onClick={() => openModal('import')}>Import</Button>
|
||||||
<Button disabled={isEmpty(diff.diff)} label="Export" onClick={() => openModal('export')} />
|
<Button disabled={isEmpty(diff.diff)} onClick={() => openModal('export')}>Export</Button>
|
||||||
{!isEmpty(diff.diff) && (
|
{!isEmpty(diff.diff) && (
|
||||||
<h4 style={{ display: 'inline' }}>{Object.keys(diff.diff).length} {Object.keys(diff.diff).length === 1 ? "config change" : "config changes"}</h4>
|
<h4 style={{ display: 'inline' }}>{Object.keys(diff.diff).length} {Object.keys(diff.diff).length === 1 ? "config change" : "config changes"}</h4>
|
||||||
)}
|
)}
|
||||||
|
@ -33,7 +33,7 @@ const ActionButtons = ({ diff }) => {
|
||||||
isOpen={modalIsOpen}
|
isOpen={modalIsOpen}
|
||||||
onClose={closeModal}
|
onClose={closeModal}
|
||||||
type={actionType}
|
type={actionType}
|
||||||
onSubmit={actionType === 'import' ? dispatch(importAllConfig()) : dispatch(exportAllConfig())}
|
onSubmit={() => actionType === 'import' ? dispatch(importAllConfig()) : dispatch(exportAllConfig())}
|
||||||
/>
|
/>
|
||||||
</ActionButtonsStyling>
|
</ActionButtonsStyling>
|
||||||
);
|
);
|
||||||
|
|
|
@ -102,7 +102,7 @@ const ConfigList = ({ diff, isLoading }) => {
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{rows.map((row) => (
|
{rows.map((row) => (
|
||||||
<ConfigListRow key={row.name} {...row} />
|
<ConfigListRow key={row.name} row={row} />
|
||||||
))}
|
))}
|
||||||
</Tbody>
|
</Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
const config = {
|
||||||
|
blacklist: [
|
||||||
|
'REDUX_STORAGE_SAVE',
|
||||||
|
'REDUX_STORAGE_LOAD',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const types = require('./types');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An asynchronous bootstrap function that runs before
|
* An asynchronous bootstrap function that runs before
|
||||||
|
@ -13,6 +14,8 @@ const fs = require('fs');
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
|
// console.log(await types['core-store'].exportAll());
|
||||||
|
|
||||||
if (strapi.plugins['config-sync'].config.importOnBootstrap) {
|
if (strapi.plugins['config-sync'].config.importOnBootstrap) {
|
||||||
if (fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
|
if (fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
|
||||||
await strapi.plugins['config-sync'].services.main.importAllConfig();
|
await strapi.plugins['config-sync'].services.main.importAllConfig();
|
||||||
|
|
|
@ -15,10 +15,10 @@ module.exports = {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
exportAll: async (ctx) => {
|
exportAll: async (ctx) => {
|
||||||
await strapi.plugins['config-sync'].services.main.exportAllConfig();
|
await strapi.plugin('config-sync').service('main').exportAllConfig();
|
||||||
|
|
||||||
ctx.send({
|
ctx.send({
|
||||||
message: `Config was successfully exported to ${strapi.plugins['config-sync'].config.destination}.`,
|
message: `Config was successfully exported to ${strapi.config.get('plugin.config-sync.destination')}.`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
importAll: async (ctx) => {
|
importAll: async (ctx) => {
|
||||||
// Check for existance of the config file destination dir.
|
// Check for existance of the config file destination dir.
|
||||||
if (!fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
|
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
|
||||||
ctx.send({
|
ctx.send({
|
||||||
message: 'No config files were found.',
|
message: 'No config files were found.',
|
||||||
});
|
});
|
||||||
|
@ -38,7 +38,7 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await strapi.plugins['config-sync'].services.main.importAllConfig();
|
await strapi.plugin('config-sync').service('main').importAllConfig();
|
||||||
|
|
||||||
ctx.send({
|
ctx.send({
|
||||||
message: 'Config was successfully imported.',
|
message: 'Config was successfully imported.',
|
||||||
|
@ -56,7 +56,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
getDiff: async (ctx) => {
|
getDiff: async (ctx) => {
|
||||||
// Check for existance of the config file destination dir.
|
// Check for existance of the config file destination dir.
|
||||||
if (!fs.existsSync(strapi.plugins['config-sync'].config.destination)) {
|
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
|
||||||
ctx.send({
|
ctx.send({
|
||||||
message: 'No config files were found.',
|
message: 'No config files were found.',
|
||||||
});
|
});
|
||||||
|
@ -70,8 +70,8 @@ module.exports = {
|
||||||
diff: {},
|
diff: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileConfig = await strapi.plugins['config-sync'].services.main.getAllConfigFromFiles();
|
const fileConfig = await strapi.plugin('config-sync').service('main').getAllConfigFromFiles();
|
||||||
const databaseConfig = await strapi.plugins['config-sync'].services.main.getAllConfigFromDatabase();
|
const databaseConfig = await strapi.plugin('config-sync').service('main').getAllConfigFromDatabase();
|
||||||
|
|
||||||
const diff = difference(databaseConfig, fileConfig);
|
const diff = difference(databaseConfig, fileConfig);
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,12 @@ module.exports = () => ({
|
||||||
? JSON.stringify(fileContents, null, 2)
|
? JSON.stringify(fileContents, null, 2)
|
||||||
: JSON.stringify(fileContents);
|
: JSON.stringify(fileContents);
|
||||||
|
|
||||||
if (!fs.existsSync(strapi.config.get('plugin.config-sync').destination)) {
|
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
|
||||||
fs.mkdirSync(strapi.config.get('plugin.config-sync').destination, { recursive: true });
|
fs.mkdirSync(strapi.config.get('plugin.config-sync.destination'), { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const writeFile = util.promisify(fs.writeFile);
|
const writeFile = util.promisify(fs.writeFile);
|
||||||
await writeFile(`${strapi.config.get('plugin.config-sync').destination}${configType}.${configName}.json`, json)
|
await writeFile(`${strapi.config.get('plugin.config-sync.destination')}${configType}.${configName}.json`, json)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// @TODO:
|
// @TODO:
|
||||||
// Add logging for successfull config export.
|
// Add logging for successfull config export.
|
||||||
|
@ -55,7 +55,7 @@ module.exports = () => ({
|
||||||
const shouldExclude = strapi.config.get('plugin.config-sync.exclude').includes(`${configName}`);
|
const shouldExclude = strapi.config.get('plugin.config-sync.exclude').includes(`${configName}`);
|
||||||
if (shouldExclude) return;
|
if (shouldExclude) return;
|
||||||
|
|
||||||
fs.unlinkSync(`${strapi.config.get('plugin.config-sync').destination}${configName}.json`);
|
fs.unlinkSync(`${strapi.config.get('plugin.config-sync.destination')}${configName}.json`);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +67,7 @@ module.exports = () => ({
|
||||||
*/
|
*/
|
||||||
readConfigFile: async (configType, configName) => {
|
readConfigFile: async (configType, configName) => {
|
||||||
const readFile = util.promisify(fs.readFile);
|
const readFile = util.promisify(fs.readFile);
|
||||||
return readFile(`${strapi.config.get('plugin.config-sync').destination}${configType}.${configName}.json`)
|
return readFile(`${strapi.config.get('plugin.config-sync.destination')}${configType}.${configName}.json`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
return JSON.parse(data);
|
return JSON.parse(data);
|
||||||
})
|
})
|
||||||
|
@ -84,11 +84,11 @@ module.exports = () => ({
|
||||||
* @returns {object} Object with key value pairs of configs.
|
* @returns {object} Object with key value pairs of configs.
|
||||||
*/
|
*/
|
||||||
getAllConfigFromFiles: async (configType = null) => {
|
getAllConfigFromFiles: async (configType = null) => {
|
||||||
if (!fs.existsSync(strapi.config.get('plugin.config-sync').destination)) {
|
if (!fs.existsSync(strapi.config.get('plugin.config-sync.destination'))) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const configFiles = fs.readdirSync(strapi.config.get('plugin.config-sync').destination);
|
const configFiles = fs.readdirSync(strapi.config.get('plugin.config-sync.destination'));
|
||||||
|
|
||||||
const getConfigs = async () => {
|
const getConfigs = async () => {
|
||||||
const fileConfigs = {};
|
const fileConfigs = {};
|
||||||
|
|
Loading…
Reference in New Issue