Init
This commit is contained in:
commit
28769020ef
13 changed files with 1131 additions and 0 deletions
26
src/commands/add-table.ts
Normal file
26
src/commands/add-table.ts
Normal 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',
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue