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

Export codegen config in a generated watcher #522

Merged
merged 2 commits into from
Jun 13, 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
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
Loading