2016年7月19日 星期二

[Bower] Register packages

 Bower   Package  




Introduction


Though creating packages is detailed in bower’s official document, I encountered some problems and wrote this tutorial for those who want to register, create your own packages to bower.


Register Steps


Initialize bower.json

Use the following cmd to create bower.json in the Project’s root directory step by step.
Take a look at bower.json specification for more details.

$ bower init


I will explain one of the settings: “ignore”.
It means that we can skip the files and directories when register your package to bower.

For example, if I want to ignore the files and directories like this…

$/

$/angu-tree-view

Then the “ignore” should be like this…
PS. Create a sub-directory under root is my habit, but the sub-directory will also be created when your package is installed!

"ignore": [
    "angu-tree-view/image",
    "angu-tree-view/configs",
    "angu-tree-view/node_modules",
    "angu-tree-view/bower_components",
    "angu-tree-view/test",
    "angu-tree-view/tests",
    "angu-tree-view/angu-tree-view.css",
    "angu-tree-view/angu-tree-view.js",
    "angu-tree-view/bower.json",
    "angu-tree-view/package.json",
    ".gitattributes",
    ".gitignore",
    "bower.json",
    "README.md"
  ]



Before Register

Before register, there are somethings we MUST do:

1.  Commit and create tag(s)
2.  Push with tags
3.  Get Git-endpoint (Only the first time!)


l   Commit and create tag(s)

$ git commit
$ git tag –a <tag(version)> -m <description>


l   Push with tags

$ git push --tags


l   Get Git-endpoint

Copy Git-endpoint thru “Clone or download” on your GitHub repository.

 

And modify it like this :

git://github.com/user/example.git


Register

Ok, now we can register our package!

$ bower register <package-name> <git-endpoint>

For example, my register is
$ bower register angu-tree-view git://github.com:KarateJB/AnguTreeView.git

PS. If you didn’t add any tag on the commit, there will be an error meaage.


Install the package


Now you can install your package thru bower.

Search package:
$ bower search <package name>

See all the versions of the package:
$ bower info <package name>

Install:
$ bower install <package name>#<version>


Update the package (version)


Updating a new version of your package is simple; just do the following steps again.

1.  Commit and create tag(s)
2.  Push with tags


▌Reference




沒有留言:

張貼留言