diff --git a/packages/cli/src/backfill-events-data.ts b/packages/cli/src/backfill-events-data.ts index f1120ea2..d7467144 100644 --- a/packages/cli/src/backfill-events-data.ts +++ b/packages/cli/src/backfill-events-data.ts @@ -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'); diff --git a/packages/codegen/src/backfill-events-data.ts b/packages/codegen/src/backfill-events-data.ts new file mode 100644 index 00000000..7da32aa3 --- /dev/null +++ b/packages/codegen/src/backfill-events-data.ts @@ -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); +} diff --git a/packages/codegen/src/generate-code.ts b/packages/codegen/src/generate-code.ts index 1bf675b0..5b0e29d8 100644 --- a/packages/codegen/src/generate-code.ts +++ b/packages/codegen/src/generate-code.ts @@ -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 => { 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')) diff --git a/packages/codegen/src/templates/backfill-events-data-template.handlebars b/packages/codegen/src/templates/backfill-events-data-template.handlebars new file mode 100644 index 00000000..1f3d9963 --- /dev/null +++ b/packages/codegen/src/templates/backfill-events-data-template.handlebars @@ -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 => { + const backFillCmd = new BackfillEventsDataCmd(); + await backFillCmd.init(Database); + + await backFillCmd.exec(Event); +}; + +main().catch(err => { + log(err); +}).finally(() => { + process.exit(0); +});