From af5b2f8e02de8367d5d638c1229866748b6891bb Mon Sep 17 00:00:00 2001 From: katelya Date: Mon, 1 Sep 2025 20:38:46 +0800 Subject: [PATCH] =?UTF-8?q?=20=E7=A7=BB=E9=99=A4=E7=83=A6=E4=BA=BA?= =?UTF-8?q?=E7=9A=84=E7=89=88=E6=9C=AC=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=EF=BC=8C=E7=AE=80=E5=8C=96=E6=8F=90=E4=BA=A4=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/pre-commit | 8 +-- package.json | 6 +-- scripts/check-package-manager.js | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 scripts/check-package-manager.js diff --git a/.husky/pre-commit b/.husky/pre-commit index 74bd7d6..9d97a6f 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,11 +1,5 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -# 生成版本号 -pnpm gen:version - -# 自动添加修改的版本文件 -git add src/lib/version.ts -git add VERSION.txt - +# 只运行代码检查,简单干净 npx lint-staged \ No newline at end of file diff --git a/package.json b/package.json index 9f0add8..647d187 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "pnpm gen:runtime && pnpm gen:manifest && next dev -H 0.0.0.0", - "build": "pnpm gen:runtime && pnpm gen:manifest && next build", + "dev": "npm run gen:runtime && npm run gen:manifest && next dev -H 0.0.0.0", + "build": "npm run gen:runtime && npm run gen:manifest && next build", "start": "next start", "lint": "next lint", - "lint:fix": "eslint src --fix && pnpm format", + "lint:fix": "eslint src --fix && npm run format", "lint:strict": "eslint --max-warnings=0 src", "typecheck": "tsc --noEmit --incremental false", "test:watch": "jest --watch", diff --git a/scripts/check-package-manager.js b/scripts/check-package-manager.js new file mode 100644 index 0000000..1c05224 --- /dev/null +++ b/scripts/check-package-manager.js @@ -0,0 +1,83 @@ +#!/usr/bin/env node + +/** + * 智能包管理器检测和推荐脚本 + * 帮助用户选择最适合的包管理器 + */ + +const { execSync } = require('child_process'); +const fs = require('fs'); +const path = require('path'); + +console.log('🔍 检测包管理器环境...\n'); + +// 检测函数 +function checkCommand(command) { + try { + execSync(`${command} --version`, { stdio: 'pipe' }); + return true; + } catch { + return false; + } +} + +function getVersion(command) { + try { + const version = execSync(`${command} --version`, { encoding: 'utf8' }).trim(); + return version; + } catch { + return 'unknown'; + } +} + +// 检测包管理器 +const hasNpm = checkCommand('npm'); +const hasPnpm = checkCommand('pnpm'); +const hasYarn = checkCommand('yarn'); + +const npmVersion = hasNpm ? getVersion('npm') : null; +const pnpmVersion = hasPnpm ? getVersion('pnpm') : null; +const yarnVersion = hasYarn ? getVersion('yarn') : null; + +// 检测锁文件 +const hasPnpmLock = fs.existsSync('pnpm-lock.yaml'); +const hasNpmLock = fs.existsSync('package-lock.json'); +const hasYarnLock = fs.existsSync('yarn.lock'); + +console.log('📦 包管理器检测结果:'); +console.log(` npm: ${hasNpm ? '✅ ' + npmVersion : '❌ 未安装'}`); +console.log(` pnpm: ${hasPnpm ? '✅ ' + pnpmVersion : '❌ 未安装'}`); +console.log(` yarn: ${hasYarn ? '✅ ' + yarnVersion : '❌ 未安装'}`); + +console.log('\n🔒 锁文件检测结果:'); +console.log(` pnpm-lock.yaml: ${hasPnpmLock ? '✅ 存在' : '❌ 不存在'}`); +console.log(` package-lock.json: ${hasNpmLock ? '✅ 存在' : '❌ 不存在'}`); +console.log(` yarn.lock: ${hasYarnLock ? '✅ 存在' : '❌ 不存在'}`); + +// 智能推荐 +console.log('\n💡 智能推荐:'); + +if (hasPnpm && hasPnpmLock) { + console.log(' 🎯 推荐使用 pnpm (已安装且有锁文件)'); + console.log(' 📝 运行命令: pnpm install && pnpm dev'); +} else if (hasNpm && hasNpmLock) { + console.log(' 🎯 推荐使用 npm (已安装且有锁文件)'); + console.log(' 📝 运行命令: npm install && npm run dev'); +} else if (hasPnpm) { + console.log(' 🎯 推荐使用 pnpm (性能更好)'); + console.log(' 📝 运行命令: pnpm install && pnpm dev'); +} else if (hasNpm) { + console.log(' 🎯 使用 npm (已安装)'); + console.log(' 📝 运行命令: npm install && npm run dev'); +} else { + console.log(' ❌ 未检测到任何包管理器,请先安装 Node.js'); +} + +// 安装建议 +if (!hasPnpm && hasNpm) { + console.log('\n🚀 pnpm 安装建议 (可选):'); + console.log(' npm install -g pnpm # 通过npm安装'); + console.log(' corepack enable && corepack prepare pnpm@latest --activate # 通过corepack'); +} + +console.log('\n✨ KatelyaTV 支持智能包管理器检测,任何包管理器都可以正常工作!');