Skip to content

Commit

Permalink
Export codegen config in a generated watcher (#522)
Browse files Browse the repository at this point in the history
* Export codegen config in a generated watcher

* Update instructions with build step
  • Loading branch information
prathamesh0 authored Jun 13, 2024
1 parent 467c173 commit 9c4b066
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Steps:
* Update generated watcher's config (`environments/local.toml`) as required

* Update generated codegen config (`codegen-config.yml`) to remove / replace your system's absolute paths
## Development
* `lint`
Expand Down Expand Up @@ -158,6 +160,12 @@ Steps:
yarn
```
* Run build:
```bash
yarn build
```
* In the config file (`environments/local.toml`):
* Update the state checkpoint settings.
Expand Down
14 changes: 11 additions & 3 deletions packages/codegen/src/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const main = async (): Promise<void> => {
})
.argv;

const config = await getConfig(path.resolve(argv['config-file']));
const configFile = path.resolve(argv['config-file']);
const config = await getConfig(configFile);

// Create an array of flattened contract strings.
const contracts: any[] = [];
Expand Down Expand Up @@ -120,7 +121,7 @@ const main = async (): Promise<void> => {

parseAndVisit(visitor, contracts, config.mode);

generateWatcher(visitor, contracts, config, overwriteExisting);
generateWatcher(visitor, contracts, configFile, config, overwriteExisting);
};

function parseAndVisit (visitor: Visitor, contracts: any[], mode: string) {
Expand Down Expand Up @@ -162,7 +163,7 @@ function parseAndVisit (visitor: Visitor, contracts: any[], mode: string) {
}
}

function generateWatcher (visitor: Visitor, contracts: any[], config: any, overWriteExisting = false) {
function generateWatcher (visitor: Visitor, contracts: any[], configFile: string, config: any, overWriteExisting = false) {
// Prepare directory structure for the watcher.
let outputDir = '';

Expand Down Expand Up @@ -198,6 +199,13 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any, overW

let outStream: Writable;

// Export the codegen config file
const configFileContent = fs.readFileSync(configFile, 'utf8');
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'codegen-config.yml'))
: process.stdout;
outStream.write(configFileContent);

// Export artifacts for the contracts.
contracts.forEach((contract: any) => {
outStream = outputDir
Expand Down
6 changes: 6 additions & 0 deletions packages/codegen/src/templates/readme-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
yarn
```

* Run build:

```bash
yarn build
```

* Create a postgres12 database for the watcher:

```bash
Expand Down

0 comments on commit 9c4b066

Please sign in to comment.