freshyo/scripts/dead-code/user-ui-store-precise.js
2026-09-02 23:12:49 +05:30

33 lines
1.2 KiB
JavaScript

const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
const ROOT = process.cwd()
const storeFiles = execSync(
"find apps/user-ui/src/store apps/user-ui/components/stores -type f -name '*.ts'"
)
.toString()
.trim()
.split('\n')
const otherFiles = execSync(
"find apps/user-ui -type f \\( -name '*.ts' -o -name '*.tsx' \\) -not -path '*/node_modules/*' -not -path '*/dist/*' -not -path '*/.expo/*' -not -path '*/.turbo/*'"
)
.toString()
.trim()
.split('\n')
.filter((f) => !f.includes('/store/'))
for (const f of storeFiles) {
const lines = fs.readFileSync(path.join(ROOT, f), 'utf8').split('\n')
const keys = [...new Set(lines.map((l) => (l.match(/^ {2}(\w+):/) || [])[1]).filter(Boolean))]
const dead = []
for (const k of keys) {
const re = new RegExp(`\\b${k}\\b`)
// own-file usage: lines where the key appears but NOT as a "key:" declaration
const internalUse = lines.some((l) => re.test(l) && !l.trimStart().startsWith(k + ':'))
const outside = otherFiles.some((of) => re.test(fs.readFileSync(path.join(ROOT, of), 'utf8')))
if (!internalUse && !outside) dead.push(k)
}
console.log(path.basename(f), '→ DEAD members:', dead.length ? dead.join(', ') : 'none')
}