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

feat(cli): update TypeScript template to match aws-cdk layout #3179

Closed
wants to merge 9 commits into from

Conversation

blimmer
Copy link
Contributor

@blimmer blimmer commented Oct 7, 2023

Related issue

Fixes #3006

Description

This PR adjusts the output format for CDKTF TypeScript projects created by cdktf init --template typescript to better match CDK. This makes it simpler for new CDKTF users with CDK experience to understand where the files are located.

You can see the current CDK layout here: https://github.com/aws/aws-cdk/tree/06bea3159e137a8e85e362795ef2cf7e219e381c/packages/aws-cdk/lib/init-templates/app/typescript

or, generate a new CDK project for comparison

npx aws-cdk@latest init app --language=typescript

Checklist

  • I have updated the PR title to match CDKTF's style guide
  • I have run the linter on my code locally
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if applicable
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works if applicable
  • New and existing unit tests pass locally with my changes

*.d.ts
bundle
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bundle contains the TS templates, which include invalid TS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is nice because the test setup file is no longer at the root of the directory. It's neatly contained in the test folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CDK uses the test folder, not __tests__.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, the stack is stored in lib and the app is defined in bin, just like CDK.

import { Construct } from "constructs";
import { TerraformStack } from "cdktf";

export class {{basePascal}}Stack extends TerraformStack {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For an app named foo MyStack becomes FooStack, just like CDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating this file to use a TypeScript config vs. JS. I retained all the existing values.

clearMocks: true,
coverageProvider: "v8",
moduleFileExtensions: ["ts", "js", "json", "node"],
setupFilesAfterEnv: ["<rootDir>/test/setup.js"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated from <rootDir>/setup.js

moduleFileExtensions: ["ts", "js", "json", "node"],
setupFilesAfterEnv: ["<rootDir>/test/setup.js"],
testEnvironment: "node",
testMatch: ["**/test/**/*.ts", "**/?(*.)+(spec|test).ts"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated from **/__tests__/**/*.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, just the app is created here. The stack is created in a separate file, as with CDK.


# ignore templates, since they're not valid TypeScript
templates
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that we're using syntax like:

export class {{basePascal}}Stack extends TerraformStack {

We have invalid TS, so eslint blows up.

@blimmer blimmer marked this pull request as ready for review October 8, 2023 00:02
@blimmer blimmer requested a review from a team as a code owner October 8, 2023 00:02
@blimmer blimmer requested review from ansgarm and DanielMSchmidt and removed request for a team October 8, 2023 00:02
@blimmer
Copy link
Contributor Author

blimmer commented Oct 8, 2023

Ah, I need to update the website docs. Taking back to draft.

@blimmer
Copy link
Contributor Author

blimmer commented Oct 21, 2023

I think I'll need to update at least:

  • Unit tests
  • Docs
  • TypeScript examples

to complete this PR. Since that'd be a decent time commitment, @DanielMSchmidt, is this a PR the team would consider merging? If not, I'll save the time and close it. If so, I'm happy to complete it.

@xiehan
Copy link
Member

xiehan commented Nov 15, 2023

Hi @blimmer:

Thank you for the effort you put into this PR! We discussed it as a team and we agreed that while there are a couple of valid arguments for making this change, overall, this is a bigger refactor than we're willing to take on; if we were going to proceed with this, we would also want to make sure that all of our tutorials and example projects outside of this repo get updated to the new format as well so that we're being consistent across-the-board. That additional effort outweighs the benefits of making this change from our perspective.

Again, we do acknowledge your contribution and appreciate the time you spent on this!

@xiehan xiehan closed this Nov 15, 2023
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: match cdk file structure
3 participants