import { LoadBMSTable } from 'bms-table-loader'; import { configLocation } from '../utils/config'; import { writeFile } from 'fs/promises'; import { join } from 'path'; import { TableCache } from '../utils/types'; import { loadTableCache } from '../utils/loadTableCache'; const tableCacheName = 'tables.json'; const tableCacheLocation = join(configLocation, tableCacheName); export const addTable = async (url: string) => { const table = await LoadBMSTable(url); let existingTableCache = await loadTableCache(); const existingTables: TableCache = { ...existingTableCache, [table.head.name]: { url, data: table, }, }; await writeFile(tableCacheLocation, JSON.stringify(existingTables, null, 2), { encoding: 'utf-8', }); };