34 lines
1.2 KiB
JavaScript
34 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')
|
|
|
|
// collect all non-store user-ui code
|
|
const consumerFiles = 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/'))
|
|
|
|
const consumerCode = consumerFiles.map((f) => fs.readFileSync(path.join(ROOT, f), 'utf8')).join('\n')
|
|
|
|
for (const f of storeFiles) {
|
|
const code = fs.readFileSync(path.join(ROOT, f), 'utf8')
|
|
// keys inside the create<...>((set) => ({ ... })) object: "name:" at 2-space indent
|
|
const keys = [...code.matchAll(/^ {2}(\w+):/gm)].map((m) => m[1])
|
|
const dead = []
|
|
for (const k of new Set(keys)) {
|
|
const re = new RegExp(`\\.${k}\\b`)
|
|
if (!re.test(consumerCode)) dead.push(k)
|
|
}
|
|
console.log(path.basename(f), '→ unused actions/state:', dead.length ? dead.join(', ') : 'none')
|
|
}
|