36 lines
1.3 KiB
JavaScript
36 lines
1.3 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 code = fs.readFileSync(path.join(ROOT, f), 'utf8')
|
|
const keys = [...new Set([...code.matchAll(/^ {2}(\w+):/gm)].map((m) => m[1]))]
|
|
const dead = []
|
|
for (const k of keys) {
|
|
const re = new RegExp(`\\b${k}\\b`, 'g')
|
|
const ownCount = (code.match(re) || []).length // def + internal uses
|
|
let outside = 0
|
|
for (const of of otherFiles) {
|
|
outside += (fs.readFileSync(path.join(ROOT, of), 'utf8').match(re) || []).length
|
|
}
|
|
// ownCount === 1 means only the definition line; outside === 0 means nobody else
|
|
if (ownCount <= 1 && outside === 0) dead.push(k)
|
|
}
|
|
console.log(path.basename(f), '→ TRULY unused:', dead.length ? dead.join(', ') : 'none')
|
|
}
|