watcher-ts/packages/codegen/src
2024-10-14 12:25:49 +05:30
..
assets Log GQL requests in watcher (#517) 2024-06-06 16:54:49 +05:30
data/entities Support topics filtering in getLogs ETH RPC API (#537) 2024-09-18 15:37:13 +05:30
templates Decrement package version (#539) 2024-10-14 12:25:49 +05:30
types/common Generate GQL client (#259) 2021-10-04 11:04:06 +05:30
utils Update subgraph watcher demo readme (#480) 2023-11-24 11:13:40 +05:30
artifacts.ts Add flag in codegen to ignore errors for unhandled types (#350) 2023-04-06 15:24:11 +05:30
backfill-events-data.ts Add a CLI to backfill watcher event data (#538) 2024-10-14 12:07:56 +05:30
checkpoint.ts Accommodate CLI refactoring changes to codegen (#261) 2022-11-25 11:31:20 +05:30
client.ts Fix codegen for creating subgraph watcher for Sushiswap (#432) 2023-10-23 09:23:20 +05:30
config.ts Gracefully shutdown server (#265) 2022-11-28 12:01:28 +05:30
database.ts Fix codegen for creating subgraph watcher for Sushiswap (#432) 2023-10-23 09:23:20 +05:30
entity.ts Mark entities as removed on store remove host API call (#484) 2023-11-21 16:00:26 +05:30
export-state.ts Accommodate CLI refactoring changes to codegen (#261) 2022-11-25 11:31:20 +05:30
fill.ts Gracefully shutdown server (#265) 2022-11-28 12:01:28 +05:30
generate-code.ts Add a CLI to backfill watcher event data (#538) 2024-10-14 12:07:56 +05:30
hooks.ts Generate IPLD blocks table and related GQL API (#260) 2021-12-28 16:08:04 +05:30
import-state.ts Accommodate CLI refactoring changes to codegen (#261) 2022-11-25 11:31:20 +05:30
index-block.ts Update codegen with changes implemented in mobymask watcher (#148) 2022-07-22 13:17:56 +05:30
indexer.ts Fix codegen for creating subgraph watcher for Sushiswap (#432) 2023-10-23 09:23:20 +05:30
inspect-cid.ts Accommodate CLI refactoring changes to codegen (#261) 2022-11-25 11:31:20 +05:30
job-runner.ts Gracefully shutdown server (#265) 2022-11-28 12:01:28 +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 Gracefully shutdown server (#265) 2022-11-28 12:01:28 +05:30
readme.ts Update codegen to add subgraph source to watcher readme (#514) 2024-06-11 14:42:54 +05:30
reset.ts Accommodate CLI refactoring changes to codegen (#261) 2022-11-25 11:31:20 +05:30
resolvers.ts Fix generated watcher GQL query name and add _change_block filter (#471) 2023-11-15 10:14:14 +05:30
schema.ts Handle object and list filters on nested GQL selections and update codegen (#532) 2024-08-05 16:32:40 +05:30
server.ts Gracefully shutdown server (#265) 2022-11-28 12:01:28 +05:30
subscriber.ts Add a table for entites in frothy region for subgraph watchers (#231) 2022-11-16 17:12:54 +05:30
tsconfig.ts Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
types.ts Handle subgraph entities field name conflicts and enum types in codegen (#86) 2021-12-28 16:08:05 +05:30
visitor.ts Load schema file path from subgraph config (#458) 2023-11-09 12:17:09 +05:30
watch-contract.ts Accommodate CLI refactoring changes to codegen (#261) 2022-11-25 11:31:20 +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 port Watcher server port.
 * @param outStream A writable output stream to write the README.md file to.
 */
export function exportReadme (
  folderName: string,
  config: { port: number, subgraphPath?: string },
  outStream: Writable
): void {
  const { port, subgraphPath } = config;
  const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
  const template = Handlebars.compile(templateString);
  let subgraphRepoName;

  if (subgraphPath) {
    const subgraphRepoDir = path.dirname(subgraphPath);
    subgraphRepoName = path.basename(subgraphRepoDir);
  }

  const readmeString = template({
    folderName,
    port,
    subgraphRepoName
  });
  outStream.write(readmeString);
}