File: /home/zeusxp5/chuair.org/wp-content/themes/lifttruck/zip-theme.js
const path = require('path');
const zipdir = require('zip-dir');
const fs = require('fs-extra');
const themeFolder = path.resolve(__dirname);
const themeName = path.basename(themeFolder);
const outputZip = path.resolve(path.join(__dirname, '..'), `${themeName}.zip`);
const zipDir = path.join(path.join(__dirname, '..'), 'temp');
const tempDir = path.join(path.join(__dirname, '..'), 'temp', themeName);
// Create a temporary directory and copy the contents of the theme folder
fs.emptyDirSync(tempDir);
const copyOptions = {
filter: (src, dest) => {
// Exclude the node_modules directory from the copy
return !src.includes('node_modules');
},
};
fs.copySync(themeFolder, tempDir, copyOptions);
const options = {
saveTo: outputZip,
filter: (path, stat) => {
if (path.includes('node_modules') ||
path.includes('resources') ||
path.includes('src') ||
path.includes('package') ||
path.includes('webpack.config') ||
path.includes('zip-theme')) {
return false;
}
const fileName = path.split('\\').pop();
if (/^\..*/.test(fileName)) {
return false;
}
return true;
},
//each: (path) => console.log(`${path} added!`),
};
// Zip the contents of the temporary directory
zipdir(zipDir, options, function (err, buffer) {
if (err) {
console.error(err);
} else {
console.log(`${buffer.length} total bytes`);
console.log('ZIP file created successfully!');
}
// Remove the temporary directory
fs.removeSync(zipDir);
});