watcher-ts/packages/codegen/src/watch-contract.ts
nikugogoi 168689a7c7
Fix codegen for non subgraph watchers (#120)
* Fix codegen for non subgraph watchers

* Remove graphWatcher.init from generated non subgraph watcher
2022-05-26 18:00:17 +05:30

22 lines
706 B
TypeScript

//
// Copyright 2021 Vulcanize, Inc.
//
import fs from 'fs';
import path from 'path';
import Handlebars from 'handlebars';
import { Writable } from 'stream';
const TEMPLATE_FILE = './templates/watch-contract-template.handlebars';
/**
* Writes the watch-contract file generated from a template to a stream.
* @param outStream A writable output stream to write the watch-contract file to.
*/
export function exportWatchContract (outStream: Writable, subgraphPath: string): void {
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
const events = template({ subgraphPath });
outStream.write(events);
}