Skip to content

Commit

Permalink
Export codegen config in a generated watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Jun 13, 2024
1 parent 467c173 commit cfff99e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 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
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

0 comments on commit cfff99e

Please sign in to comment.