aws / aws-pdk

The AWS PDK provides building blocks for common patterns together with development tools to manage and build your projects.
https://aws.github.io/aws-pdk/
Apache License 2.0
379 stars 75 forks source link

[FEATURE] Add custom folder path option for Smithy-generated handlers #860

Open fahadnasir40 opened 5 days ago

fahadnasir40 commented 5 days ago

Describe the feature

Add an option in the Smithy handler trait to define a custom folder path for the generated handers.

Use Case

Current settings generate all handlers inside the src and test folders with a flat hierarchy. Need an option to customize the individual handler path.

Proposed Solution

Add a new optional subdir option to the Smithy handler trait?

Other Information

We may also need to add this option for async handlers.

Acknowledgements

PDK version used

0.23.66

What languages will this feature affect?

Typescript, Java, Python

Environment details (OS name and version, etc.)

Linux, Windows etc

cogwirrel commented 5 days ago

I think the tricky part for typescript will be getting the esbuild command right to bundle all the handlers - I wonder if we'd need to make it more generic so it finds all ts files in the target directory which export a function called handler? :) Not sure exactly the best way to achieve this though - could maybe add a new script to run.ts but it might increase the size of the bundled run.js that ends up in the PDK distributable as that itself would then include esbuild!

fahadnasir40 commented 4 days ago

I think we may need an index file to store the paths of the generated handlers. Is it possible to read handler data from the model/.api.json file? I'm not quite sure how these projects are linked together. If we choose to scan all files in src/**/* directory, we can run a command with a regex and pass the result to the current esbuild command.

cogwirrel commented 2 days ago

We can read the model/.api.json at build time (just not at project synthesis time as users should be able to add an operation and just rebuild rather than having to re-synthesize too).

So yes I think we could have a script/command read model/.api.json to find where all the handlers are and pass that to the esbuild command :) Ideally I think we'll want this as a node.js script which we can then pass the output to esbuild, so it's as platform agnostic as possible :)