-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Automatically generate dom types #47
Comments
What tools would you suggest to write a parser for that data, that generates scala code? |
I'm actually unexperienced with automatically generating scala-code. But here are my thoughts on how I would approach it: Trigger code-generation with sbt: https://www.scala-sbt.org/1.x/docs/Howto-Generating-Files.html The generator would look like this: |
I feel like our trait files are simple enough that you don't even need Scala-aware code generators to generate them. A simple Scala or JS script that concatenates strings will be much easier to understand and contribute to. CompileTest will pick up any resulting syntax / type errors anyway. My biggest concern with generated code is the rigidity of it. If we're generating whole files, we won't be able to edit them manually. MDN data also doesn't have Scala-specific stuff such as
So this generation needs to be customizable enough to account for all those factors, as well as other general stuff like
In all, this seems like a big investment in time and complexity that will only save time when adding props/attributes/events, as existing ones almost never change. It will probably never pay off. I think one way to minimize the total effort and complexity would be to instead write a less involved helper script that would read MDN data and simply print out code like this:
for a desirable subset of attrs (or props or whatever). Then you'd just copy-paste it into the right trait, trimming down the comments and doing any other manual work that the script did not account for. This would reduce the chance of errors when adding new defs and will probably be faster than doing it manually like we do now, but also faster than meticulously configuring a super advanced code generator that declaratively defines the entirety of the generated files. |
Agreed.
Yes, it is a big time investment and trade-off, like with all automation tasks. But the benefits are: correctness, completeness, up-to-date for code and documentation.
I agree. Before attempting to write a full-blown solution from the start, we can have simple solutions that already help a lot. I did something similar in my font-awesome facade: |
Just found this: https://github.com/mdn/data
I think it should be possible to extract a huge amount of code automatically and have a more up-to-date library in general.
There is also https://github.com/mdn/browser-compat-data and https://github.com/Fyrd/caniuse
The text was updated successfully, but these errors were encountered: