Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo4815162342 committed Nov 28, 2024
1 parent 44f654a commit 143d95b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 47 deletions.
42 changes: 6 additions & 36 deletions src/utils/instrument-meta-data/generate-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,28 @@ const saveFile = promisify(fs.writeFile);

const OUTPUT_FOLDER = path.resolve(__dirname, 'generated');

// Promise.all([getActualStartDates(), getRawMetaData()])
// .then(([actualStartDates, rawMetaData]) => {
// return Promise.all([
// saveFile(
// path.resolve(OUTPUT_FOLDER, `raw-meta-data-${new Date().toISOString().slice(0, 10)}.json`),
// JSON.stringify(rawMetaData, null, 2)
// ),
// generateMeta(
// rawMetaData.instruments,
// actualStartDates,
// path.resolve(OUTPUT_FOLDER, 'instrument-meta-data.json')
// ),
// generateInstrumentEnum(
// rawMetaData.instruments,
// path.resolve(OUTPUT_FOLDER, 'instrument-enum.ts')
// ),

// ]);
// })
// .then(() => {
// console.log('Done');
// });


async function run() {
const [actualStartDates, rawMetaData] = await Promise.all([getActualStartDates(), getRawMetaData()]);
const [actualStartDates, rawMetaData] = await Promise.all([
getActualStartDates(),
getRawMetaData()
]);
await saveFile(
path.resolve(OUTPUT_FOLDER, `raw-meta-data-${new Date().toISOString().slice(0, 10)}.json`),
JSON.stringify(rawMetaData, null, 2)
);

const metaDataFilePath = path.resolve(OUTPUT_FOLDER, 'instrument-meta-data.json');

await generateMeta(
rawMetaData.instruments,
actualStartDates,
metaDataFilePath
);

await generateInstrumentEnum(
metaDataFilePath,
path.resolve(OUTPUT_FOLDER, 'instrument-enum.ts')
);
await generateMeta(rawMetaData.instruments, actualStartDates, metaDataFilePath);

await generateInstrumentEnum(metaDataFilePath, path.resolve(OUTPUT_FOLDER, 'instrument-enum.ts'));

await generateInstrumentGroupData(
rawMetaData,
path.resolve(OUTPUT_FOLDER, 'instrument-groups.json')
);

console.log('Done');

}

run();
Expand Down
6 changes: 2 additions & 4 deletions src/utils/instrument-meta-data/generate-group-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export function generateInstrumentGroupData(
metadata: MetaDataResponse,
path: string
): Promise<void> {


const currentGroupDataRaw = fs.readFileSync(path, 'utf8');
const currentGroupData = JSON.parse(currentGroupDataRaw) as GroupData[];

Expand Down Expand Up @@ -58,8 +56,8 @@ export function generateInstrumentGroupData(
return {
id: item.id,
instruments: Array.from(new Set(item.instruments))
}
})
};
});

return saveFile(path, JSON.stringify(dedupedGroups, null, 2)).then(() => {
console.log('instrument groups generated!', path);
Expand Down
7 changes: 2 additions & 5 deletions src/utils/instrument-meta-data/generate-instrument-enum.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* eslint-disable no-console */
import fs from 'fs';
import { promisify } from 'util';
import { InstrumentMetaDataMap } from './generate-meta';
const saveFile = promisify(fs.writeFile);

export function generateInstrumentEnum(
fromPath: string,
toPath: string
): Promise<void> {

export function generateInstrumentEnum(fromPath: string, toPath: string): Promise<void> {
const instrumentsmetaData = fs.readFileSync(fromPath, 'utf8');
const instrumentsMetaData = JSON.parse(instrumentsmetaData) as InstrumentMetaDataMap;

Expand Down
3 changes: 1 addition & 2 deletions src/utils/instrument-meta-data/generate-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ const decimalFactorOverride: Record<string, number> = {
lnkusd: 1000
};

type InstrumentMetaDataMap = Record<string, InstrumentMetaData>;
export type InstrumentMetaDataMap = Record<string, InstrumentMetaData>;

export function generateMeta(
instruments: MetaDataResponse['instruments'],
actualStartDates: ActualStartDates,
path: string
): Promise<void> {

const currentValueFromFile = fs.readFileSync(path, 'utf8');
const currentValue = JSON.parse(currentValueFromFile) as InstrumentMetaDataMap;

Expand Down

0 comments on commit 143d95b

Please sign in to comment.