Add required codegen template

This commit is contained in:
Prathamesh Musale 2024-10-14 11:33:36 +05:30
parent 52309ef72b
commit eb46645a70
4 changed files with 54 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import { ConnectionOptions, Repository } from 'typeorm';
import debug from 'debug';
import { DEFAULT_CONFIG_PATH, JSONbigNative, DatabaseInterface, Config, EventInterface } from '@cerc-io/util';
import { BaseCmd } from './base';
const log = debug('vulcanize:backfill-events-data');

View File

@ -0,0 +1,21 @@
//
// Copyright 2024 Vulcanize, Inc.
//
import fs from 'fs';
import path from 'path';
import Handlebars from 'handlebars';
import { Writable } from 'stream';
const TEMPLATE_FILE = './templates/backfill-events-data-template.handlebars';
/**
* Writes the backfill-events-data file generated from a template to a stream.
* @param outStream A writable output stream to write the backfill-events-data file to.
*/
export function exportBackfillEventsData (outStream: Writable): void {
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
const content = template({});
outStream.write(content);
}

View File

@ -40,6 +40,7 @@ import { exportIndexBlock } from './index-block';
import { exportSubscriber } from './subscriber';
import { exportReset } from './reset';
import { filterInheritedContractNodes, writeFileToStream } from './utils/helpers';
import { exportBackfillEventsData } from './backfill-events-data';
const main = async (): Promise<void> => {
const argv = await yargs(hideBin(process.argv))
@ -389,6 +390,11 @@ function generateWatcher (visitor: Visitor, contracts: any[], configFile: string
: process.stdout;
exportIndexBlock(outStream);
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/cli/backfill-events-data.ts'))
: process.stdout;
exportBackfillEventsData(outStream);
if (config.subgraphPath) {
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/entity/Subscriber.ts'))

View File

@ -0,0 +1,26 @@
//
// Copyright 2024 Vulcanize, Inc.
//
import 'reflect-metadata';
import debug from 'debug';
import { BackfillEventsDataCmd } from '@cerc-io/cli';
import { Database } from '../database';
import { Event } from '../entity/Event';
const log = debug('vulcanize:backfill-events-data');
const main = async (): Promise<void> => {
const backFillCmd = new BackfillEventsDataCmd();
await backFillCmd.init(Database);
await backFillCmd.exec(Event);
};
main().catch(err => {
log(err);
}).finally(() => {
process.exit(0);
});