2021-09-23 11:25:46 +00:00
|
|
|
//
|
|
|
|
// 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.
|
2021-12-23 11:56:03 +00:00
|
|
|
* @param port Watcher server port.
|
2021-09-23 11:25:46 +00:00
|
|
|
* @param outStream A writable output stream to write the README.md file to.
|
|
|
|
*/
|
2024-06-11 09:12:54 +00:00
|
|
|
export function exportReadme (
|
|
|
|
folderName: string,
|
|
|
|
config: { port: number, subgraphPath?: string },
|
|
|
|
outStream: Writable
|
|
|
|
): void {
|
|
|
|
const { port, subgraphPath } = config;
|
2021-09-23 11:25:46 +00:00
|
|
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
|
|
|
const template = Handlebars.compile(templateString);
|
2024-06-11 09:12:54 +00:00
|
|
|
let subgraphRepoName;
|
|
|
|
|
|
|
|
if (subgraphPath) {
|
|
|
|
const subgraphRepoDir = path.dirname(subgraphPath);
|
|
|
|
subgraphRepoName = path.basename(subgraphRepoDir);
|
|
|
|
}
|
|
|
|
|
2021-09-23 11:25:46 +00:00
|
|
|
const readmeString = template({
|
|
|
|
folderName,
|
2024-06-11 09:12:54 +00:00
|
|
|
port,
|
|
|
|
subgraphRepoName
|
2021-09-23 11:25:46 +00:00
|
|
|
});
|
|
|
|
outStream.write(readmeString);
|
|
|
|
}
|