Skip to content

Commit

Permalink
Fix unzipping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-wd committed Dec 10, 2023
1 parent ce32e19 commit 3ef4093
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions commands/setup_theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,27 @@ async function setup_theme(themeName) {
// Download the zip file
await downloadFile(zipUrl, 'theme-redone.zip');

// Unzip the file
// Unzip the file to a temporary directory
const spinner = ora('Unzipping the file...').start();
const zip = new AdmZip('theme-redone.zip');
zip.extractAllTo('theme-redone', true); // Extract to current directory
const tempExtractPath = path.join('.', 'temp-extract');
fs.mkdirSync(tempExtractPath, { recursive: true });
zip.extractAllTo(tempExtractPath, true);
spinner.succeed('Unzipping completed');

// Determine the top-level directory name and move its contents
const extractedFolders = fs.readdirSync(tempExtractPath);
if (extractedFolders.length !== 1) {
console.error(chalk.red('Unexpected structure in the zip file.'));
return false;
}

const topLevelDir = path.join(tempExtractPath, extractedFolders[0]);
fs.renameSync(topLevelDir, newThemePath);

// Clean up temporary directory
fs.rmdirSync(tempExtractPath, { recursive: true });

// Delete the .git directory from the new theme folder
const gitDirPath = path.join(newThemePath, '.git');
if (fs.existsSync(gitDirPath)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webredone/trb-cli",
"version": "3.0.6",
"version": "3.0.7",
"description": "TRB-CLI is a handy Node.js CLI that automates the process of managing blocks in a Theme Redone WordPress theme",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 3ef4093

Please sign in to comment.