简体   繁体   English

如何创建自定义规则以复制文件夹并执行npm安装

[英]How to create a custom rule to copy folder and perform 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. 我只是从Bazel开始,我想创建一个规则,将我的nodejs应用程序(文件夹)复制到沙箱中,复制其他本地软件包(使用file://注释在package.json中引用)并执行npm install操作。

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). 然后,输出目录应该是一个可分发的nodejs应用程序,其中已经设置了node_modules /并且可以正常工作(或者这就是我想要的)。

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. 我已经尝试过从这条规则开始,但是我似乎无法对其进行任何修改,并且由于逻辑很难遵循,所以我也不知道从那里去哪里。

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 "..". 我也尝试从一个简单的动作开始,但是我做不到,特别是在本地库方面,因为它不允许我将任何包含“ ..”的文件声明为glob

Can you please give some advice to get started? 能否请您提供一些建议以开始使用?

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). 如果可能的话,我还想知道如何动态生成一个JSON文件,因此我可以在bazel本身中声明我的节点依赖项(能够跟踪它们并集中化它们的版本)。

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. 我建议您阅读有关编写扩展自定义Skylark规则的文档。 Be sure to start small and iterate. 确保从小处开始并进行迭代。

It's quite cumbersome to work with directories, you might want to create a tar first. 使用目录非常麻烦,您可能需要首先创建tar。 You can also perform npm install if you really want to, but it will have caching and remote execution implications. 如果确实需要,也可以执行npm install,但是它将涉及缓存和远程执行。

And of course, you can generate json in Skylark. 当然,您可以在Skylark中生成json。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM