const fs = require('fs') const path = require('path') const { execSync } = require('child_process') const ROOT = '/Users/mohammedshafiuddin/WebDev/freshyo' const APP = 'apps/user-ui' 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') const codes = new Map() for (const f of files) codes.set(f, fs.readFileSync(path.join(ROOT, f), 'utf8')) const suspects = [ 'useJWT', 'toaster', 'notif-checker', 'notif-register', 'notif-context', 'useColorScheme', 'useUploadToObjectStore', 'useProductSlotIdentifier', 'getCurrentUserId', 'queryClient', 'string-manipulators', 'AddressForm', 'AddToCartDialog', 'CentralStoreInitializer', 'google-sign-in', 'LocationAttacher', 'FirstUserWrapper', 'FlashDeliveryNote', 'HealthTestWrapper', 'LocationTestWrapper', 'NextOrderGlimpse', 'OrderMenu', 'QuickDeliveryAddressSelector', 'registration-form', 'TabLayoutWrapper', 'TestingPhaseNote', 'UpdateChecker', 'WebViewWrapper', 'CheckoutAddressSelector', 'ComplaintForm', 'ProductDetail', 'ProductCard', 'BackHandler', 'floating-cart-bar', 'cart-page', 'checkout-page', 'PaymentAndOrderComponent', 'SlotSpecificView', 'cart-query-hooks', 'useAuthenticatedRoute', ] for (const name of suspects) { const re = new RegExp(`from ['"][^'"]*/${name}['"]`) const importers = [] for (const [of, c] of codes) { if (re.test(c)) importers.push(of.replace(APP + '/', '')) } console.log(`${name}: ${importers.length === 0 ? '*** NEVER IMPORTED ***' : importers.join(', ')}`) } // store hooks usage console.log('\n=== STORE HOOKS ===') const storeFiles = files.filter((f) => f.includes('/store/')) for (const sf of storeFiles) { const code = codes.get(sf) const m = code.match(/export\s+const\s+(use\w+)/g) || [] const hooks = m.map((x) => x.replace('export const ', '')) for (const h of hooks) { let refs = 0 const filesUsing = [] for (const [of, oc] of codes) { if (of === sf) continue if (new RegExp(`\\b${h}\\b`).test(oc)) { refs++; filesUsing.push(of.replace(APP + '/', '')) } } console.log(`${h} (${path.basename(sf)}): ${refs === 0 ? '*** UNUSED ***' : refs + ' refs'}`) } }