diff --git a/README.md b/README.md index 7a81ce3..f2fe480 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# Strapi plugin config +# Strapi plugin config-sync -A quick description of config. +A quick description of config-sync. diff --git a/admin/src/components/Header/index.js b/admin/src/components/Header/index.js index f0cfd05..854481a 100644 --- a/admin/src/components/Header/index.js +++ b/admin/src/components/Header/index.js @@ -13,9 +13,9 @@ const HeaderComponent = () => { const headerProps = { title: { - label: formatMessage({ id: 'config.Header.Title' }), + label: formatMessage({ id: 'config-sync.Header.Title' }), }, - content: formatMessage({ id: 'config.Header.Description' }), + content: formatMessage({ id: 'config-sync.Header.Description' }), }; return ( diff --git a/admin/src/state/actions/Config.js b/admin/src/state/actions/Config.js index add0e49..125db60 100644 --- a/admin/src/state/actions/Config.js +++ b/admin/src/state/actions/Config.js @@ -11,8 +11,8 @@ export function getAllConfig() { return async function(dispatch) { dispatch(setLoadingState(true)); try { - const databaseConfig = await request('/config/all/from-database', { method: 'GET' }); - const fileConfig = await request('/config/all/from-files', { method: 'GET' }); + const databaseConfig = await request('/config-sync/all/from-database', { method: 'GET' }); + const fileConfig = await request('/config-sync/all/from-files', { method: 'GET' }); dispatch(setFileConfigInState(fileConfig)); dispatch(setDatabaseConfigInState(databaseConfig)); dispatch(setLoadingState(false)); @@ -43,7 +43,7 @@ export function exportAllConfig() { return async function(dispatch) { dispatch(setLoadingState(true)); try { - const { message } = await request('/config/export', { method: 'GET' }); + const { message } = await request('/config-sync/export', { method: 'GET' }); dispatch(setFileConfigInState(Map({}))); dispatch(setDatabaseConfigInState(Map({}))); @@ -60,7 +60,7 @@ export function importAllConfig() { return async function(dispatch) { dispatch(setLoadingState(true)); try { - const { message } = await request('/config/import', { method: 'GET' }); + const { message } = await request('/config-sync/import', { method: 'GET' }); dispatch(setFileConfigInState(Map({}))); dispatch(setDatabaseConfigInState(Map({}))); diff --git a/config/config.json b/config/config.json index b97cc8d..f0a37b5 100644 --- a/config/config.json +++ b/config/config.json @@ -1,5 +1,5 @@ { - "destination": "extensions/config/files/", + "destination": "extensions/config-sync/files/", "minify": false, "importOnBootstrap": false, "exclude": [] diff --git a/config/functions/bootstrap.js b/config/functions/bootstrap.js index db207b5..9324aff 100644 --- a/config/functions/bootstrap.js +++ b/config/functions/bootstrap.js @@ -13,12 +13,12 @@ const fs = require('fs'); */ module.exports = () => { - if (strapi.plugins.config.config.importOnBootstrap) { - if (fs.existsSync(strapi.plugins.config.config.destination)) { - const configFiles = fs.readdirSync(strapi.plugins.config.config.destination); + if (strapi.plugins['config-sync'].config.importOnBootstrap) { + if (fs.existsSync(strapi.plugins['config-sync'].config.destination)) { + const configFiles = fs.readdirSync(strapi.plugins['config-sync'].config.destination); configFiles.map((file) => { - strapi.plugins.config.services.config.importFromFile(file.slice(0, -5)); + strapi.plugins['config-sync'].services.config.importFromFile(file.slice(0, -5)); }); } } diff --git a/controllers/config.js b/controllers/config.js index e3ac9e7..745315c 100644 --- a/controllers/config.js +++ b/controllers/config.js @@ -18,11 +18,11 @@ module.exports = { const coreStore = await coreStoreAPI.find({ _limit: -1 }); Object.values(coreStore).map(async ({ key, value }) => { - await strapi.plugins.config.services.config.writeConfigFile(key, value); + await strapi.plugins['config-sync'].services.config.writeConfigFile(key, value); }); ctx.send({ - message: `Config was successfully exported to ${strapi.plugins.config.config.destination}.` + message: `Config was successfully exported to ${strapi.plugins['config-sync'].config.destination}.` }); }, @@ -34,7 +34,7 @@ module.exports = { */ import: async (ctx) => { // Check for existance of the config file destination dir. - if (!fs.existsSync(strapi.plugins.config.config.destination)) { + if (!fs.existsSync(strapi.plugins['config-sync'].config.destination)) { ctx.send({ message: 'No config files were found.' }); @@ -42,10 +42,10 @@ module.exports = { return; } - const configFiles = fs.readdirSync(strapi.plugins.config.config.destination); + const configFiles = fs.readdirSync(strapi.plugins['config-sync'].config.destination); configFiles.map((file) => { - strapi.plugins.config.services.config.importFromFile(file.slice(0, -5)); + strapi.plugins['config-sync'].services.config.importFromFile(file.slice(0, -5)); }); ctx.send({ @@ -61,7 +61,7 @@ module.exports = { */ getConfigsFromFiles: async (ctx) => { // Check for existance of the config file destination dir. - if (!fs.existsSync(strapi.plugins.config.config.destination)) { + if (!fs.existsSync(strapi.plugins['config-sync'].config.destination)) { ctx.send({ message: 'No config files were found.' }); @@ -69,13 +69,13 @@ module.exports = { return; } - const configFiles = fs.readdirSync(strapi.plugins.config.config.destination); + const configFiles = fs.readdirSync(strapi.plugins['config-sync'].config.destination); let formattedConfigs = {}; const getConfigs = async () => { return Promise.all(configFiles.map(async (file) => { const formattedConfigName = file.slice(0, -5); // remove the .json extension. - const fileContents = await strapi.plugins.config.services.config.readConfigFile(formattedConfigName); + const fileContents = await strapi.plugins['config-sync'].services.config.readConfigFile(formattedConfigName); formattedConfigs[formattedConfigName] = fileContents; })); }; diff --git a/package.json b/package.json index b1fa504..bb14216 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "strapi-plugin-config", + "name": "strapi-plugin-config-sync", "version": "0.0.1", - "description": "Manage your Strapi core_store configuration as partial json files which can be imported/exported across environments. ", + "description": "Manage your Strapi database configuration as partial json files which can be imported/exported across environments. ", "strapi": { - "name": "config", + "name": "config-sync", "icon": "plug", - "description": "Manage your Strapi core_store configuration as partial json files which can be imported/exported across environments. " + "description": "Manage your Strapi database configuration as partial json files which can be imported/exported across environments. " }, "dependencies": { "immutable": "^4.0.0-rc.12", diff --git a/services/config.js b/services/config.js index eec935a..ab1cc1c 100644 --- a/services/config.js +++ b/services/config.js @@ -17,21 +17,21 @@ module.exports = { */ writeConfigFile: async (configName, fileContents) => { // Check if the config should be excluded. - const shouldExclude = strapi.plugins.config.config.exclude.includes(configName); + const shouldExclude = strapi.plugins['config-sync'].config.exclude.includes(configName); if (shouldExclude) return; // Check if the JSON content should be minified. const json = - !strapi.plugins.config.config.minify ? + !strapi.plugins['config-sync'].config.minify ? JSON.stringify(JSON.parse(fileContents), null, 2) : fileContents; - if (!fs.existsSync(strapi.plugins.config.config.destination)) { - fs.mkdirSync(strapi.plugins.config.config.destination, { recursive: true }); + if (!fs.existsSync(strapi.plugins['config-sync'].config.destination)) { + fs.mkdirSync(strapi.plugins['config-sync'].config.destination, { recursive: true }); } const writeFile = util.promisify(fs.writeFile); - await writeFile(`${strapi.plugins.config.config.destination}${configName}.json`, json); + await writeFile(`${strapi.plugins['config-sync'].config.destination}${configName}.json`, json); }, /** @@ -42,7 +42,7 @@ module.exports = { */ readConfigFile: async (configName) => { const readFile = util.promisify(fs.readFile); - return await readFile(`${strapi.plugins.config.config.destination}${configName}.json`) + return await readFile(`${strapi.plugins['config-sync'].config.destination}${configName}.json`) .then((data) => { return JSON.parse(data); }) @@ -59,11 +59,11 @@ module.exports = { */ importFromFile: async (configName) => { // Check if the config should be excluded. - const shouldExclude = strapi.plugins.config.config.exclude.includes(configName); + const shouldExclude = strapi.plugins['config-sync'].config.exclude.includes(configName); if (shouldExclude) return; const coreStoreAPI = strapi.query('core_store'); - const fileContents = await strapi.plugins.config.services.config.readConfigFile(configName); + const fileContents = await strapi.plugins['config-sync'].services.config.readConfigFile(configName); const configExists = await strapi .query('core_store')