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

48 lines
2 KiB
JavaScript

const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
const ROOT = '/Users/mohammedshafiuddin/WebDev/freshyo'
const APP = 'apps/user-ui'
// all user-ui source files
const files = execSync(
`find ${APP} -type f \\( -name '*.ts' -o -name '*.tsx' \\) -not -path '*/node_modules/*' -not -path '*/dist/*' -not -path '*/.expo/*' -not -path '*/.turbo/*'`,
{ cwd: ROOT }
).toString().trim().split('\n')
// all ts/tsx content across the whole repo that could import these (user-ui + repo scripts)
const scannerFiles = execSync(
`find apps/user-ui scripts packages/migrator -type f \\( -name '*.ts' -o -name '*.tsx' -o -name '*.js' \\) -not -path '*/node_modules/*' -not -path '*/dist/*' -not -path '*/.expo/*' -not -path '*/.turbo/*'`,
{ cwd: ROOT }
).toString().trim().split('\n')
const contents = new Map()
for (const f of scannerFiles) {
try { contents.set(f, fs.readFileSync(path.join(ROOT, f), 'utf8')) } catch {}
}
// route files are entry points (expo-router) — exclude from "never imported" check
const isRoute = (f) => f.startsWith(`${APP}/app/`) && !f.includes('+api')
const isConfig = (f) => /metro\.config|eslint\.config|tsconfig|expo-env/.test(f)
const neverImported = []
for (const f of files) {
if (isRoute(f) || isConfig(f)) continue
const base = path.basename(f).replace(/\.(ts|tsx)$/, '')
// special web variants
const candidates = [base]
if (base.includes('.')) candidates.push(base) // useColorScheme.web
const baseNoPlatform = base.replace(/\.web$/, '')
const re = new RegExp(`from ['"][^'"]*${baseNoPlatform.replace(/\./g, '\\.')}['"]|require\\(['"][^'"]*${baseNoPlatform.replace(/\./g, '\\.')}['"]\\)`)
const importers = []
for (const [of, c] of contents) {
if (of === f) continue
if (re.test(c)) importers.push(of)
}
if (importers.length === 0) neverImported.push(f)
}
console.log('=== FILES NEVER IMPORTED (excluding expo-router entry points) ===')
neverImported.forEach((f) => console.log(f))
console.log('count:', neverImported.length)