AI 辅助的设计系统健康报告:自动生成组件使用率与弃用分析
AI 辅助的设计系统健康报告自动生成组件使用率与弃用分析一、这个组件三年前写的现在还有人在用吗设计系统维护者常见困境组件数量持续增长300但没人知道哪些组件还在用、哪些已经死了、哪些被滥用了。删除一个组件需要手动调研三周最后发现不敢删万一有人用呢。健康报告就是解决组件库的未知债务问题自动扫描全量业务代码统计每个组件的使用频率、使用方式Props 组合、最近使用时间生成一份量化的组件健康度报告。二、健康度评分模型健康度评分模型通过全量代码扫描启动自动提取组件引用并构建组件使用矩阵。基于该矩阵系统从五个关键维度量化组件状态使用频率0-100 分、Props 使用广度0-100 分、最近使用时间30 天内满分半年以上为 0 分、使用趋势增长/稳定/下降以及兼容性问题违反设计规范次数。上述维度数据将汇聚为综合健康分并依据分数区间进行状态判定健康 80 分广泛使用状态良好。注意50-80 分使用率下降需关注。危险 50 分考虑弃用或重构。死亡0 分可安全删除。三、健康报告生成器// health-report/component-health-analyzer.ts // 组件健康度分析器 interface ComponentHealth { componentName: string; /** 总使用次数 */ usageCount: number; ---/** 使用该组件的页面/模块数量/usageScope: number;/* 最后使用日期/lastUsedDate: string;/* Props 使用率被使用的 Props / 总 Props/propsUsageRate: number;/* 僵尸 Props定义了但从未被使用的 Props/zombieProps: string[];/* 使用趋势最近 3 个月 vs 前 3 个月/trend: growing | stable | declining | new | dead;/* 设计规范违规次数不推荐用法/designViolations: number;/* 综合健康分 0-100/healthScore: number;/* 建议操作 */recommendation: keep | monitor | refactor | deprecate | remove;}/**设计系统健康报告生成器扫描整个 monorepo分析每个组件的使用情况/class HealthReportGenerator {/*生成全量健康报告*/async generateReport(projectRoots: string[]): PromiseComponentHealth[] {const allUsages await this.scanAllProjects(projectRoots);const componentDefs await this.loadComponentDefinitions();const healths: ComponentHealth[] [];for (const [name, def] of Object.entries(componentDefs)) {const usage allUsages.filter(u u.componentName name);// 计算 Props 使用率const usedProps new Set();usage.forEach(u {Object.keys(u.props).forEach(p usedProps.add(p));});const totalDefinedProps def.props.length;const propsUsageRate totalDefinedProps 0? usedProps.size / totalDefinedProps: 1;// 僵尸 Propsconst zombieProps def.props.filter(p !usedProps.has(p.name)).map(p p.name);// 使用趋势const trend this.calcTrend(usage, name);// 健康分计算const healthScore this.calcHealthScore({usageCount: usage.length,usageScope: new Set(usage.map(u u.file)).size,propsUsageRate,zombiePropCount: zombieProps.length,trend,violations: 0});// 建议const recommendation this.getRecommendation(healthScore, usage.length, trend);healths.push({componentName: name,usageCount: usage.length,usageScope: new Set(usage.map(u u.file)).size,lastUsedDate: this.getLastUsedDate(usage),propsUsageRate: Math.round(propsUsageRate * 100) / 100,zombieProps,trend,designViolations: 0,healthScore,recommendation});}return healths.sort((a, b) b.usageCount - a.usageCount);}/**健康分计算权重分配使用频率: 30%使用广度: 20%Props 使用率: 20%近期活跃度: 15%趋势: 10%违规扣分: 5%*/private calcHealthScore(params: {usageCount: number;usageScope: number;propsUsageRate: number;zombiePropCount: number;trend: string;violations: number;}): number {let score 0;// 使用频率0-30分 if (params.usageCount 0) { score 0; } else if (params.usageCount 5) { score 10; } else if (params.usageCount 20) { score 20; } else { score 30; } // 使用广度0-20分 if (params.usageScope 20) score 20; else if (params.usageScope 10) score 15; else if (params.usageScope 3) score 10; else if (params.usageScope 0) score 5; // Props 使用率0-20分 score Math.round(params.propsUsageRate * 20); // 近期活跃度0-15分 // 由 calcTrend 内部赋值 // 趋势分数0-10分 switch (params.trend) { case growing: score 10; break; case stable: score 7; break; case new: score 5; break; case declining: score 2; break; case dead: score 0; break; } // 违规扣分-5分上限 score - Math.min(5, params.violations); // 僵尸 Props 扣分 score - Math.min(5, params.zombiePropCount * 2); return Math.max(0, Math.min(100, score));}/**使用趋势计算*/private calcTrend(usages: any[],componentName: string): growing | stable | declining | new | dead {if (usages.length 0) return dead;const threeMonthsAgo Date.now() - 90 * 24 * 60 * 60 * 1000; const sixMonthsAgo Date.now() - 180 * 24 * 60 * 60 * 1000; const recent usages.filter(u u.date threeMonthsAgo).length; const older usages.filter( u u.date sixMonthsAgo u.date threeMonthsAgo ).length; if (older 0 recent 0) return new; if (recent older * 1.2) return growing; if (recent older * 0.8) return declining; return stable;}private getRecommendation(score: number,usageCount: number,trend: string): ComponentHealth[recommendation] {if (usageCount 0) return remove;if (score 30) return deprecate;if (score 50) return refactor;if (score 70) return monitor;return keep;}private getLastUsedDate(usages: any[]): string {if (usages.length 0) return 从未使用;const latest Math.max(...usages.map(u u.date));return new Date(latest).toISOString().split(T)[0];}private async scanAllProjects(roots: string[]): Promiseany[] {// 扫描所有项目的代码文件提取组件使用记录return [];}private async loadComponentDefinitions(): PromiseRecordstring, any {// 加载组件库的组件定义文件return {};}}/**生成 Markdown 格式的健康报告*/function generateMarkdownReport(healths: ComponentHealth[]): string {const total healths.length;const healthy healths.filter(h h.recommendation keep).length;const atRisk healths.filter(h [monitor, refactor].includes(h.recommendation)).length;const deprecated healths.filter(h [deprecate, remove].includes(h.recommendation)).length;let report # 设计系统健康报告\n\n;report - 总组件数: ${total}\n;report - 健康: ${healthy} | 关注: ${atRisk} | 危险: ${deprecated}\n\n;report ## 危险组件建议弃用或删除\n\n;report | 组件 | 使用次数 | 健康分 | 建议 |\n;report |------|---------|--------|------|\n;for (const h of healths.filter(h h.recommendation deprecate || h.recommendation remove)) {report | ${h.componentName} | ${h.usageCount} | ${h.healthScore} | ${h.recommendation} |\n;}report \n## 僵尸 Props定义了但从未使用的 Props\n\n;for (const h of healths.filter(h h.zombieProps.length 0)) {report ### ${h.componentName}\n;for (const prop of h.zombieProps) {report - \${prop}\n;}report \n;}return report;}## 四、健康报告的时效性与可信度 **代码扫描的覆盖率**。如果只扫描 src/ 目录遗漏了测试文件、Storybook Stories 等间接使用场景报告的使用次数会低估。建议扫描范围包括.tsx、.jsx、.ts 文件中所有 JSX 标签和 createElement 调用。 **使用频率不反映重要性**。一个只在首页用了一次的关键 CTA 按钮组件比一个在 50 个后台页面使用的普通表单字段更重要。健康分需要加入使用位置的权重——首页使用权重高于设置页。 **Git 历史提供趋势数据**。仅扫描当前代码只能得到现状结合 Git 历史可以分析过去半年的使用趋势——这是健康报告中trend字段的价值来源。 ## 五、总结 设计系统健康报告将组件库的维护从凭感觉变成看数据 1. **使用矩阵**——每个组件被多少个页面/模块使用 2. **Props 分析**——哪些 Props 是僵尸属性定义但从未使用 3. **趋势判断**——使用量在增长还是下降 4. **操作建议**——删除 / 弃用 / 重构 / 监控 / 保持 这份报告应该**每周自动生成**发布到团队 Slack 频道或维护者 Dashboard 中。不是为了让谁去读而是当某个组件的健康分持续下降时自动触发是否需要重构的讨论。

