两种流行的选择:
将您的 TypeScript 类封装在 CLI 包装器中并将其用作程序
使用类似Execjs或elixir-nodejs
考虑到它的复杂性pass-js
以及如何配置它,我绝对建议您从第一种方法开始。
开发命令行界面
首先,为您的 TS 代码开发 CLI。建议:您应该接受参数,生成文件,并将生成的文件路径打印到stdout
.
这是基础指南:https ://walrus.ai/blog/2019/11/typescript-cli/
调用你的程序!
然后,使用System.cmd/3在 Elixir 中调用您的程序。
{output, code} = System.cmd("/path/to/your/program", ["program", "arguments"])
file_path = String.trim(output)
# file_path is the path of the generated pkpass
# (if you print the generated file path to stdout)
#
# code is the exit code of the program.
# 0 means success, anything else means error (you should develop that in your CLI interface)
程序界面由您决定。我建议你从简单的开始。
例如,您还可以返回 JSON 并使用Jason对其进行解析。或者您可以将二进制文件打印到标准输出并直接读取它,但这种方法有额外的复杂性。