cherry-studio/v2-refactor-temp/tools/data-classify/scripts/check-duplicates.js
fullex 806a294508 feat: add v2-refactor-temp directory for V2 refactoring tools
- Add data-classify tools for data inventory extraction and code generation
  - Include consolidated Chinese documentation (README.md)
  - Update generated file path references

  This temporary directory will be removed after V2 refactor is complete.
2025-11-29 11:55:45 +08:00

79 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
function checkDuplicatesAndChildren() {
const classificationFile = path.join(__dirname, '../data/classification.json')
const classification = JSON.parse(fs.readFileSync(classificationFile, 'utf8'))
// 提取所有preferences项包括children
const allPrefs = []
function extractItems(items, source, category, parentKey = '') {
if (!Array.isArray(items)) return
items.forEach((item) => {
// 处理有children的项目
if (item.children) {
console.log(`发现children项: ${source}/${category}/${item.originalKey}`)
extractItems(item.children, source, category, `${parentKey}${item.originalKey}.`)
return
}
// 处理普通项目
if (item.category === 'preferences' && item.status === 'classified' && item.targetKey) {
allPrefs.push({
source,
category,
originalKey: parentKey + item.originalKey,
targetKey: item.targetKey,
fullPath: `${source}/${category}/${parentKey}${item.originalKey}`
})
}
})
}
// 遍历所有数据源
;['electronStore', 'redux', 'localStorage'].forEach((source) => {
if (classification.classifications[source]) {
Object.keys(classification.classifications[source]).forEach((category) => {
const items = classification.classifications[source][category]
extractItems(items, source, category)
})
}
})
console.log(`\n=== 总共找到 ${allPrefs.length} 个preferences项 ===\n`)
// 检查重复的targetKey
const targetKeyGroups = {}
allPrefs.forEach((pref) => {
if (!targetKeyGroups[pref.targetKey]) {
targetKeyGroups[pref.targetKey] = []
}
targetKeyGroups[pref.targetKey].push(pref)
})
// 显示重复项
const duplicates = Object.keys(targetKeyGroups).filter((key) => targetKeyGroups[key].length > 1)
if (duplicates.length > 0) {
console.log('=== 重复的targetKey ===')
duplicates.forEach((targetKey) => {
console.log(`\n${targetKey}:`)
targetKeyGroups[targetKey].forEach((pref) => {
console.log(` - ${pref.fullPath}`)
})
})
} else {
console.log('✅ 没有发现重复的targetKey')
}
return { allPrefs, duplicates: duplicates.map((key) => targetKeyGroups[key]) }
}
if (require.main === module) {
checkDuplicatesAndChildren()
}
module.exports = checkDuplicatesAndChildren