jecki / ts2python

Python-interoperability for Typescript-Interfaces
Apache License 2.0
39 stars 3 forks source link

Running ts2python inside python script #12

Closed peacefulotter closed 9 months ago

peacefulotter commented 9 months ago

Hi,

Not sure if this is already feasible or if this can be a feature request but I would like to run ts2python inside a python script.

Can this be achieved? If yes, how? If not, could you implement it?

Many thanks

jecki commented 9 months ago

This can easily be be done by importing compile_src or process_file from ts2pythonParser, e.g.

from ts2python.ts2pthonParser import process_file
...
process_file("SOURCE.ts", "DESTINATION.py")

or, use:

from ts2pthon.ts2pythonParser import compile_src, serialize_result
...
result, errors = compile_src(DOCUMENT)
if errors:
    for e in errors:  print(e)
else:
   print(serialize_result(result))
peacefulotter commented 9 months ago

Cool, thank you for this! Would be nice to add this to the docs unless I missed it somewhere.

jecki commented 8 months ago

Good idea, it's now in the README.