如何在Bower中注册本地git包?

时间:2023-01-24 08:21:24

How can I register a local git package in bower?

如何在凉亭中注册本地git包?

My current component.json is as follows

我当前的component.json如下

{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1"
  }
}

However I also would like to add a package I have created at C:/mypackage which is a git repository with versions tagged. When I do bower install --save C:/mypackage it properly adds it to project but it doesn't add it to my component.json.

但是我还想在C:/ mypackage中添加一个我创建的包,它是一个带有标签版本的git存储库。当我做bower安装--save C:/ mypackage它正确地将它添加到项目但它不会将它添加到我的component.json。

I am trying bower register mypackage C:/mypackage but it keeps giving me

我正在尝试使用bower注册mypackage C:/ mypackage,但它一直在给我

bower error Incorrect format

What am I doing wrong?

我究竟做错了什么?

4 个解决方案

#1


71  

Option 1: Public Bower registration

Bower is built mostly to share public (client-side) code in a "non-opinionated" manner. The primary use case, then, is to have a publicly accessible repository (on GitHub) that is registerd with a name and git repository url. I just did this myself:

Bower主要用于以“非自我意见”的方式共享公共(客户端)代码。那么,主要的用例是拥有一个可公开访问的存储库(在GitHub上),该存储库注册了一个名称和git存储库url。我自己就是这样做的:

bower register linksoup git://github.com/automatonic/linksoup

This is just telling the bower server that when you install linksoup to go and grab the code at the git://github.com/automatonic/linksoup repository, and put it in the local project's component directory.

这只是告诉购物者服务器,当您安装linksoup时,去git://github.com/automatonic/linksoup存储库中获取代码,并将其放在本地项目的组件目录中。

If this is what you want to do, then just set up a repository on github/etc., push your code there, and then register with the resulting repository info.

如果这是你想要做的,那么只需在github / etc上设置一个存储库,在那里推送你的代码,然后注册生成的存储库信息。

Option 2: Private dependency

There are many reasons not to post your code at a publicly accessible repository. It may not be open source, etc. if your mypackage code is not meant to be public, then you should probably not be registering it on the public bower server... Further, even if you could register a local directory, it would only work on your machine...which defeats the purpose of sharing the code via bower.

有许多理由不将代码发布在可公开访问的存储库中。它可能不是开源等,如果您的mypackage代码不是公开的,那么您可能不应该在公共凉亭服务器上注册它...此外,即使您可以注册本地目录,它也只会在您的机器上工作......这违背了通过凉亭共享代码的目的。

If you just want to have bower manage a local, private dependency, then I am going to riff off of blockhead's solution:

如果你只是想让bower管理一个本地的,私人的依赖,那么我将重复一下blockhead的解决方案:

{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1",
    "mypackage": "file:///path/to/mypackage/.git"
  }
}

This is just saying that myproject needs mypackage, and to use git clone to retrieve it. My guess is that this can use anything git can understand (including local repositories). But you should note that this may run into problems for anyone else working on this code that cannot access your local path.

这只是说myproject需要mypackage,并使用git clone来检索它。我的猜测是,这可以使用git可以理解的任何东西(包括本地存储库)。但是您应该注意,对于无法访问本地路径的其他任何人来说,这可能会遇到问题。

Best Guess

It looks to me as if you may have assumed that bower register was a local operation (telling bower how to find a dependency via some sort of local registry). As far as I can tell, this is only a remote and public registration, which is why this is unsupported.

它看起来好像你可能认为bower注册是一个本地操作(告诉bower如何通过某种本地注册表找到依赖)。据我所知,这只是一个远程和公共注册,这就是为什么这不受支持。

You may also be looking for a way to do something like a link operation with npm. That is, work on a dependency module without always having your dev cycle include a publish.

您可能也在寻找一种方法来执行与npm的链接操作之类的操作。也就是说,在不依赖开发周期的情况下处理依赖模块包括发布。

A little detail about how many people are involved and what you were trying to accomplish would facilitate a more targeted answer.

关于涉及多少人以及您想要实现的目标的一些细节将有助于更有针对性的答案。

#2


52  

You can add any git repository as follows:

您可以添加任何git存储库,如下所示:

{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1",
    "myrepo":"git://myrepo.com/myrepo"
  }
}

#3


33  

You can use bower link:

你可以使用凉亭链接:

The link functionality allows developers to easily test their packages. Linking is a two-step process.

链接功能允许开发人员轻松测试他们的包。链接是一个两步过程。

Using bower link in a project folder will create a global link. Then, in some other package, bower link <pkg> will create a link in the components folder pointing to the previously created link.

在项目文件夹中使用bower链接将创建一个全局链接。然后,在其他一些包中,bower链接 将在components文件夹中创建一个指向先前创建的链接的链接。

This allows to easily test a package because changes will be reflected immediately. Please note that bower will not fetch the linked package dependencies.

这样可以轻松测试包,因为更改会立即反映出来。请注意,bower不会获取链接的包依赖项。

Bower will overwrite the link when installing/updating.

Bower将在安装/更新时覆盖链接。

#4


23  

The big idea with bower is to easily share your projects' dependencies. So using local repo should be limited to testing.

使用bower的最大想法是轻松共享项目的依赖关系。所以使用本地回购应限于测试。

Once you understand that, you should know that it is not –strictly– necessary to register your package in order to use it as a dependency.

一旦你理解了这一点,你应该知道注册你的软件包以便将其用作依赖项是非常必要的。

This is due to the fact that bower depencency can specify either a version, a folder or a package. So you can use local repository.

这是因为凉亭依赖性可以指定版本,文件夹或包。所以你可以使用本地存储库。

Define as bower package

First you will need to define your dependency as a bower package:

首先,您需要将依赖项定义为bower包:

# create the bower package
cd /path/to/you-need-me
bower init
# answer questions…

Add as project dependency

Then in your main project, the one that need the you-need-me dependency, edit bower.json file to add (or expand):

然后在你的主项目中,需要你需要我的依赖项,编辑bower.json文件来添加(或扩展):

  "dependencies": {
    …
    "you-need-me":  "file:///path/to/you-need-me/.git/"
    "you-need-me-windows":  "C:/path/to/you-need-me-windows/.git/"
  }

So you don't give a version, but an local git endpoint, i.e. the subdirectory .git/.

所以你不提供一个版本,而是一个本地的git端点,即子目录.git /。

Install dependency

In the man project install bower dependencies with:

在man项目中安装bower依赖项:

cd /path/to/main-project/
bower install

Failure

bower you-need-me#*              ENOTFOUND Package /path/to/you-need-me/ not found

Check again your path and that you point to the .git/ directory of your dependency.

再次检查您的路径,并指向您的依赖项的.git /目录。

Success

You should get something like:

你应该得到类似的东西:

bower you-need-me#*             not-cached file:///path/to/you-need-me/.git/#*
bower you-need-me#*                resolve file:///path/to/you-need-me/.git/#*
bower you-need-me#*               checkout master
bower you-need-me#*               resolved file:///path/to/you-need-me/.git/#b18c753c6f
bower you-need-me#*                install you-need-me#b18c753c6f

Write a blog entry about that: Testing bower.json locally before registering package.

写一篇博客文章:在注册包之前在本地测试bower.json。

#1


71  

Option 1: Public Bower registration

Bower is built mostly to share public (client-side) code in a "non-opinionated" manner. The primary use case, then, is to have a publicly accessible repository (on GitHub) that is registerd with a name and git repository url. I just did this myself:

Bower主要用于以“非自我意见”的方式共享公共(客户端)代码。那么,主要的用例是拥有一个可公开访问的存储库(在GitHub上),该存储库注册了一个名称和git存储库url。我自己就是这样做的:

bower register linksoup git://github.com/automatonic/linksoup

This is just telling the bower server that when you install linksoup to go and grab the code at the git://github.com/automatonic/linksoup repository, and put it in the local project's component directory.

这只是告诉购物者服务器,当您安装linksoup时,去git://github.com/automatonic/linksoup存储库中获取代码,并将其放在本地项目的组件目录中。

If this is what you want to do, then just set up a repository on github/etc., push your code there, and then register with the resulting repository info.

如果这是你想要做的,那么只需在github / etc上设置一个存储库,在那里推送你的代码,然后注册生成的存储库信息。

Option 2: Private dependency

There are many reasons not to post your code at a publicly accessible repository. It may not be open source, etc. if your mypackage code is not meant to be public, then you should probably not be registering it on the public bower server... Further, even if you could register a local directory, it would only work on your machine...which defeats the purpose of sharing the code via bower.

有许多理由不将代码发布在可公开访问的存储库中。它可能不是开源等,如果您的mypackage代码不是公开的,那么您可能不应该在公共凉亭服务器上注册它...此外,即使您可以注册本地目录,它也只会在您的机器上工作......这违背了通过凉亭共享代码的目的。

If you just want to have bower manage a local, private dependency, then I am going to riff off of blockhead's solution:

如果你只是想让bower管理一个本地的,私人的依赖,那么我将重复一下blockhead的解决方案:

{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1",
    "mypackage": "file:///path/to/mypackage/.git"
  }
}

This is just saying that myproject needs mypackage, and to use git clone to retrieve it. My guess is that this can use anything git can understand (including local repositories). But you should note that this may run into problems for anyone else working on this code that cannot access your local path.

这只是说myproject需要mypackage,并使用git clone来检索它。我的猜测是,这可以使用git可以理解的任何东西(包括本地存储库)。但是您应该注意,对于无法访问本地路径的其他任何人来说,这可能会遇到问题。

Best Guess

It looks to me as if you may have assumed that bower register was a local operation (telling bower how to find a dependency via some sort of local registry). As far as I can tell, this is only a remote and public registration, which is why this is unsupported.

它看起来好像你可能认为bower注册是一个本地操作(告诉bower如何通过某种本地注册表找到依赖)。据我所知,这只是一个远程和公共注册,这就是为什么这不受支持。

You may also be looking for a way to do something like a link operation with npm. That is, work on a dependency module without always having your dev cycle include a publish.

您可能也在寻找一种方法来执行与npm的链接操作之类的操作。也就是说,在不依赖开发周期的情况下处理依赖模块包括发布。

A little detail about how many people are involved and what you were trying to accomplish would facilitate a more targeted answer.

关于涉及多少人以及您想要实现的目标的一些细节将有助于更有针对性的答案。

#2


52  

You can add any git repository as follows:

您可以添加任何git存储库,如下所示:

{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1",
    "myrepo":"git://myrepo.com/myrepo"
  }
}

#3


33  

You can use bower link:

你可以使用凉亭链接:

The link functionality allows developers to easily test their packages. Linking is a two-step process.

链接功能允许开发人员轻松测试他们的包。链接是一个两步过程。

Using bower link in a project folder will create a global link. Then, in some other package, bower link <pkg> will create a link in the components folder pointing to the previously created link.

在项目文件夹中使用bower链接将创建一个全局链接。然后,在其他一些包中,bower链接 将在components文件夹中创建一个指向先前创建的链接的链接。

This allows to easily test a package because changes will be reflected immediately. Please note that bower will not fetch the linked package dependencies.

这样可以轻松测试包,因为更改会立即反映出来。请注意,bower不会获取链接的包依赖项。

Bower will overwrite the link when installing/updating.

Bower将在安装/更新时覆盖链接。

#4


23  

The big idea with bower is to easily share your projects' dependencies. So using local repo should be limited to testing.

使用bower的最大想法是轻松共享项目的依赖关系。所以使用本地回购应限于测试。

Once you understand that, you should know that it is not –strictly– necessary to register your package in order to use it as a dependency.

一旦你理解了这一点,你应该知道注册你的软件包以便将其用作依赖项是非常必要的。

This is due to the fact that bower depencency can specify either a version, a folder or a package. So you can use local repository.

这是因为凉亭依赖性可以指定版本,文件夹或包。所以你可以使用本地存储库。

Define as bower package

First you will need to define your dependency as a bower package:

首先,您需要将依赖项定义为bower包:

# create the bower package
cd /path/to/you-need-me
bower init
# answer questions…

Add as project dependency

Then in your main project, the one that need the you-need-me dependency, edit bower.json file to add (or expand):

然后在你的主项目中,需要你需要我的依赖项,编辑bower.json文件来添加(或扩展):

  "dependencies": {
    …
    "you-need-me":  "file:///path/to/you-need-me/.git/"
    "you-need-me-windows":  "C:/path/to/you-need-me-windows/.git/"
  }

So you don't give a version, but an local git endpoint, i.e. the subdirectory .git/.

所以你不提供一个版本,而是一个本地的git端点,即子目录.git /。

Install dependency

In the man project install bower dependencies with:

在man项目中安装bower依赖项:

cd /path/to/main-project/
bower install

Failure

bower you-need-me#*              ENOTFOUND Package /path/to/you-need-me/ not found

Check again your path and that you point to the .git/ directory of your dependency.

再次检查您的路径,并指向您的依赖项的.git /目录。

Success

You should get something like:

你应该得到类似的东西:

bower you-need-me#*             not-cached file:///path/to/you-need-me/.git/#*
bower you-need-me#*                resolve file:///path/to/you-need-me/.git/#*
bower you-need-me#*               checkout master
bower you-need-me#*               resolved file:///path/to/you-need-me/.git/#b18c753c6f
bower you-need-me#*                install you-need-me#b18c753c6f

Write a blog entry about that: Testing bower.json locally before registering package.

写一篇博客文章:在注册包之前在本地测试bower.json。