how to include a private local file in javascript project using bower - javascript

i want to include a custom file as one of the bower dependency.
I am have the following bower.json
{
"name": "xyz",
"version": "0.0.0",
"dependencies": {
"sass-bootstrap": "~2.3.0",
"requirejs": "~2.1.4",
"modernizr": "~2.6.2",
"jquery": "~1.9.1",
"beautify": "file:/path/to/beautify.js"
},
"devDependencies": {}
}
But when i do bower install
it gives error :
bower beautify#* ENOTFOUND Package file:/path/to/beautify.js not found
however when i open the same path in browser i get the right file.
I have also checked the case sensitive of the path.
Now can any one tell me what error i am doing? Is there any thing wrong with the syntax?
Also tell me what if i want to add the same via bower cache. Where the global bower cache is stored in mac? And how can we register the url of private package so that i just need to put name of the package in bower.json and bower finds the file from the cache?

The code below didn't work for me using Bower 1.2.8 on Ubuntu.
"beautify": "/path/to/beautify.js"
What did work was using: "beautify": "./path/to/beautify.js". This way the path is pointing to the file relative from the directory where bower.json resides.

It should be just /relative/path/to/beautify.js. No 'file:/'.
"beautify": "/path/to/beautify.js"

If you have bower installed you can do this from the commandline
bower install ../beautify.js -S
Assuming the local repo is a directory next to your current directory. This is just a testing approach and should be an available repo for general use
EDIT
It looks like you also need to tag your repo so you will pick up the latest changes too
git tag v0.0.2

Related

How to include MathJax as a dependency

I'm trying to include MathJax as a dependency in my bower.json or package.json file. However, I can't find documentation anywhere on how to correctly include it.
I've tried including it like so:
"devDependencies": {
"mathjax": "2.7.5"
}
This does not work.
Does anyone know where I could find this information?
with that you are only including it as a devDependency, basically you installed the package using:
npm install mathjax -D
but what you should do is:
npm install mathjax --save
with that you will be able to use it.
The solution to this issue is to include MathJax in the bower.json file as follows:
"devDependencies": {
"MathJax": "2.7.5"//or replace version number with "latest"
}

Angular 2 library on a private repository

I have to write a library for my app, that can be imported in the other application that I will make. In there will be a lot of functionality related to the get or post with my rest api.
The first think that I have see in google is to publish my code on npm, but I cannot publish there. So I have looked at this example:
How to install an npm package from GitHub directly?
So I have writed my package.json this way:
"dependencies": {
"#angular/animations": "^5.1.0",
...
"myRepo": "git+https://MyUser#git.myRepo.git",
}
And it works,but when I make npm install it download only package.json and readme.md file and nothing else (At the moment in the repo there are a few o file and one directory with one file inside).
Can you help me with this?
Thanks a lot!
My package.json inside the repo that I want to install looks like:
{
name: "myPackage",
version: "1.0.0"
}
And the file in this repo:
directory/
jsfile.js
package.json
readme.md

Why Bower always downloads angular version of v 1.5.9-build.5086+sha...?

I am using bower.json to manage my front end dependencies.. no matter however i specify the version of angular in bower i end up getting different version of angular library... Many of the functionality of my code are from previous version of angulars so the functions like $http.post.success() are depracted here and the code does not work. I need angular v 1.4.8 but it always downloads some other v1.5.9.build version. Here is how i tried downloading the package from bower.json
1) Mentioning the versions only..
"dependencies": {
"angular": "1.4.8",
"jquery": "2.1.4"
},
"resolutions": {
"jquery": "2.1.4",
"angular": "1.4.8"
2) I tried this way as well giving the full path of the repo in github
"dependencies": {
"angular": "https://github.com/angular/bower-angular.git#1.4.8",
"jquery": "2.1.4"
},
"resolutions": {
"jquery": "2.1.4",
"angular": "https://github.com/angular/bower-angular.git#1.4.8"
Any help would be greatly appreciated
So in my case apparently the problem was git from Visualt Studio Web Tools located at
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
With it, bower tries to install correct versions, but if you look into the bower cache you can see that actual downloaded files don't match.
Solutions
Install Git for Windows
Delete %USERPROFILE%\AppData\Local\bower
Restart Visual Studio
Delete wwwroot/lib and Restore bower packages
You might need to change the point the path of current git.exe in VS
for that:
Tools>Options>ProjectsandSolutions>ExternalTools
See the original answer here https://stackoverflow.com/a/38460014/1505521

How to make requirements.txt-like file with bower?

I've started working with bower, and it seems really helpful. I come from a python background, and so I'm used to having virtualenv and requirements.txt.
Since I'd rather not store all my dependencies in source control if I can help it, I was wondering, how can I create a file like requirements.txt with bower?
After poking around a bit more, I have the solution.
bower uses a file called bower.json (formerly component.json) which is similar to a Gemfile or requirements.txt.
It can be created manually, and will look something like this...
{
"name": "<app name, defaults co current folder name>",
"version": "0.0.0",
"dependencies": {
"backbone": "~0.9.10",
"underscore": "~1.4.3"
}
}
However, the piece that I was missing was to include the --save flag when installing packages in bower:
bower install <package_name> --save
Unfortunately, I do not believe there is a way to set this behaviour by default using the .bowerrc file.
As an added tidbit, once you have a bower.json file, installing your dependencies is as simple as running bower install.

How to register a local git package in Bower?

How can I register a local git package in bower?
My current component.json is as follows
{
"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.
I am trying bower register mypackage C:/mypackage but it keeps giving me
bower error Incorrect format
What am I doing wrong?
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 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.
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.
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.
If you just want to have bower manage a local, private dependency, then I am going to riff off of blockhead's solution:
{
"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.
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.
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.
A little detail about how many people are involved and what you were trying to accomplish would facilitate a more targeted answer.
You can add any git repository as follows:
{
"name": "myproject",
"version": "1.0.0",
"dependencies": {
"jquery": "1.8.0",
"twitter/bootstrap": "2.1.1",
"myrepo":"git://myrepo.com/myrepo"
}
}
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.
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 will overwrite the link when installing/updating.
The big idea with bower is to easily share your projects' dependencies. So using local repo should be limited to testing.
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:
# 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):
"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/.
Install dependency
In the man project install bower dependencies with:
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.
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.

Categories