@tianyio/quality-helper
Version:
A comprehensive quality helper tool for project scaffolding and management
350 lines (269 loc) • 8.96 kB
Markdown
质量助手(Quality
Helper)是一个集代码规范、版本管理和开发流程优化于一体的现代化前端脚手架工具。提供一站式代码质量解决方案,支持快速集成到现代前端项目开发流程中,具备智能依赖管理、配置文件更新、版本信息生成等核心功能。
```bash
npm install -g @tianyio/quality-helper
pnpm add -g @tianyio/quality-helper
yarn global add @tianyio/quality-helper
npm install @tianyio/quality-helper
npx @tianyio/quality-helper <command>
```
```bash
npx quality-helper create
npx qh create
npx quality-helper create my-vue-app --single
npx qh create my-vue-app --single
npx quality-helper create my-workspace --monorepo
npx qh create my-workspace --monorepo
```
```bash
cd existing-project
npx quality-helper update-config
npx qh update-config
npx quality-helper update-deps
npx qh update-deps
```
```bash
npm run lint
npm run format
git add .
git commit -m "feat: add quality tools"
```
```typescript
// vite.config.ts
import { defineConfig } from 'vite'
import { versionInfoPlugin } from '@tianyio/quality-helper/version-plugin'
export default defineConfig({
plugins: [
versionInfoPlugin({
// 开发模式下提供API接口
injectGitInfo: true,
injectBuildTime: true,
// 生产构建时生成版本文件
generateFile: true,
outputPath: 'dist/version.json',
}),
],
})
```
```typescript
// 在Vue组件中使用
<template>
<div class="version-info">
<p>版本: {{ versionInfo.version }}</p>
<p>构建时间: {{ versionInfo.buildTime }}</p>
<p>Git提交: {{ versionInfo.gitCommitShort }}</p>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import versionInfo from 'virtual:version-info'
</script>
```
```bash
npx quality-helper create [项目名称] [选项]
npx qh create [项目名称] [选项]
npx quality-helper create
npx qh create
npx quality-helper create my-awesome-project
npx qh create my-awesome-project
npx quality-helper create my-project --single
npx qh create my-workspace --monorepo
npx quality-helper create vue-admin --single
npx qh create react-components --monorepo
```
**创建流程说明:**
1. 选择项目架构(单体/Monorepo)
2. 选择前端框架(Vue3/React/Vanilla)
3. 配置项目基础信息
4. 自动安装依赖和配置工具
5. 初始化 Git 仓库和提交规范
```bash
npx quality-helper update-deps
```
**依赖管理特性:**
- 🔍 **智能检测** - 自动识别包管理器(npm/pnpm/yarn)
- 📊 **状态分析** - 显示过时依赖和安全漏洞
- 🎯 **精准分类** - 区分生产依赖和开发依赖
- 🚀 **批量操作** - 支持一键更新所有依赖
- 🛠️ **自动修复** - 自动处理pnpm锁文件损坏问题
- 🔄 **版本智能获取** - 自动获取npm最新稳定版本号
- **智能合并**:自动合并现有配置与模板配置
- **一步式选择**:支持分组全选或单文件选择
- **模板优先**:新配置项优先,保留用户自定义配置
- **格式保持**:保持原有文件格式和注释结构
- **依赖自动安装**:配置更新后自动检测并提示安装所需依赖
- **智能依赖分类**:自动区分生产依赖和开发依赖进行安装
- **智能检测**:自动检测项目中缺失的依赖包
- **分类安装**:区分生产依赖和开发依赖,精准安装
- **多包管理器支持**:自动检测并使用项目的包管理器(npm/yarn/pnpm)
- **版本管理**:支持更新到推荐版本或最新版本
- **依赖清理**:支持清理缓存和重新安装
- **状态检查**:提供详细的依赖状态报告
- **锁文件修复**:自动检测并修复pnpm锁文件损坏问题(ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY)
- **版本号智能解析**:当依赖版本为'latest'时,自动获取npm仓库最新稳定版本
- **错误恢复**:遇到依赖冲突时自动使用--no-frozen-lockfile参数重试安装
```ts
interface VersionInfo {
// 基本信息
name: string // 项目名称
version: string // 项目版本
description: string // 项目描述
author: string // 项目作者
homepage: string // 项目主页
repository: string // 仓库地址
license: string // 许可证
// 构建信息
buildTime: string // 构建时间(ISO格式)
buildTimestamp: number // 构建时间戳
// Git信息
gitCommitHash: string // 完整提交哈希
gitCommitShort: string // 短提交哈希
gitBranch: string // 当前分支
gitCommitDate: string // 提交日期
gitCommitMessage: string // 提交信息
gitAuthor: string // 提交作者
gitEmail: string // 作者邮箱
gitDirty: boolean // 是否有未提交更改
// 环境信息
nodeVersion: string // Node.js版本
platform: string // 操作系统平台
arch: string // 系统架构
}
```
| 配置文件 | 描述 |
| ------------- | -------------- |
| .editorconfig | 编辑器配置文件 |
| 配置文件 | 描述 |
| ------------- | --------------- |
| .eslintrc.js | ESLint 配置文件 |
| .eslintignore | ESLint 忽略文件 |
| 配置文件 | 描述 |
| --------------- | ----------------- |
| .prettierrc | Prettier 配置文件 |
| .prettierignore | Prettier 忽略文件 |
| 配置文件 | 描述 |
| -------------------- | -------------------- |
| .gitignore | Git 忽略文件 |
| .gitattributes | Git 属性文件 |
| .lintstagedrc.js | Lint-staged 配置文件 |
| commitlint.config.js | Commitlint 配置文件 |
| .husky/pre-commit | Git pre-commit 钩子 |
| .husky/commit-msg | Git commit-msg 钩子 |
| 配置文件 | 描述 |
| -------- | ------------- |
| .npmrc | NPM 配置文件 |
| .pnpmrc | PNPM 配置文件 |
| 配置文件 | 描述 |
| ------------ | ------------ |
| .env | 环境变量文件 |
| .env.local | 本地环境变量 |
| .env.develop | 开发环境变量 |
| .env.prod | 生产环境变量 |
```bash
npx quality-helper create my-admin-system --single
cd my-admin-system
npm run dev
```
```bash
cd legacy-project
npx quality-helper update-config
npx quality-helper update-deps
npm run lint
npm run format
git add . && git commit -m "feat: 添加代码质量工具"
```
```bash
npx quality-helper create ui-components --monorepo
cd ui-components
npx quality-helper update-deps
```
```bash
git clone <project-url>
cd project
npx quality-helper update-deps
npx quality-helper update-config
git commit -m "feat(components): 添加新按钮组件"
```