From 688c4b952e14d45c4d59f2ac84ffc9b4edb8018b Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 23 Dec 2025 09:52:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Drelease.js=20=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=B2=A1=E6=9C=89=E6=B8=85=E7=90=86=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release.js | 66 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/release.js b/release.js index d3b1efe..34c92c9 100644 --- a/release.js +++ b/release.js @@ -211,12 +211,13 @@ function createZipArchive(sourceDir, outputPath) { try { // 根据操作系统选择命令 if (process.platform === 'win32') { - // Windows系统使用PowerShell命令 - const command = `Compress-Archive -Path "${sourceDir}\*" -DestinationPath "${outputPath}" -Force`; - execSync(command, { shell: 'powershell.exe' }); + // Windows系统使用PowerShell命令,排除文件名后缀为 -mp-weixin.zip 的文件 + // 使用PowerShell的管道功能和Where-Object来排除特定文件 + const command = `PowerShell.exe -Command "Get-ChildItem -Path \"${sourceDir}\" | Where-Object { $_.Name -notlike '*\-mp\-weixin\.zip' } | Compress-Archive -DestinationPath \"${outputPath}\" -Force"`; + execSync(command, { shell: 'cmd.exe' }); } else { - // Linux/Mac系统使用zip命令 - const command = `zip -r "${outputPath}" * -d "${sourceDir}"`; + // Linux/Mac系统使用zip命令,排除文件名后缀为 -mp-weixin.zip 的文件 + const command = `zip -r "${outputPath}" * -x "*-mp-weixin.zip"`; execSync(command, { cwd: sourceDir }); } console.log(`Zip archive created: ${outputPath}`); @@ -226,6 +227,31 @@ function createZipArchive(sourceDir, outputPath) { } } +function cleanDistDir(distDir) { + if (fs.existsSync(distDir)) { + // 清理dist目录下除**-mp-weixin.zip文件外的所有内容 + const files = fs.readdirSync(distDir); + files.forEach(file => { + const filePath = path.join(distDir, file); + const stats = fs.statSync(filePath); + + // 只保留符合特定命名模式的zip文件(**-mp-weixin.zip) + if (stats.isFile() && path.extname(file) === '.zip' && file.endsWith('-mp-weixin.zip')) { + console.log(`Keeping zip file: ${file}`); + } else { + if (stats.isDirectory()) { + fs.rmSync(filePath, { recursive: true, force: true }); + console.log(`Removed directory: ${file}`); + } else { + fs.unlinkSync(filePath); + console.log(`Removed file: ${file}`); + } + } + }); + console.log('Cleaned dist directory (excluding -mp-weixin.zip files)'); + } +} + // 主函数 function main() { try { @@ -235,30 +261,7 @@ function main() { // 清理dist目录(如果存在且不保留) if (fs.existsSync(distDir)) { - if (keepDist) { - console.log('Keeping existing dist directory contents'); - } else { - // 清理dist目录下除zip文件外的所有内容 - const files = fs.readdirSync(distDir); - files.forEach(file => { - const filePath = path.join(distDir, file); - const stats = fs.statSync(filePath); - - // 只保留zip文件 - if (stats.isFile() && path.extname(file) === '.zip') { - console.log(`Keeping zip file: ${file}`); - } else { - if (stats.isDirectory()) { - fs.rmSync(filePath, { recursive: true, force: true }); - console.log(`Removed directory: ${file}`); - } else { - fs.unlinkSync(filePath); - console.log(`Removed file: ${file}`); - } - } - }); - console.log('Cleaned dist directory (excluding zip files)'); - } + cleanDistDir(distDir); } else { // 创建dist目录 fs.mkdirSync(distDir, { recursive: true }); @@ -278,6 +281,11 @@ function main() { // 创建zip压缩包 console.log('Creating zip archive...'); createZipArchive(distDir, zipPath); + + // 清理dist目录(如果不保留) + if (!keepDist) { + cleanDistDir(distDir); + } console.log('\nAll tasks completed successfully!'); console.log(`Dist directory: ${distDir}`);