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 script to generate JS template apps from TS #4374

Merged
merged 6 commits into from
Mar 4, 2022

Conversation

tomduncalf
Copy link
Contributor

@tomduncalf tomduncalf commented Feb 25, 2022

What, How & Why?

Currently we have to manually sync our JS template apps with our TS template apps, which has led to them slipping out of sync.

This PR adds a script which strips the types out of the TS apps and writes the output into the JS template apps, using the detype npm package (tsc does not preserve comments and whitespace).

It also updates the JS apps with the output of the script.

A future enhancement might be to have the react-native-template-realm-ts as the "master" app, then we copy the app directory from there into the Expo template as part of this script, and generate the JS apps. This would mean we only have to maintain one set of app code, but each template could have its own supporting code.

☑️ ToDos

  • 📝 Changelog entry
  • 📝 Compatibility label is updated or copied from previous entry
  • 🚦 Tests
  • 📱 Check the React Native/other sample apps work if necessary
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

If this PR adds or changes public API's:

  • typescript definitions file is updated
  • jsdoc files updated
  • Chrome debug API is updated if API is available on React Native

@cla-bot cla-bot bot added the cla: yes label Feb 25, 2022
@tomduncalf tomduncalf requested a review from takameyer February 25, 2022 14:59
@tomduncalf tomduncalf changed the title Td/convert ts example to js Add script to generate JS template apps from TS Feb 25, 2022
# Strip types from every .ts* file (except those in node_modules) and write the output
# to the corresponding file in react-native-template-realm-js, with the extension changed
# to ".js" (regardless of whether the original was ".tsx" or ".ts")
for i in `find . -path ./node_modules -prune -o -name "*.ts*" -print`; do npx detype $i $2/${i/\.ts*/\.js} ; done
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@takameyer I'm wondering if maybe this should only convert files in app/, and delete all the *.ts* files in there first in case we delete/rename a file... WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. We should probably move the App.tsx into app/ as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See a4917cb

Copy link
Contributor

@takameyer takameyer 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 amazing! We will have to ensure to get this into our CI at some point

@tomduncalf tomduncalf merged commit cf501cf into master Mar 4, 2022
@tomduncalf tomduncalf deleted the td/convert-ts-example-to-js branch March 4, 2022 18:19
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants