// Which backend commands does the phone never call? The remaining feature // surface, by fact rather than by memory. A command counts as used when its // api.js wrapper is referenced from src/mobile or the shared modules the // phone imports, or when it is invoked by name there. const fs = require('fs'); const path = require('path'); const root = 'F:/Coding/SoulStream/'; const read = (p) => fs.readFileSync(root + p, 'utf8'); const api = read('src/lib/api.js'); const fnByCmd = {}; for (const m of api.matchAll(/export const (\w+) = [\s\S]*?invoke\(\s*"([a-z_:|]+)"/g)) if (!fnByCmd[m[2]]) fnByCmd[m[2]] = m[1]; for (const m of api.matchAll(/export (?:async )?function (\w+)\b[\s\S]*?invoke\(\s*"([a-z_:|]+)"/g)) if (!fnByCmd[m[2]]) fnByCmd[m[2]] = m[1]; const walk = (d) => fs.readdirSync(root + d, { withFileTypes: true }).flatMap((e) => e.isDirectory() ? walk(d + '/' + e.name) : [d + '/' + e.name]); const phone = [...walk('src/mobile'), 'src/lib/sources.js', 'src/lib/catalogMatch.js', 'src/lib/events.js', 'src/lib/localReleaseType.js', 'src/lib/editions.js'] .filter((p) => fs.existsSync(root + p)).map(read).join('\n'); const cmds = new Set(); for (const f of fs.readdirSync(root + 'src-tauri/src').filter((x) => x.endsWith('.rs'))) { const s = read('src-tauri/src/' + f); for (const m of s.matchAll(/#\[tauri::command\][^\n]*\n(?:[^\n]*\n)?\s*(?:pub\s+)?(?:async\s+)?fn\s+(\w+)/g)) cmds.add(m[1]); } const used = []; const unused = []; for (const c of [...cmds].sort()) { const fn = fnByCmd[c]; const hit = (fn && new RegExp('\\b' + fn + '\\b').test(phone)) || new RegExp('"' + c + '"').test(phone); (hit ? used : unused).push(c + (fn ? '' : ' (no api wrapper)')); } console.log(cmds.size + ' commands: ' + used.length + ' called from the phone, ' + unused.length + ' never'); console.log('--- never called from the phone ---'); console.log(unused.join('\n'));