This commit is contained in:
pfych 2025-07-10 07:03:18 +10:00
commit 28769020ef
13 changed files with 1131 additions and 0 deletions

26
src/commands/add-table.ts Normal file
View file

@ -0,0 +1,26 @@
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',
});
};