Skip to content

Commit

Permalink
Add required codegen template
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Oct 14, 2024
1 parent 52309ef commit eb46645
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/backfill-events-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
21 changes: 21 additions & 0 deletions packages/codegen/src/backfill-events-data.ts
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions packages/codegen/src/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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'))
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit eb46645

Please sign in to comment.