相关新闻

Xplique与TensorFlow/PyTorch无缝集成教程:5分钟上手模型解释

Xplique与TensorFlow/PyTorch无缝集成教程:5分钟上手模型解释

Xplique与TensorFlow/PyTorch无缝集成教程:5分钟上手模型解释 【免费下载链接】xplique 👋 Xplique is a Neural Networks Explainability Toolbox 项目地址: https://gitcode.com/gh_mirrors/xp/xplique Xplique是一款功能强大的神经网络可解释性…

2026/11/19 20:41:42 阅读更多 →
基于MFC和WinSock的简易聊天室程序(附完整源码)

基于MFC和WinSock的简易聊天室程序(附完整源码)

本文使用Windows C网络编程和多线程编程实现一个简单的聊天室程序。该程序由服务器端和客户端两部分组成。服务器端负责客户端的上线、离线,以及转发各个客户端发来的消息。客户端向服务器发送信息,从服务器接收信息,以及显示信息到客户端界面…

2026/11/18 21:41:53 阅读更多 →
如何在Windows上优雅地管理Android应用?APK Installer场景化使用指南

如何在Windows上优雅地管理Android应用?APK Installer场景化使用指南

如何在Windows上优雅地管理Android应用?APK Installer场景化使用指南 【免费下载链接】APK-Installer An Android Application Installer for Windows 项目地址: https://gitcode.com/GitHub_Trending/ap/APK-Installer 你是否经常需要在Windows电脑上测试An…

2026/11/19 2:13:33 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/19 21:38:27 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/19 21:38:49 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/19 21:39:09 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/19 21:36:50 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/19 21:37:45 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/19 21:36:20 阅读更多 →

日新闻

周新闻

月新闻