Skip to content

Commit be3873f

Browse files
authored
Fix unzipping issue (#16)
1 parent ce32e19 commit be3873f

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

commands/setup_theme.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,27 @@ async function setup_theme(themeName) {
8181
// Download the zip file
8282
await downloadFile(zipUrl, 'theme-redone.zip');
8383

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

92+
// Determine the top-level directory name and move its contents
93+
const extractedFolders = fs.readdirSync(tempExtractPath);
94+
if (extractedFolders.length !== 1) {
95+
console.error(chalk.red('Unexpected structure in the zip file.'));
96+
return false;
97+
}
98+
99+
const topLevelDir = path.join(tempExtractPath, extractedFolders[0]);
100+
fs.renameSync(topLevelDir, newThemePath);
101+
102+
// Clean up temporary directory
103+
fs.rmdirSync(tempExtractPath, { recursive: true });
104+
90105
// Delete the .git directory from the new theme folder
91106
const gitDirPath = path.join(newThemePath, '.git');
92107
if (fs.existsSync(gitDirPath)) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webredone/trb-cli",
3-
"version": "3.0.6",
3+
"version": "3.0.7",
44
"description": "TRB-CLI is a handy Node.js CLI that automates the process of managing blocks in a Theme Redone WordPress theme",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)