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: add new convert command to CLI #188

Merged
merged 48 commits into from
Mar 14, 2022

Conversation

peter-rr
Copy link
Member

@peter-rr peter-rr commented Jan 20, 2022

Description

  • First proposal to implement asyncapi convert command.

Related issue(s)

@peter-rr peter-rr changed the title Add convert command feat: add new convert command to CLI Jan 20, 2022
Copy link
Member

@fmvilas fmvilas left a comment

Choose a reason for hiding this comment

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

This is looking great, Peter! 🙌

Left a few comments where you can improve the code. If I'm not mistaken, this should already work if you try in your machine 🎉

src/commands/convert.ts Outdated Show resolved Hide resolved
src/commands/convert.ts Outdated Show resolved Hide resolved
src/commands/convert.ts Outdated Show resolved Hide resolved
src/commands/convert.ts Outdated Show resolved Hide resolved
src/commands/convert.ts Outdated Show resolved Hide resolved
peter-rr and others added 6 commits January 25, 2022 20:20
Adding `flags` when parsing `Convert` class to avoid using `Convert.flags` in the rest of the file.

Co-authored-by: Fran Méndez <fmvilas@gmail.com>
Using an object as 3rd argument for `convert()`

Co-authored-by: Fran Méndez <fmvilas@gmail.com>
Removing `Convert.x.x` notation

Co-authored-by: Fran Méndez <fmvilas@gmail.com>
Removing one more `Convert.x.x`

Co-authored-by: Fran Méndez <fmvilas@gmail.com>
Printing the content of `convertedFile` properly

Co-authored-by: Fran Méndez <fmvilas@gmail.com>
@peter-rr peter-rr requested a review from fmvilas January 25, 2022 21:49
@peter-rr
Copy link
Member Author

@fmvilas All requested changes applied and seem to be working fine 👍 I think we're almost ready to start testing the convert command with real asyncapi files 🚀

@peter-rr
Copy link
Member Author

peter-rr commented Feb 3, 2022

@Souvikns I wonder if you have any clue about an error I'm getting when passing the -h flag. The info displayed by the command when the -h flag is passed is correct, but an unexpected Error: EEXIT: 0 is shown at the bottom:

image

However, when the --help flag is passed, that error is not shown and everything is displayed correctly.

In order to solve this issue I've been trying to import the flags from @oclif/core as you mentioned in this fix, but then I'm getting this error plugin when executing the command:

image

Do you know if there is something missing or that I'm not taking into consideration? Thank you!! :)

@peter-rr
Copy link
Member Author

peter-rr commented Feb 3, 2022

@magicmatatjahu @fmvilas I've been testing the --id flag and I didn't get any successful result for none of the different spec file versions:

  • For 2.x versions: The conversion is successful but the --id flag applied doesn't have any effect on the converted file.
  • For 1.x versions: The conversion failed since the following error is thrown: Error: Version 1.2.0 is not supported. I guess this is related to the converter 🤔, not to the flag itself.

So, my questions about this flag:

  • Am I missing something at this flag's implementation? Or am I not considering the right use cases?
  • Does it make sense to keep using this flag? Or should we consider to remove it from convert command.

What do you think, guys?

@Souvikns
Copy link
Member

Souvikns commented Feb 4, 2022

@peter-rr can you confirm where you are seeing this error i.e. in your development environment or production.
I checked your branch and it is working as expected.

Now there is an issue in production where we are getting a warning, the CLI works fine but still throws a warning. You can see #192 for full details. We thought #201 would fix the issue but that is not the case currently I have been working on #203 to migrate oclif to the latest version.

@peter-rr
Copy link
Member Author

peter-rr commented Feb 4, 2022

@Souvikns Yeap, I see both errors in my development environment updated with the latest changes from production. Maybe I'm missing some package or plugin needed, not sure 🤔

I checked your branch and it is working as expected.

Do you mean you didn't get any of those errors when running the command on my branch?

We thought #201 would fix the issue but that is not the case currently I have been working on #203 to migrate oclif to the latest version.

Then I think I should wait until #203 is merged so I can test my branch with the latest oclif version and check if those errors still persist. I'll let you know :)

@Souvikns
Copy link
Member

Souvikns commented Feb 5, 2022

Do you mean you didn't get any of those errors when running the command on my branch?

Yeah, I opened your PR in my local setup. Do an npm install and see if it fixes the issue. Do let me know if it doesn't

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

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

Awesome, but I have some insight :)

src/commands/convert.ts Outdated Show resolved Hide resolved
@peter-rr
Copy link
Member Author

peter-rr commented Mar 4, 2022

Now I see you have already created a .d.ts file but you have to change the tsconfig.json file. Just add your global.d.ts file inside include array

Still getting the same errors after applying that change. I guess there is something I'm doing wrong or not taking into account 🤔

@@ -0,0 +1,2 @@
declare module '@asyncapi/converter';
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
declare module '@asyncapi/converter';
declare module '@asyncapi/converter' {
export async function convert(spec: string, targetVersion: string, options: any): Promise<any>
}

@peter-rr try writing the module as per your needs, I am just giving an example for convert do this for @asyncapi/spec as well.

You can take some inspiration from https://github.com/asyncapi/server-api/blob/master/src/server-api.d.ts

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

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

Please propagate my changes. There's problem with ts-node and how exactly it reads the custom typings from external modules. We should move to the Jest and then it will be easy to handle by custom jest transpiler. It's not that important if we have defined types globally or skip them, let's not make our job harder because types are not important here as we know how the package works underneath anyway (and its API).

Propagate changes and then fix tests, because all fail.

src/commands/convert.ts Show resolved Hide resolved
src/commands/convert.ts Show resolved Hide resolved
Fix problem with '@asyncapi/converter' external module

Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
@sonarcloud
Copy link

sonarcloud bot commented Mar 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

peter-rr and others added 2 commits March 7, 2022 21:51
Fix problem with '@asyncapi/specs' external module

Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
@peter-rr
Copy link
Member Author

peter-rr commented Mar 7, 2022

Please propagate my changes. There's problem with ts-node and how exactly it reads the custom typings from external modules.

Great :) Problems related to external modules are solved now and I'm trying to fix all the current failing tests. They are only 4 at this moment 💪

src/commands/convert.ts Outdated Show resolved Hide resolved
Getting 'Command' class from 'base.ts' and not from '@oclif/core'

Co-authored-by: souvik <souvikde.ns@gmail.com>
@peter-rr
Copy link
Member Author

peter-rr commented Mar 9, 2022

@Souvikns @magicmatatjahu
All tests passing now 🎉 Let me know if anything missing or could be improved :)

@sonarcloud
Copy link

sonarcloud bot commented Mar 11, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@Souvikns Souvikns left a comment

Choose a reason for hiding this comment

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

Wow 🤩 looks good, wait for @magicmatatjahu's approval then we can merge this.

Copy link
Member

@fmvilas fmvilas left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

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

Thanks @peter-rr for contribution! LGTM! 🚀

@magicmatatjahu
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 61f8da7 into asyncapi:master Mar 14, 2022
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@fmvilas fmvilas mentioned this pull request Apr 29, 2022
@peter-rr peter-rr deleted the add-convert-command branch July 20, 2022 11:22
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.

5 participants