diff --git a/commands/setup_theme.js b/commands/setup_theme.js index 6565374..5883d0e 100644 --- a/commands/setup_theme.js +++ b/commands/setup_theme.js @@ -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)) { diff --git a/package.json b/package.json index 9251490..d4a4ed3 100644 --- a/package.json +++ b/package.json @@ -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",