Files
watcher-ts/packages/codegen/src
prathamesh0 ac74da6ea6 Add a CLI to backfill watcher event data (#538)
* Add a CLI to backfill watcher event data

* Add required codegen template

* Increment package version
2024-10-14 12:07:56 +05:30
..
2024-06-06 16:54:49 +05:30
2021-10-04 11:04:06 +05:30
2022-11-28 12:01:28 +05:30
2022-11-28 12:01:28 +05:30
2022-11-28 12:01:28 +05:30
2022-11-28 12:01:28 +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);
}