watcher-ts/packages/codegen/src
prathamesh0 4ddb8c4af6 Auto generating state from indexer methods (#277)
* Generate default derived state for Mapping type variables

* Update IPLDBlock in storage methods instead of using a private class variable

* Default state flag for indexer storage methods

* Helper functions to update state objects

* Add checkpoint flag in Contract table and corresponding changes in existing watchers

* Update codegen docs

* Add examples to generated docs

* Turn default state off by default

* Make state parameter to indexer storage methods default to none

* Add method to get prev. state in indexer
2021-12-28 16:08:04 +05:30
..
data/entities Auto generating state from indexer methods (#277) 2021-12-28 16:08:04 +05:30
templates Auto generating state from indexer methods (#277) 2021-12-28 16:08:04 +05:30
types/common Generate GQL client (#259) 2021-10-04 11:04:06 +05:30
utils Codegen flag for watcher kind and eventsInRange query support (#254) 2021-09-28 10:22:21 +05:30
artifacts.ts Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
checkpoint.ts Ensuring chronological execution of hooks and checkpointing (#264) 2021-12-28 16:08:04 +05:30
client.ts Ensuring chronological execution of hooks and checkpointing (#264) 2021-12-28 16:08:04 +05:30
config.ts Codegen flag for watcher kind and eventsInRange query support (#254) 2021-09-28 10:22:21 +05:30
database.ts Change initial checkpoint hook and hook status entity naming (#269) 2021-12-28 16:08:04 +05:30
entity.ts Change initial checkpoint hook and hook status entity naming (#269) 2021-12-28 16:08:04 +05:30
events.ts Support storage mode for code generator (#251) 2021-09-27 10:13:50 +05:30
fill.ts Support GQL subscriptions, fill and custom hook for indexing on event (#255) 2021-09-29 10:04:09 +05:30
generate-code.ts Ensuring chronological execution of hooks and checkpointing (#264) 2021-12-28 16:08:04 +05:30
hooks.ts Generate IPLD blocks table and related GQL API (#260) 2021-12-28 16:08:04 +05:30
indexer.ts Auto generating state from indexer methods (#277) 2021-12-28 16:08:04 +05:30
job-runner.ts Implement active watcher. (#252) 2021-09-27 15:24:17 +05:30
lint.ts Generate entities from YAML templates and lint support in generated watchers (#253) 2021-09-27 18:03:04 +05:30
package.ts Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
readme.ts Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
resolvers.ts Generate GQL client (#259) 2021-10-04 11:04:06 +05:30
schema.ts Auto generating state from indexer methods (#277) 2021-12-28 16:08:04 +05:30
server.ts Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
tsconfig.ts Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
visitor.ts Auto generating state from indexer methods (#277) 2021-12-28 16:08:04 +05:30
watch-contract.ts Ensuring chronological execution of hooks and checkpointing (#264) 2021-12-28 16:08:04 +05:30

//
// Copyright 2021 Vulcanize, Inc.
//

import fs from 'fs';
import path from 'path';
import Handlebars from 'handlebars';
import { Writable } from 'stream';

const TEMPLATE_FILE = './templates/readme-template.handlebars';

/**
 * Writes the README.md file generated from a template to a stream.
 * @param folderName Watcher folder name to be passed to the template.
 * @param contractName Input contract name given as title of the README.
 * @param outStream A writable output stream to write the README.md file to.
 */
export function exportReadme (folderName: string, contractName: string, outStream: Writable): void {
  const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
  const template = Handlebars.compile(templateString);
  const readmeString = template({
    folderName,
    contractName
  });
  outStream.write(readmeString);
}