How to create a custom rule to copy folder and perform npm install

痴心易碎 提交于 2019-12-12 05:26:13

问题


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.

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.

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?

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).


回答1:


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.

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.

And of course, you can generate json in Skylark.



来源:https://stackoverflow.com/questions/44550809/how-to-create-a-custom-rule-to-copy-folder-and-perform-npm-install

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!