Implement scaffolding of runner
This commit is contained in:
@@ -10,15 +10,13 @@ const PARSERS: Record<string, Constructor<BaseTransactionParser<ParserConfig>>>
|
||||
"pl.ing": PlIng
|
||||
};
|
||||
|
||||
export async function parseTransaction(parserName: string, config: ProfileConfig, data: string[]): Promise<Transaction|undefined> {
|
||||
const Parser = PARSERS[parserName];
|
||||
export function createParser(config: ProfileConfig): BaseTransactionParser<ParserConfig> {
|
||||
const Parser = PARSERS[config.parser];
|
||||
|
||||
if (!Parser) {
|
||||
throw new Error(`Unknown parser: ${parserName}`);
|
||||
throw new Error(`Unknown parser: ${config.parser}`);
|
||||
}
|
||||
|
||||
const parser = new Parser(parserName);
|
||||
|
||||
return parser.parseTransaction(config, data);
|
||||
return new Parser(config.parser);
|
||||
}
|
||||
|
||||
|
||||
18
src/runner/index.ts
Normal file
18
src/runner/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { openCsv } from "@/csv";
|
||||
import { createParser } from "@/parser";
|
||||
import { Config } from "@/types/config";
|
||||
|
||||
export function loadTransactions(file: string, profile: string, config: Config) {
|
||||
const profileConfig = config.profiles[profile];
|
||||
|
||||
if (!profileConfig) {
|
||||
throw new Error(`Unknown profile: ${profile}`);
|
||||
}
|
||||
|
||||
const parser = createParser(profileConfig);
|
||||
|
||||
openCsv(file).on('data', async data => {
|
||||
const transaction = await parser.parseTransaction(profileConfig, data);
|
||||
console.log(transaction);
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
export type ProfileConfig = {
|
||||
config?: object;
|
||||
parser: string;
|
||||
config?: ParserConfig;
|
||||
};
|
||||
|
||||
export type ParserConfig = {
|
||||
|
||||
};
|
||||
|
||||
export type Config = {
|
||||
profiles: Record<string, ProfileConfig>;
|
||||
};
|
||||
Reference in New Issue
Block a user