fix: 修复release.js 默认没有清理临时文件的问题
This commit is contained in:
66
release.js
66
release.js
@@ -211,12 +211,13 @@ function createZipArchive(sourceDir, outputPath) {
|
|||||||
try {
|
try {
|
||||||
// 根据操作系统选择命令
|
// 根据操作系统选择命令
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
// Windows系统使用PowerShell命令
|
// Windows系统使用PowerShell命令,排除文件名后缀为 -mp-weixin.zip 的文件
|
||||||
const command = `Compress-Archive -Path "${sourceDir}\*" -DestinationPath "${outputPath}" -Force`;
|
// 使用PowerShell的管道功能和Where-Object来排除特定文件
|
||||||
execSync(command, { shell: 'powershell.exe' });
|
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 {
|
} else {
|
||||||
// Linux/Mac系统使用zip命令
|
// Linux/Mac系统使用zip命令,排除文件名后缀为 -mp-weixin.zip 的文件
|
||||||
const command = `zip -r "${outputPath}" * -d "${sourceDir}"`;
|
const command = `zip -r "${outputPath}" * -x "*-mp-weixin.zip"`;
|
||||||
execSync(command, { cwd: sourceDir });
|
execSync(command, { cwd: sourceDir });
|
||||||
}
|
}
|
||||||
console.log(`Zip archive created: ${outputPath}`);
|
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() {
|
function main() {
|
||||||
try {
|
try {
|
||||||
@@ -235,30 +261,7 @@ function main() {
|
|||||||
|
|
||||||
// 清理dist目录(如果存在且不保留)
|
// 清理dist目录(如果存在且不保留)
|
||||||
if (fs.existsSync(distDir)) {
|
if (fs.existsSync(distDir)) {
|
||||||
if (keepDist) {
|
cleanDistDir(distDir);
|
||||||
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)');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 创建dist目录
|
// 创建dist目录
|
||||||
fs.mkdirSync(distDir, { recursive: true });
|
fs.mkdirSync(distDir, { recursive: true });
|
||||||
@@ -279,6 +282,11 @@ function main() {
|
|||||||
console.log('Creating zip archive...');
|
console.log('Creating zip archive...');
|
||||||
createZipArchive(distDir, zipPath);
|
createZipArchive(distDir, zipPath);
|
||||||
|
|
||||||
|
// 清理dist目录(如果不保留)
|
||||||
|
if (!keepDist) {
|
||||||
|
cleanDistDir(distDir);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('\nAll tasks completed successfully!');
|
console.log('\nAll tasks completed successfully!');
|
||||||
console.log(`Dist directory: ${distDir}`);
|
console.log(`Dist directory: ${distDir}`);
|
||||||
console.log(`Zip file: ${zipPath}`);
|
console.log(`Zip file: ${zipPath}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user