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

Useful script to convert all .js files to .ts in a repo #1120

Closed
zepumph opened this issue Oct 19, 2021 · 5 comments
Closed

Useful script to convert all .js files to .ts in a repo #1120

zepumph opened this issue Oct 19, 2021 · 5 comments

Comments

@zepumph
Copy link
Member

zepumph commented Oct 19, 2021

While working on phetsims/ratio-and-proportion#404, I found this to be useful:

find . -name "*.js" ! -iname "*phet-io-overrides.js"  -exec bash -c 'mv "$1" "${1%.js}".ts' - '{}' \;

@samreid, do you think this could be part of the documentation on converting repos to typescript?

@samreid
Copy link
Member

samreid commented Oct 19, 2021

Remember if renaming a file, it should be done with git mv so it is tracked with version control. For now, I have been converting file-by-file, and it has been insignificant overhead to rename these by hand. If we do want to automate this, perhaps add a // @ts-nocheck at the beginning of each file so it passes a build? Then the manual step is to remove that directive instead of renaming the file? But I'm happy to rename them by hand as long as I continue to go one-by-one. What do you think?

@samreid samreid assigned zepumph and unassigned samreid Oct 19, 2021
@zepumph
Copy link
Member Author

zepumph commented Oct 19, 2021

Agreed! I have 1364 compiler errors to get through before I'm done, but I thought it would go fast for this sim.

As for using git mv, the IDE picked up the changes easily.

  • Run the script
  • go to IDE and pretend like you are going to commit
  • Right click on "Unversioned Files" and say add to VCS
  • escape out, and reload the commit dialog. Every file is noted as being "moved" instead of a delete + new file.

@zepumph zepumph assigned samreid and unassigned zepumph Oct 19, 2021
samreid added a commit that referenced this issue Oct 19, 2021
@samreid
Copy link
Member

samreid commented Oct 19, 2021

I updated the docs to match my current sentiment, can you please review and advise?

@zepumph
Copy link
Member Author

zepumph commented Oct 21, 2021

Just to note here for the record. I did go "all in" for ratio and proportion with that script, and in general it was not totally ideal. I would likely do it again but wanted to note the trade offs. Because it ended up taking a couple of days to work through the whole repo, I am committing to a branch so that master doesn't have compile errors. That said, it has been really nice to have a global number of all compile errors to track my progress. First day I went from 1300 -> 1100, then over the next 2 days I got to 500. I think I would use this script again if it was 8am, and I was planning on converting a repo as my whole day today, because I think it is really tiresome to convert file extensions manually.

Anywho, the RaP issue I'm tracking this in is phetsims/ratio-and-proportion#404, and note that it is on a branch (for now. . .).

@samreid
Copy link
Member

samreid commented Oct 21, 2021

Thanks, sounds interesting and I'll consider it as a possibility for myself next time!

samreid added a commit to phetsims/phet-info that referenced this issue Oct 26, 2021
samreid added a commit to phetsims/phet-info that referenced this issue Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants