git 中的库和示例循环依赖
我正在制作一个 js 库并使用 git 进行版本控制。假设它位于 mylib/lib.js
。在我的库目录中,我有一个与该库一起开发的示例程序的子模块,例如 mylib/example/example.js
。现在的问题是:示例程序应该如何访问该库?
如果我使用相对路径向上获取 js 文件(如 ../lib.js
),则意味着该示例不是独立的;运行它的唯一方法是克隆库。那么让它成为一个子模块真的没有任何意义。
如果我将 lib.js
复制到示例目录中,那么我就违反了 DRY,并且每次更新时都必须复制它(这将是很多)。
对于这个问题有更好的解决方案吗?
I'm making a js library and using git for version control. Say it's located at mylib/lib.js
. Inside my library directory, I have a submodule for an example program that I'm developing alongside that library, say mylib/example/example.js
. Now, the question is: how should the example program access the library?
If I use a relative path to go up and grab the js file (like ../lib.js
), that means that the example isn't standalone; the only way to run it would be to clone the library. Then there's really no point to have it be a submodule at all.
If I copy lib.js
into the example directory, then I'm violating DRY and I'd have to copy it every time it gets updated (which is going to be a lot).
Is there a better solution to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您应该将该库作为示例的子模块,或者简单的导出版本。对于您的用户来说也是如此。
如果总是更新很烦人,请编写一个本地* build/makefile/git 挂钩,以确保(所有)示例程序接收最新版本的 lib.js。
*本地为 .gitignore 内部,因为只有作为开发人员的您在您的计算机上才对确切的设置感兴趣
I think you should have the library as a submodule of the example instead, or a plain exported version. That's what it will look like for your users as well.
If it's to annoying to update all of the time, write a local* build/makefile/git hook that makes sure (all of) your example program(s) receive the latest version of your lib.js.
*Local as inside .gitignore because that exact setup is only interesting to you as a developer, on your machine