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

Add support to Android using Kotlin code generation #53

Merged
merged 26 commits into from
Dec 22, 2023
Merged

Add support to Android using Kotlin code generation #53

merged 26 commits into from
Dec 22, 2023

Conversation

husseinala
Copy link
Contributor

@husseinala husseinala commented Dec 5, 2023

Resolves #1

Description

Where I work, we've been using Arkana on our iOS projects and we're big fans of the project, so would like to adopt it for our Android projects too, which is why we thought it would be helpful to kick off the process of adding Kotlin support.

This PR adds a KotlinCodeGenerator and modifies the execution entry point to determine which generator to run based on the specified --lang argument flag.

The following changes have also been made:

Arkana Arguments

  • Added a --lang flag used to specify the generator to use for e.g. kotlin. Defaults to swift.

Arkana YAML config

  • Added a kotlin_package_name option which is used by the Kotlin generator to determine the package name of the generated module. Defaults to com.arkanakeys.
  • Added a kotlin_sources_path option which is used by the Kotlin generator to determine the path for generated Kotlin classes. Defaults to src/main/kotlin.
  • Added a should_generate_gradle_build_file option which is useful if your result_path is a path of an existing module and you would like to avoid generating a new build.gradle file.

Generated module structure

Screenshot 2023-12-05 at 11 14 59

Generated sources

{namespace}Environment.kt

Contains interface declaration for the environment-specific keys.
Screenshot 2023-12-05 at 11 17 53

{namespace}.kt

Contains the Keys object:

Screenshot 2023-12-05 at 11 19 58

@rogerluan
Copy link
Owner

rogerluan commented Dec 5, 2023

Thank you soooo much for this PR, @husseinala !

I'm very excited to review it, test it and provide feedback! I'll only be able to take a look at this by the end of the week though, probably over the weekend!

I know there are many people interested in this, so I'll tag them here so they can follow the evolution of this new feature/PR as it happens and can also provide valuable feedback and maybe even help us test a bit in diverse projects/work environments 😊

@JARMourato @humblerookie @Shafichariri @houmie @mrea1 @yuukiw00w @AF-cgi @mrea1 @marceltex 🙇

Thanks a lot again @husseinala, and congrats on your first contribution here! ❤️

PS: Great PR description, thanks for the thorough explanation! 🤩

@husseinala
Copy link
Contributor Author

Thank you @rogerluan! Looking forward to the feedback from everyone 😊

Copy link
Sponsor Collaborator

@JARMourato JARMourato left a comment

Choose a reason for hiding this comment

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

Its missing the README adjustments 😉

lib/arkana.rb Outdated Show resolved Hide resolved
lib/arkana/helpers/kotlin_template_helper.rb Outdated Show resolved Hide resolved
lib/arkana/helpers/kotlin_template_helper.rb Outdated Show resolved Hide resolved
Copy link
Owner

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

Note

Partial review for now!

I left some minor comments so far, as I haven't reviewed the core logic of the PR. Some things I noticed (also piggy backing on some of the comments that were already left above by other reviewers):

  1. We should be updating the README as well to reflect all the changes (e.g. remove the "coming soon" section, adding proper usage documentation for the new kotlin features, perhaps add some more instructions on how to adequate your project for kotlin generation, etc).
  2. Kotlin unit tests are super valuable as they guarantee the actual encoding/decoding is working as expected, and that it doesn't regress in the future :) could you add those?
  3. Do the generated kotlin files pass a standard kotlin linter out-of-the-box? One with a "widely adopted" style guide 😇
  4. Last but not least, could you also implement an e2e test to be run in CI via Rakefile, like we're doing with Swift? These references will be helpful:

Looking forward to continue reviewing this PR when I have some extra time! It's looking promising! 🙌

template.yml Outdated Show resolved Hide resolved
template.yml Outdated Show resolved Hide resolved
template.yml Outdated Show resolved Hide resolved
lib/arkana/templates/kotlin/build.gradle.kts.erb Outdated Show resolved Hide resolved
lib/arkana/templates/kotlin/build.gradle.kts.erb Outdated Show resolved Hide resolved
lib/arkana/models/arguments.rb Outdated Show resolved Hide resolved
lib/arkana/kotlin_code_generator.rb Show resolved Hide resolved
@husseinala
Copy link
Contributor Author

