bms-pack-cli/src/commands/add-table.ts
2025-07-10 07:03:18 +10:00

26 lines
766 B
TypeScript

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',
});
};