Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update codegen to add subgraph source to watcher readme #514

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Steps:

This will create a folder containing the generated code at the path provided in config. Follow the steps in [Run Generated Watcher](#run-generated-watcher) to setup and run the generated watcher.

* Update generated watcher's `package.json` with desired `version`, `description`, `repository` URL, etc.

* Update generated watcher's config (`environments/local.toml`) as required

## Development

* `lint`
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any, overW
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'README.md'))
: process.stdout;
exportReadme(path.basename(outputDir), config.port, outStream);
exportReadme(path.basename(outputDir), config, outStream);

outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'LICENSE'))
Expand Down
17 changes: 15 additions & 2 deletions packages/codegen/src/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ const TEMPLATE_FILE = './templates/readme-template.handlebars';
* @param port Watcher server port.
* @param outStream A writable output stream to write the README.md file to.
*/
export function exportReadme (folderName: string, port: number, outStream: Writable): void {
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
port,
subgraphRepoName
});
outStream.write(readmeString);
}
7 changes: 7 additions & 0 deletions packages/codegen/src/templates/readme-template.handlebars
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# {{folderName}}

{{#if (subgraphPath)}}
## Source

<!-- TODO: Update with publised subgraph release version -->
* Subgraph: [{{subgraphRepoName}} v0.1.0](https://github.com/cerc-io/{{subgraphRepoName}}/releases/tag/v0.1.0)

{{/if}}
## Setup

* Run the following command to install required packages:
Expand Down
1 change: 1 addition & 0 deletions packages/util/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ const registerWatcherConfigMetrics = async ({ server, upstream, jobQueue }: Conf

watcherConfigMetric.set({ category: 'jobqueue', field: 'num_events_in_batch' }, Number(jobQueue.eventsInBatch));
watcherConfigMetric.set({ category: 'jobqueue', field: 'block_delay_seconds' }, (Number(jobQueue.blockDelayInMilliSecs) || 0) / 1000);
watcherConfigMetric.set({ category: 'jobqueue', field: 'block_processing_offset' }, Number(jobQueue.blockProcessingOffset) ?? 0);
watcherConfigMetric.set({ category: 'jobqueue', field: 'use_block_ranges' }, Number(jobQueue.useBlockRanges));
watcherConfigMetric.set({ category: 'jobqueue', field: 'historical_logs_block_range' }, Number(jobQueue.historicalLogsBlockRange));
watcherConfigMetric.set({ category: 'jobqueue', field: 'historical_max_fetch_ahead' }, Number(jobQueue.historicalMaxFetchAhead));
Expand Down
Loading