免责声明:我是Jsonix和Jsonix Schema Compiler的作者,我正在尝试找出 Jsonix Schema Compiler 应该集成到 NPM 中的规范方式package.json
。
NPM 包提供了一个基于 Java的jsonix-schema-compiler
代码生成工具。如果jsonix-schema-compiler
作为依赖项安装,则它可用于生成 XML<->JS 映射。调用类似于:
java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar
schema.xsd
这会生成一个 JavaScript 文件Mappings.js
,它基本上是模块代码的一部分。
理想情况下,jsonix-schema-compiler
上面的调用(java -jar ...
等等)应该在模块构建期间执行。但必须在安装模块依赖后node_modules/jsonix-schema-compiler
执行(否则会丢失)。
我的问题是 - 我应该在哪里规范地配置 NPM 包中的代码生成?
现在我正在postinstall
脚本中执行此操作,例如:
{
...
"dependencies": {
"jsonix": "x.x.x",
"jsonix-schema-compiler": "x.x.x"
},
"devDependencies" : {
"nodeunit" : "~0.8.6"
},
"scripts": {
"postinstall" : "java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar schema.xsd",
"test": "nodeunit src/test/javascript/tests.js"
}
}
但是读过这个:
tl;博士不要使用安装。使用 .gyp 文件进行编译,并为其他任何内容预发布。
您几乎不必显式设置预安装或安装脚本。如果您这样做,请考虑是否有其他选择。
我现在很困惑是否postinstall
也可以。
我想要做的就是能够在安装依赖项之后但在其他事情(如测试或发布)之前执行某个命令行命令。我应该如何规范地做到这一点?