Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage external JS/CSS libraries on GitHub [closed]

For my Java project which uses Maven I have added Twitters Bootstrap lately to my repository on GitHub. Now I have noticed that my GitHub language statistic changed from

  • 100% Java

to

  • 66,% Java 33,3% JavaScript

Since I didn't write the JS part, is there a way to manage that this isn't counted as mine or how would one normally manage foreign JS code in a GitHub repository or projects in general

like image 980
Mahoni Avatar asked Jun 14 '12 19:06

Mahoni


4 Answers

I have faced that problem lately, too. There are several ways to deal with it:

  • use the performance optimized versions, for instance bootstrap.min.js instead of bootstrap.js etc. GitHub uses the file size to determine the language proportion of each repository. This won't reduce it to zero, but at least it reduces the proportion

  • This might be what you want: GitHub has a vendor list with regular expressions which are exluced from the language graph. There you will see, that jQuery is already part of the exclusion. There is also a pending pull request to add Twitter Bootstrap. If this does not get pass you can always add the files to a directory called vendor there they will be excluded from the statistics.

  • use the Maven AntRun Plugin: With it you could simply download the JavaScript library files on request with Ant Get

  • there are also Maven repositories for these JavaScript libraries: Bootstrap-Maven. However, the files are mounted at /ext/bootstrap/ and I have no idea how this helps

  • there are even more solutions, like Maven War Plugin using overlays.

Finally my advice: just put the files into your repository. I have looked into some bigger projects on GitHub using jQuery and Twitter Bootstrap and they all put their JavaScript library files into the repository.

The advantage of these JavaScript library files is that they don't have to be compiled what so ever. Use this advantage and don't add additional burdens for the sake of aesthetic. Best practice seems to be adding it to the repository and live with the stupid language graph. Who knows, maybe certain files will be ignored in the future.

like image 146
Konrad Reiche Avatar answered Sep 22 '22 23:09

Konrad Reiche


The question is fairly old, but for future reference, it should be noted that GitHub added in 2014 a new feature to handle this thing. Possibly thanks to an open issue on the linguist repository.

This feature allows regarding certain files as libraries, documentation or a specific language.

Just add .gitattributes file to your repository. For example, to ignore a library folder, just add the line:

library/* linguist-vendored

Or to set the docs folder, add the line:

docs/* linguist-documentation

More examples can be found here.

like image 31
Liran Funaro Avatar answered Sep 24 '22 23:09

Liran Funaro


Two observations:

  • The GitHub statistics are not incorrect: your project consists of those amounts of Java and JavaScript code. It would be incorrect to say that it is a 100% Java project.
  • It's not common to include dependencies in your own code repository. You install them manually or automatically (using a system/method that varies for each programming language / environment). For example, Python has a file called requirements.txt which lists the dependencies but in Java I can imagine there to be a similar approach.
like image 36
Simeon Visser Avatar answered Sep 24 '22 23:09

Simeon Visser


Use git submodules or put your 3rd party files in a directory called 'vendor'. Then Github will not count them as part of your code

like image 31
Munter Avatar answered Sep 21 '22 23:09

Munter