chore: 新增清理脚本并优化项目配置

1.  新增clean脚本用于清理项目构建产物和缓存
2.  更新.gitignore忽略eslint缓存和src-tauri的target目录
3.  在package.json中添加clean命令
4.  格式化StudentManager组件的回调函数代码
This commit is contained in:
Yukino_fox
2026-07-05 10:47:39 +08:00
parent 1c2cc2e077
commit fbf8079cca
4 changed files with 202 additions and 41 deletions
+144
View File
@@ -0,0 +1,144 @@
/**
* Clean script - Similar to `flutter clean`
* Cleans all build artifacts and caches for the Tauri project
*/
const fs = require("fs")
const path = require("path")
// ANSI color codes for console output
const colors = {
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
reset: "\x1b[0m",
}
/**
* Delete a directory recursively
* @param {string} dirPath - Path to directory to delete
*/
function deleteDirectory(dirPath) {
const fullPath = path.resolve(dirPath)
if (!fs.existsSync(fullPath)) {
console.log(`${colors.yellow}${colors.reset} Not found: ${dirPath}`)
return false
}
try {
fs.rmSync(fullPath, { recursive: true, force: true })
console.log(`${colors.green}${colors.reset} Deleted: ${dirPath}`)
return true
} catch (error) {
console.error(`${colors.red}${colors.reset} Failed to delete ${dirPath}: ${error.message}`)
return false
}
}
/**
* Delete a file
* @param {string} filePath - Path to file to delete
*/
function deleteFile(filePath) {
const fullPath = path.resolve(filePath)
if (!fs.existsSync(fullPath)) {
console.log(`${colors.yellow}${colors.reset} Not found: ${filePath}`)
return false
}
try {
fs.unlinkSync(fullPath)
console.log(`${colors.green}${colors.reset} Deleted: ${filePath}`)
return true
} catch (error) {
console.error(`${colors.red}${colors.reset} Failed to delete ${filePath}: ${error.message}`)
return false
}
}
/**
* Main clean function
*/
function clean() {
console.log(`\n${colors.blue}════════════════════════════════════════${colors.reset}`)
console.log(`${colors.blue} SecScore Clean - Removing build artifacts${colors.reset}`)
console.log(`${colors.blue}════════════════════════════════════════${colors.reset}\n`)
// Get project root directory
const rootDir = path.resolve(__dirname, "..")
// Directories to clean
const dirsToClean = [
// Node.js / Frontend
"node_modules",
"dist",
".vite",
// Rust / Tauri
"src-tauri/target",
// Test coverage
"coverage",
// Cache directories
".eslintcache",
"node_modules/.cache",
]
// Files to clean
const filesToClean = [
// Lock files
"pnpm-lock.yaml",
]
let deletedCount = 0
let failedCount = 0
// Clean directories
console.log(`${colors.blue}Cleaning directories:${colors.reset}`)
for (const dir of dirsToClean) {
const dirPath = path.join(rootDir, dir)
if (deleteDirectory(dirPath)) {
deletedCount++
} else if (fs.existsSync(dirPath)) {
failedCount++
}
}
// Clean files
if (filesToClean.length > 0) {
console.log(`\n${colors.blue}Cleaning files:${colors.reset}`)
for (const file of filesToClean) {
const filePath = path.join(rootDir, file)
if (deleteFile(filePath)) {
deletedCount++
} else if (fs.existsSync(filePath)) {
failedCount++
}
}
}
// Summary
console.log(`\n${colors.blue}════════════════════════════════════════${colors.reset}`)
console.log(`${colors.green}✓ Deleted: ${deletedCount}${colors.reset}`)
if (failedCount > 0) {
console.log(`${colors.red}✗ Failed: ${failedCount}${colors.reset}`)
}
console.log(`${colors.blue}════════════════════════════════════════${colors.reset}`)
if (failedCount > 0) {
console.log(
`\n${colors.yellow}⚠ Some items could not be deleted. Try closing any running processes and try again.${colors.reset}\n`
)
process.exit(1)
}
console.log(`\n${colors.green}✓ Clean completed successfully!${colors.reset}`)
console.log(`${colors.yellow} Run 'pnpm install' to reinstall dependencies.${colors.reset}\n`)
}
// Run clean
clean()