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

Template for setting up an emitter #2736

Merged
merged 36 commits into from
Dec 20, 2023

Conversation

timotheeguerin
Copy link
Member

@timotheeguerin timotheeguerin commented Dec 6, 2023

Add a new template for scaffolding an emitter

emitter-ts template setup the following:

  • basic emitter files
  • typescript
  • test with node test runner with basic test and test host setup
  • prettier
  • linting with eslint

Change to the init area

  • Added a new --template cli option to allow selecting the template without a prompt.
  • Refactor to make it easier to test. Note that none of the API is exposed yet so its just for internal use.

Added e2e test for templates

Scafold the template and then run commands like npm install, npm run build, npm run test, etc. to make sure everything is done correctly.

This is quite costly so might be worth separating in a different step

Copy link
Contributor

github-actions bot commented Dec 6, 2023

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2736/

Website: https://tspwebsitepr.z22.web.core.windows.net/prs/2736/

@timotheeguerin timotheeguerin marked this pull request as ready for review December 8, 2023 17:24
@timotheeguerin timotheeguerin changed the title [Wip] Template for setting up an emitter Template for setting up an emitter Dec 8, 2023
@azure-sdk
Copy link
Collaborator

You can try these changes at https://cadlplayground.z22.web.core.windows.net/prs/2736/

Check the website changes at https://tspwebsitepr.z22.web.core.windows.net/prs/2736/

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to get this in. Can we update the doc for getting started with an emitter to reference the steps necessary?

import { EmitContext, emitFile, resolvePath } from "@typespec/compiler";

export async function $onEmit(context: EmitContext) {
if (!context.program.compilerOptions.noEmit) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be worth putting something super simple here with the emitter framework, like just printing out model names or some such?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure I really wanted people to try to use the emitter framework today as there is still a lot of issues with it.

I might take a stab during the holidays at solving all those issues Travis and I got when using it and after I think we could setup the boilperplate for the emitter framework usage.

} from "@typespec/compiler/testing";
import { TestLibrary } from "../src/testing/index.js";

export async function createMyTestHost() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find these names to be a little awkward with "my" in them, could maybe template in the emitter name in place of "my"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be great but I think our template engine right now doesn’t have this capability to change casing. I can do a follow up pr that does

@timotheeguerin timotheeguerin merged commit 9aa5706 into microsoft:main Dec 20, 2023
12 checks passed
@timotheeguerin timotheeguerin deleted the feature/library-init branch December 20, 2023 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants