Lior Chaga
Lior Chaga

Reputation: 1480

publishing a bower package (with bower ?)

The web is full of examples how to consume packages by bower, but it is missing a simple walkthrough of how to register/deploy/publish (whatever term you prefer) packages.

Suppose I'm developing my own js package, how can I deploy it to a private repository / folder? Should I use bower at all for that purpose? Or should I use grunt tasks?

Let me be more accurate about what I need: I'd like to create a js project, that consumes other bower packages. I'd like to concatenate dozens of js files into one or several js files (each one meant to be a bower package), lint them, minify them, test them and smash their bones, and than simply deploy each of the final js files into a repository (in my case - SVN, because that what we use in our company).

As much as I dig the web it seems to me that this is not a task for bower, it's a task for grunt/ant. Am I right?

Upvotes: 4

Views: 2673

Answers (2)

Lior Chaga
Lior Chaga

Reputation: 1480

I've made a lot of progress in the past few weeks, and I'm happy to share my findings to any grunt+bower rookies like me.

It appears that bower registers by default to http://bower.herokuapp.com registry, which only supports the git protocol (since it's meant to server public libraries).

So if you'd like to publish your own js libraries in private repositories, using the default registry is not a good practice. There are many bower registry implementations out there. Personally I'm a java guy so in my playground I used https://github.com/Softpagehomeware/bower-java-registry, but there are also npm, python and other registry implementations.

When you want to consume your package in another project, just define where to look for it in you .bowerrc file:

{
    "registry": {
        "register": "http://myhost/bower-java-server",
        "publish":  "http://myhost/bower-java-server",

        "search": [
            "http://myhost/bower-java-server"
          , "https://bower.herokuapp.com"
        ]
    },

    "directory": "bower_components"
}

This way, when you have a bower dependency, it first looks in your private registry, and if it doesn't find it, it searches herokuapp registry.

As for hosting the distribution package in my private git repository, I've used grunt-build-control, which can take you dist folder and push it to your distributable repository (which is registered in your bower registry).

Upvotes: 2

Greg McGuffey
Greg McGuffey

Reputation: 3316

A bit late, but I am currently trying to figure many of the same things. Here's what I've figured out so far.

  • You'd use grunt to build your libraries, put them into a distribution folder. This would handle all the linting/minifying/concatenating etc.
  • When it is ready for prime time, create a tag for it in svn. (See below...this is a bit weird).
  • You do not need to register anything. Just use the install with the path to the repository.

    bower install svn+https://svn.mycompany.com/myproject

  • Use the --save or --save-dev options to save it in your bower.json file.

  • You can hit SVN a few ways:

    • A public remote Subversion endpoint, e.g., svn+http://package.googlecode.com/svn/.
    • A private Subversion repository, e.g., svn+ssh://package.googlecode.com/svn/.
    • A local endpoint, i.e., a folder that's an Subversion repository, e.g., svn+file:///path/to/svn/.

This is from the Bower Home Page.

Of course it isn't quite this easy. Some more I've found out:

What ever you put in as the path to the SVN repository must have three folders under it: trunk, branches and tags. So, it is completely fine to point to some sub folder, but under that, you have to have these three folders. I.e. Lets say you have a distribution folder under your main folder (i.e. /trunk/dist). You have grunt putting the final product into this folder. Then you tag it (copy trunk to tags). So your directory structure would look something like:

myproject\tags\REL-1.0\dist\my-library.js

With this structure, bower is puke, if you tried to do something like

bower install https://svn.mycompany.com/myproject/tags/REL-1.0/dist

Now, if you make those three folders under dist it will work. I.e. if the folder structure looked like:

myproject\tabs\REL-1.0\dist\tags\my-library.js

the above bower command would work (but that is really ugly).

Because of this, you likely need to have a separate repository for you packages. Oh, and whatever the last folder in the path is, that will be folder in the vendor folder after bower installs it. I.e. in the example above, the library will be in the vendors\dist folder....not ideal. So, I'm currently looking at something like this:

mypackages/MyLibrary/tags/REL-1.0

So, the repository is mypackages, there is a folder for each library. Under that are the three required folders (trunk etc). Then I have folders under tags for each release.

You can note the folder like this:

bower install svn+https://svn.mycompany.com/mypackages/MyLibrary#REL-1.0

And you can use #trunk to get the trunk. Kinda weird. If you don't supply any version (folder), it gets the latest folder from tags(not sure if that is done via sort order or on commit date). If there are no folders in tags, it gets trunk. Not sure how to get to anything in branches.

Also, if you have security on your repository, if you've saved the authentication info, it will just work. No idea how that would work if you don't have the authentication information saved.

I hope this helps! I'm still figuring it out myself...

Upvotes: 4

Related Questions