33const { isEmpty } = require ( 'lodash' ) ;
44const fs = require ( 'fs' ) ;
55const util = require ( 'util' ) ;
6+ const childProcess = require ( "child_process" ) ;
67const difference = require ( '../utils/getObjectDiff' ) ;
78const { logMessage } = require ( '../utils' ) ;
89
@@ -54,7 +55,7 @@ module.exports = () => ({
5455 * @param {string } configName - The name of the config file.
5556 * @returns {void }
5657 */
57- deleteConfigFile : async ( configName ) => {
58+ deleteConfigFile : async ( configName ) => {
5859 // Check if the config should be excluded.
5960 const shouldExclude = ! isEmpty ( strapi . config . get ( 'plugin::config-sync.excludedConfig' ) . filter ( ( option ) => configName . startsWith ( option ) ) ) ;
6061 if ( shouldExclude ) return ;
@@ -65,6 +66,23 @@ module.exports = () => ({
6566 fs . unlinkSync ( `${ strapi . config . get ( 'plugin::config-sync.syncDir' ) } ${ configName } .json` ) ;
6667 } ,
6768
69+ /**
70+ * Zip config files.
71+ *
72+ * @param {string } configName - The name of the config file.
73+ * @returns {void }
74+ */
75+ zipConfigFiles : async ( ) => {
76+ const fileName = `config-${ new Date ( ) . toJSON ( ) } .zip` ;
77+ childProcess . execSync ( `zip -r ${ fileName } *` , {
78+ cwd : strapi . config . get ( 'plugin.config-sync.syncDir' ) ,
79+ } ) ;
80+ const fullFilePath = `${ strapi . config . get ( 'plugin.config-sync.syncDir' ) } ${ fileName } ` ;
81+ const base64Data = fs . readFileSync ( fullFilePath , { encoding : 'base64' } ) ;
82+ fs . unlinkSync ( fullFilePath ) ;
83+ return { base64Data, name : fileName , message : 'Success' } ;
84+ } ,
85+
6886 /**
6987 * Read from a config file.
7088 *
@@ -191,7 +209,7 @@ module.exports = () => ({
191209 * @param {object } onSuccess - Success callback to run on each single successfull import.
192210 * @returns {void }
193211 */
194- exportAllConfig : async ( configType = null , onSuccess ) => {
212+ exportAllConfig : async ( configType = null , onSuccess ) => {
195213 const fileConfig = await strapi . plugin ( 'config-sync' ) . service ( 'main' ) . getAllConfigFromFiles ( ) ;
196214 const databaseConfig = await strapi . plugin ( 'config-sync' ) . service ( 'main' ) . getAllConfigFromDatabase ( ) ;
197215
0 commit comments