Note

Partial review for now!

I left some minor comments so far, as I haven't reviewed the core logic of the PR. Some things I noticed (also piggy backing on some of the comments that were already left above by other reviewers):

  1. We should be updating the README as well to reflect all the changes (e.g. remove the "coming soon" section, adding proper usage documentation for the new kotlin features, perhaps add some more instructions on how to adequate your project for kotlin generation, etc).

  2. Kotlin unit tests are super valuable as they guarantee the actual encoding/decoding is working as expected, and that it doesn't regress in the future :) could you add those?

  3. Do the generated kotlin files pass a standard kotlin linter out-of-the-box? One with a "widely adopted" style guide 😇

  4. Last but not least, could you also implement an e2e test to be run in CI via Rakefile, like we're doing with Swift? These references will be helpful:

Looking forward to continue reviewing this PR when I have some extra time! It's looking promising! 🙌

Thanks @JARMourato, @marceltex & @rogerluan for taking the time to go through the PR 🙏🏼 , will work on addressing all the raised issues and push all the necessary changes, including making sure all the generated code passes Kotlin's official codeing conventions

Copy link

watermelon-copilot-for-code-review bot commented Dec 19, 2023

Watermelon AI Summary

AI Summary deactivated by husseinala

GitHub PRs

arkana is an open repo and Watermelon will serve it for free.
🍉🫶

@husseinala
Copy link
Contributor Author

Hi @rogerluan, sorry for the delay, I've been a bit busy the last two weeks, but I finally got around to making the requested changes which address the following points:

  1. The readme has been updated to include information about Android/Kotlin support.
  2. Updated the Kotlin code generator to generate Kotlin unit tests when should_generate_gradle_build_file is set to true.
  3. Updated the Rakefile to include a test_kotlin task. This required the addition of a couple of support files which I included inside spec/fixtures/kotlin to be able to run the Kotlin tests outside a normal Android project.
  4. Updated the Kotlin code template to ensure the generated code is in line with the official JetBrains Kotlin code style.

@rogerluan
Copy link
Owner

I made some changes to the Kotlin erb templates to adjust the code style/formatting, more specifically the line breaks 😊 I think they look better this way. Here's a visual diff of the changes if you're curious:

Click here to expand

image image image image

lib/arkana/templates/kotlin/arkana_tests.kt.erb Outdated Show resolved Hide resolved
spec/fixtures/kotlin/build.gradle.kts Outdated Show resolved Hide resolved
spec/fixtures/kotlin/gradlew Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
lib/arkana/templates/kotlin/arkana.kt.erb Show resolved Hide resolved
Copy link
Owner

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

I finished reviewing this PR and addressing all the nitpicks I had in mind 🤓

Solid PR @husseinala you did an awesome work here! Thank you so much!

There are just a couple things left that I asked you to review, whenever you have some time 🙇 and I just left some misc questions too 😊 . Other than that, could you also merge the latest master into this branch, resolving the conflicts? They should be simple (just minor text changes) 🙇

Looking forward to getting this merged! 🚀🚀

README.md Show resolved Hide resolved
@rogerluan rogerluan changed the title Implement Kotlin generator support Add support to Android via Kotlin code generation Dec 22, 2023
@rogerluan rogerluan changed the title Add support to Android via Kotlin code generation Add support to Android using Kotlin code generation Dec 22, 2023
# Conflicts:
#	template.yml
Copy link
Owner

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

I've merged latest master into this branch, this is now good to go!! 🚀

Thanks once again for your contribution @husseinala! ❤️

@husseinala
Copy link
Contributor Author

Yaay 🎉 thank you for taking the time to review and clean up the PR @rogerluan. Really glad I was able to contribute to this project! ❤️

@rogerluan rogerluan merged commit 65965d0 into rogerluan:main Dec 22, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support to Android
5 participants