asyncapi / website

AsyncAPI specification website
https://www.asyncapi.com
Apache License 2.0
527 stars 667 forks source link

Migration of build + workflow scripts to typescript #3187

Open akshatnema opened 2 months ago

akshatnema commented 2 months ago

Description

With the current package.json built for ES modules and packages, as we migrated the website to Next js 14 + Typescript, it has now started affecting the scripts folder like working of meetings workflow, automation of blog creation using npm script, etc. Since, to have uniformity across the website, we decided to migrate the existing Node js scripts to common js modules (in Typescript), enhancing the code maintenance, scalability, and readability for contributors.

Tasks need to be done

This issue comprises multiple tasks, that need to be completed to cover all the scripts in the project. Here is the list:

DhairyaMajmudar commented 2 months ago

Hi @akshatnema, I would like to open a PR for migrating build scripts files into ts

lucky29-git commented 2 months ago

@DhairyaMajmudar I would like to work on this, please inform if you need any help.

akshatnema commented 2 months ago

This idea is currently part of AsyncAPI mentorship program (https://github.com/orgs/asyncapi/discussions/1361) - You have to apply from there itself.

akshatnema commented 1 month ago

Hey Everyone, Here is the proposal submission form for project idea, Migration of build + workflow scripts to typescript. Please answer the questions in the form as well.

Form Link - https://forms.gle/ZjhDcfo55B7HDhUy6

JeelRajodiya commented 2 weeks ago

Project Status

Build Scripts Migration

List of Scripts (from the least dependent(on each other) to the most dependent script)

Build script migration is expected to be finished by: 19th December, 2024

Workflow Script Migration

Unique workflows in the website repo

All Other workflows either are in the .github repo or does not have any javascript code to migrate

Workflow Script Migration is expected to be finished by: 9th January, 2025

Test Scripts Migration (currently not under consideration for the project)

If Considered Test Scripts Migration is expected to be finished by: 20th February, 2025

akshatnema commented 2 weeks ago

@JeelRajodiya Regarding workflow scripts, migrate only those workflows which are not maintained from .github repo. Don't update the workflows which are maintained at .github repository.

Secondly, why there is a need of migrating tests in typescript?

JeelRajodiya commented 2 weeks ago

@JeelRajodiya Regarding workflow scripts, migrate only those workflows which are not maintained from .github repo. Don't update the workflows which are maintained at .github repository.

Sure, I will update the comment.

Secondly, why there is a need of migrating tests in typescript?

Isn't this in the scope of the project?, I have mentioned the test script migration in my proposal so I have included it here as well. Are we considering to migrate them?

akshatnema commented 2 weeks ago

Are we considering to migrate them?

Currently, @vishvamsinh28 is writing tests for the scripts. Let him finish that first. It's not necessary to migrate the tests in TS, if they works even if scripts are in typescript. If during of scripts, tests result out incompatible, we can then think of them to migrate them to typescript, else I don't find any reason to migrate them. WDYT?

JeelRajodiya commented 2 weeks ago

Currently, @vishvamsinh28 is writing tests for the scripts. Let him finish that first.

I was not aware about it. Thanks for informing.

It's not necessary to migrate the tests in TS, if they works even if scripts are in typescript. If during of scripts, tests result out incompatible, we can then think of them to migrate them to typescript, else I don't find any reason to migrate them. WDYT?

Sure, Let's drop the plan of migrating the tests. We can think of migrating them later on if needed.

JeelRajodiya commented 2 weeks ago

@akshatnema What do you think about using tsx instead of ts-node?

While running the .ts files with ts-node, I am having the following issues.

SyntaxError: Cannot use import statement outside a module

image

When I try to just use the require imports, typescript is not detecting the types of imported modules. So I have to use ES imports. To resolve this error, I added "type": "module" in the package.json file. This configuration requires me that in each file we should have ES imports, So I have may need to migrate all of the scripts at the same time.

However after adding the configuration, another error pop-up, please see below.

image

We can resolve this error as well, but It requires me to modify the tsconfig.json file.

On the other hand, when I run the scripts with tsx. We do not have any errors and it does not require me to make any modification in the package.json or tsconfig.json files.

Successful typescript run with tsx image

akshatnema commented 2 weeks ago

SyntaxError: Cannot use import statement outside a module

@JeelRajodiya This is a very generic error, probably you have not setup the package.json with ts-node correctly. This should not happen.

When I try to just use the require imports, typescript is not detecting the types of imported modules. So I have to use ES imports. To resolve this error, I added "type": "module" in the package.json file. This configuration requires me that in each file we should have ES imports, So I have may need to migrate all of the scripts at the same time.

Yeah, that's perfectly fine because logically you should have all files is ts only. And it would be best if you thought in that approach to migrate all the script files.

We can resolve this error as well, but It requires me to modify the tsconfig.json file.

Yeah, feel free to do those changes. You have to make these changes to implement it in better. Just that we are getting some normal configuration issues, we can't simply move from ts-node to tsx.

akshatnema commented 2 weeks ago

@JeelRajodiya Also, during targeting all the above errors (from tsconfig file as well), if we find ourselves in a endless loop to resolve the errors or it is changing the environment for next js inside repo, then we can think to use tsx over here.

JeelRajodiya commented 1 week ago

@akshatnema

I have a question, Which formatter I should use for the scripts? currently I am using default Vscode formatter for javascript/Typescript but it seems to modify the whole file when I format.

Also, I like you inform you that I will be creating a single PR for the script migration

akshatnema commented 1 week ago

There's already prettier configured inside eslint configuration. You should follow that only. Yeah it will change most of the formatting, as it will follow the rules mentioned there. Also, make sure that these rules are followed in all ts files.