@@ -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 ) ) {
0 commit comments