如何创建自定义规则以复制文件夹并执行npm安装 [英] How to create a custom rule to copy folder and perform npm install
问题描述
我只是从Bazel开始,我想创建一条规则,将我的nodejs应用程序(文件夹)复制到沙箱中,复制其他本地包(使用file://
批注在package.json中引用)并执行npm install
动作.
I'm just starting with Bazel, I want to create a rule that copies my nodejs application (folder) inside the sandbox, copies other local packages (referenced in package.json using the file://
annotation) and perform a npm install
action.
然后输出目录应该是一个可分发的nodejs应用程序,其中的node_modules/已经设置并且可以正常工作(或者这就是我想要得到的).
The output directory should then be a distributable nodejs application with the node_modules/ already set and working (or this is what I want to get).
我已经尝试通过重新开始这条规则但我似乎无法对其进行任何修改,而且由于逻辑很难遵循,因此我也不知道从那里去哪里.
I've tried by starting over this rule but I can't seem to perform any modification over it and I don't know where to go from there since the logic is pretty hard to follow.
我也尝试从一个简单的动作开始,但是我做不到,特别是关于本地库,因为它不允许我将任何包含".."的文件声明为glob
.
I also tried to start with an easier action but I cannot get it right, especially regarding the local libraries, because it won't allow me declare as glob
any file containing "..".
能否请您提供一些入门建议?
Can you please give some advice to get started?
如果可能的话,我还想知道如何动态生成一个JSON文件,因此我可以在bazel本身中声明我的节点依赖项(能够跟踪它们并集中其版本).
If possible I'd also like to know how could I dynamically generate a JSON file, so I'd be able to declare my node dependencies in bazel itself (being able to track them down and centralize their version).
推荐答案
this won't be an easy exercise :) It's perfectly doable, and at the end you'll be perfectly comfortable understanding what that rule does :)
我建议您阅读有关编写扩展名的文档,并自定义云雀规则开始.确保从小处开始并进行迭代.
I suggest you to read the documentation on writing extensions and custom Skylark rules to start. Be sure to start small and iterate.
使用目录非常麻烦,您可能需要首先创建tar.如果确实需要,您还可以执行npm install,但这将涉及缓存和远程执行.
It's quite cumbersome to work with directories, you might want to create a tar first. You can also perform npm install if you really want to, but it will have caching and remote execution implications.
当然,您可以在Skylark中生成json.
And of course, you can generate json in Skylark.
这篇关于如何创建自定义规则以复制文件夹并执行npm安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!